Skip to content

Commit

Permalink
Fix has actions (#1901)
Browse files Browse the repository at this point in the history
* Fix Action Repetitive Calling

* Fix validActionsCount

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Aug 26, 2024
1 parent 84eaf9b commit 0b0d9cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Traits/Helpers/ActionsHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ public function getActionWrapperAttributes(): array
#[Computed]
public function hasActions(): bool
{
return (new Collection($this->actions()))
->filter(fn ($action) => $action instanceof Action)->count() > 0;
if (! isset($this->validActions)) {
$this->validActions = $this->getActions();
}

return $this->validActions->count() > 0;
}

#[Computed]
public function getActions(): Collection
{
return (new Collection($this->actions()))
->filter(fn ($action) => $action instanceof Action)
->each(function (Action $action, int $key) {
$action->setTheme($this->getTheme());
});

if (! isset($this->validActions)) {
$this->validActions = (new Collection($this->actions()))
->filter(fn ($action) => $action instanceof Action)
->each(function (Action $action, int $key) {
$action->setTheme($this->getTheme());
});
}

return $this->validActions;
}
}
3 changes: 3 additions & 0 deletions src/Traits/WithActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rappasoft\LaravelLivewireTables\Traits;

use Illuminate\Support\Collection;
use Rappasoft\LaravelLivewireTables\Traits\Configuration\ActionsConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Helpers\ActionsHelpers;

Expand All @@ -16,6 +17,8 @@ trait WithActions

protected string $actionsPosition = 'right';

protected ?Collection $validActions;

protected function actions(): array
{
return [];
Expand Down

0 comments on commit 0b0d9cb

Please sign in to comment.