From df03df9b5dbdb4f2c57ec7cd6ef0f59f4eae62fe Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Tue, 3 Jun 2025 17:24:51 +0100 Subject: [PATCH] fix --- packages/tables/docs/04-actions.md | 4 +- .../tables/resources/views/index.blade.php | 106 +++++++++--------- .../src/Table/Concerns/HasRecordActions.php | 18 +++ 3 files changed, 73 insertions(+), 55 deletions(-) diff --git a/packages/tables/docs/04-actions.md b/packages/tables/docs/04-actions.md index ac3fdebd77..78781cf16d 100644 --- a/packages/tables/docs/04-actions.md +++ b/packages/tables/docs/04-actions.md @@ -5,7 +5,7 @@ import AutoScreenshot from "@components/AutoScreenshot.astro" ## Introduction -Filament's tables can use [Actions](../actions). They are buttons that can be added to the [end of any table row](#record-actions), or even in the [header](#header-actions) of a table. For instance, you may want an action to "create" a new record in the header, and then "edit" and "delete" actions on each row. [Bulk actions](#bulk-actions) can be used to execute code when records in the table are selected. Additionally, actions can be added to any [table column](#column-actions), such that each cell in that column is a trigger for your action. +Filament's tables can use [Actions](../actions). They are buttons that can be added to the [end of any table row](#record-actions), or even in the [header](#header-actions) or [toolbar](#toolbar-actions) of a table. For instance, you may want an action to "create" a new record in the header, and then "edit" and "delete" actions on each row. [Bulk actions](#bulk-actions) can be used to execute code when records in the table are selected. Additionally, actions can be added to any [table column](#column-actions), such that each cell in that column is a trigger for your action. It's highly advised that you read the documentation about [customizing action trigger buttons](../actions/overview) and [action modals](../actions/modals) to that you are aware of the full capabilities of actions. @@ -116,7 +116,7 @@ public function table(Table $table): Table ## Bulk actions -Tables also support "bulk actions". These can be used when the user selects rows in the table. Traditionally, when rows are selected, a "bulk actions" button appears in the top left corner of the table. When the user clicks this button, they are presented with a dropdown menu of actions to choose from. You can put them in the `$table->toolbarActions()` or `$table->headerActions()` methods: +Tables also support "bulk actions". These can be used when the user selects rows in the table. Traditionally, when rows are selected, a "bulk actions" button appears. When the user clicks this button, they are presented with a dropdown menu of actions to choose from. You can put them in the `$table->toolbarActions()` or `$table->headerActions()` methods: ```php use Filament\Tables\Table; diff --git a/packages/tables/resources/views/index.blade.php b/packages/tables/resources/views/index.blade.php index 1f0a72528c..52e0e185c0 100644 --- a/packages/tables/resources/views/index.blade.php +++ b/packages/tables/resources/views/index.blade.php @@ -12,14 +12,14 @@ use Illuminate\Support\Str; use Illuminate\View\ComponentAttributeBag; - $actions = $getActions(); - $flatActionsCount = count($getFlatActions()); - $actionsAlignment = $getActionsAlignment(); - $actionsPosition = $getActionsPosition(); - $actionsColumnLabel = $getActionsColumnLabel(); + $recordActions = $getRecordActions(); + $flatRecordActionsCount = count($getFlatRecordActions()); + $recordActionsAlignment = $getRecordActionsAlignment(); + $recordActionsPosition = $getRecordActionsPosition(); + $recordActionsColumnLabel = $getRecordActionsColumnLabel(); - if (! $actionsAlignment instanceof Alignment) { - $actionsAlignment = filled($actionsAlignment) ? (Alignment::tryFrom($actionsAlignment) ?? $actionsAlignment) : null; + if (! $recordActionsAlignment instanceof Alignment) { + $recordActionsAlignment = filled($recordActionsAlignment) ? (Alignment::tryFrom($recordActionsAlignment) ?? $recordActionsAlignment) : null; } $activeFiltersCount = $getActiveFiltersCount(); @@ -89,7 +89,7 @@ $defaultSortOptionLabel = $getDefaultSortOptionLabel(); $sortDirection = $getSortDirection(); - if (count($actions) && (! $isReordering)) { + if (count($recordActions) && (! $isReordering)) { $columnsCount++; } @@ -791,7 +791,7 @@ $hasCollapsibleColumnsLayout = (bool) $collapsibleColumnsLayout?->isVisible(); $recordActions = array_reduce( - $actions, + $recordActions, function (array $carry, $action) use ($record): array { if (! $action instanceof \Filament\Actions\ActionGroup) { $action = clone $action; @@ -985,7 +985,7 @@ @elseif ($recordAction) @php - $recordWireClickAction = $getAction($recordAction) + $recordWireClickAction = $getRecordAction($recordAction) ? "mountTableAction('{$recordAction}', '{$recordKey}')" : $recordWireClickAction = "{$recordAction}('{$recordKey}')"; @endphp @@ -1040,7 +1040,7 @@ 'fi-ta-actions fi-wrapped sm:fi-not-wrapped', 'fi-align-start' => $contentGrid, 'md:fi-align-end' => ! $contentGrid, - 'fi-ta-actions-before-columns-position' => $actionsPosition === RecordActionsPosition::BeforeColumns, + 'fi-ta-actions-before-columns-position' => $recordActionsPosition === RecordActionsPosition::BeforeColumns, ]) > @foreach ($recordActions as $action) @@ -1120,7 +1120,7 @@ @if ($isReordering) @else - @if (count($actions) && in_array($actionsPosition, [RecordActionsPosition::BeforeCells, RecordActionsPosition::BeforeColumns])) + @if (count($recordActions) && in_array($recordActionsPosition, [RecordActionsPosition::BeforeCells, RecordActionsPosition::BeforeColumns])) @endif @@ -1160,7 +1160,7 @@ @endforeach @if ((! $isReordering) && count($records)) - @if (count($actions) && in_array($actionsPosition, [RecordActionsPosition::AfterColumns, RecordActionsPosition::AfterCells])) + @if (count($recordActions) && in_array($recordActionsPosition, [RecordActionsPosition::AfterColumns, RecordActionsPosition::AfterCells])) @endif @@ -1176,14 +1176,14 @@ @if ($isReordering) @else - @if (count($actions) && $actionsPosition === RecordActionsPosition::BeforeCells) - @if ($actionsColumnLabel) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::BeforeCells) + @if ($recordActionsColumnLabel) - {{ $actionsColumnLabel }} + {{ $recordActionsColumnLabel }} @else @endif @@ -1222,14 +1222,14 @@ @endif - @if (count($actions) && $actionsPosition === RecordActionsPosition::BeforeColumns) - @if ($actionsColumnLabel) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::BeforeColumns) + @if ($recordActionsColumnLabel) - {{ $actionsColumnLabel }} + {{ $recordActionsColumnLabel }} @else @endif @@ -1294,16 +1294,16 @@ @endforeach @if ((! $isReordering) && count($records)) - @if (count($actions) && $actionsPosition === RecordActionsPosition::AfterColumns) - @if ($actionsColumnLabel) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::AfterColumns) + @if ($recordActionsColumnLabel) - {{ $actionsColumnLabel }} + {{ $recordActionsColumnLabel }} @else @endif @@ -1342,16 +1342,16 @@ @endif - @if (count($actions) && $actionsPosition === RecordActionsPosition::AfterCells) - @if ($actionsColumnLabel) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::AfterCells) + @if ($recordActionsColumnLabel) - {{ $actionsColumnLabel }} + {{ $recordActionsColumnLabel }} @else @endif @@ -1381,7 +1381,7 @@ @if ($isReordering) @else - @if (count($actions) && in_array($actionsPosition, [RecordActionsPosition::BeforeCells, RecordActionsPosition::BeforeColumns])) + @if (count($recordActions) && in_array($recordActionsPosition, [RecordActionsPosition::BeforeCells, RecordActionsPosition::BeforeColumns])) @endif @@ -1414,7 +1414,7 @@ @endforeach @if ((! $isReordering) && count($records)) - @if (count($actions) && in_array($actionsPosition, [RecordActionsPosition::AfterColumns, RecordActionsPosition::AfterCells])) + @if (count($recordActions) && in_array($recordActionsPosition, [RecordActionsPosition::AfterColumns, RecordActionsPosition::AfterCells])) @endif @@ -1443,7 +1443,7 @@ $recordGroupTitle = $group?->getTitle($record); $recordActions = array_reduce( - $actions, + $recordActions, function (array $carry, $action) use ($record): array { if (! $action instanceof \Filament\Actions\ActionGroup) { $action = clone $action; @@ -1473,8 +1473,8 @@ @endphp @endif @@ -1656,17 +1656,17 @@ @endif - @if (count($actions) && $actionsPosition === RecordActionsPosition::BeforeCells && (! $isReordering)) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::BeforeCells && (! $isReordering))
'fi-align-center', Alignment::Start, Alignment::Left => 'fi-align-start', Alignment::Between, Alignment::Justify => 'fi-align-between', Alignment::End, Alignment::Right => '', - default => is_string($actionsAlignment) ? $actionsAlignment : '', + default => is_string($recordActionsAlignment) ? $recordActionsAlignment : '', }, ]) > @@ -1698,17 +1698,17 @@ @endif - @if (count($actions) && $actionsPosition === RecordActionsPosition::BeforeColumns && (! $isReordering)) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::BeforeColumns && (! $isReordering))
'fi-align-center', Alignment::Start, Alignment::Left => 'fi-align-start', Alignment::Between, Alignment::Justify => 'fi-align-between', Alignment::End, Alignment::Right => '', - default => is_string($actionsAlignment) ? $actionsAlignment : '', + default => is_string($recordActionsAlignment) ? $recordActionsAlignment : '', }, ]) > @@ -1784,17 +1784,17 @@ @endforeach - @if (count($actions) && $actionsPosition === RecordActionsPosition::AfterColumns && (! $isReordering)) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::AfterColumns && (! $isReordering))
'fi-align-center', Alignment::Start, Alignment::Left => 'fi-align-start', Alignment::Between, Alignment::Justify => 'fi-align-between', Alignment::End, Alignment::Right => '', - default => is_string($actionsAlignment) ? $actionsAlignment : '', + default => is_string($recordActionsAlignment) ? $recordActionsAlignment : '', }, ]) > @@ -1826,17 +1826,17 @@ @endif - @if (count($actions) && $actionsPosition === RecordActionsPosition::AfterCells && (! $isReordering)) + @if (count($recordActions) && $recordActionsPosition === RecordActionsPosition::AfterCells && (! $isReordering))
'fi-align-center', Alignment::Start, Alignment::Left => 'fi-align-start', Alignment::Between, Alignment::Justify => 'fi-align-between', Alignment::End, Alignment::Right => '', - default => is_string($actionsAlignment) ? $actionsAlignment : '', + default => is_string($recordActionsAlignment) ? $recordActionsAlignment : '', }, ]) > @@ -1864,8 +1864,8 @@ @endphp getRecordActionsColumnLabel(); } + + /** + * @return array + */ + public function getFlatRecordActions(): array + { + $flatActions = []; + + foreach ($this->getRecordActions() as $action) { + if ($action instanceof ActionGroup) { + $flatActions = array_merge($flatActions, $action->getFlatActions()); + } else { + $flatActions[$action->getName()] = $action; + } + } + + return $flatActions; + } }