Fix table view power actions (#1490)

This commit is contained in:
Charles 2025-07-06 19:03:09 -04:00 committed by GitHub
parent 556551b4f3
commit f8e802afcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 35 deletions

View File

@ -110,7 +110,7 @@ class ListServers extends ListRecords
->poll('15s') ->poll('15s')
->columns($usingGrid ? $this->gridColumns() : $this->tableColumns()) ->columns($usingGrid ? $this->gridColumns() : $this->tableColumns())
->recordUrl(!$usingGrid ? (fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)) : null) ->recordUrl(!$usingGrid ? (fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)) : null)
->actions(!$usingGrid ? ActionGroup::make(static::getPowerActions()) : []) ->actions(!$usingGrid ? ActionGroup::make(static::getPowerActions(view: 'table')) : [])
->actionsAlignment(Alignment::Center->value) ->actionsAlignment(Alignment::Center->value)
->contentGrid($usingGrid ? ['default' => 1, 'md' => 2] : null) ->contentGrid($usingGrid ? ['default' => 1, 'md' => 2] : null)
->emptyStateIcon('tabler-brand-docker') ->emptyStateIcon('tabler-brand-docker')
@ -221,10 +221,9 @@ class ListServers extends ListRecords
} }
/** @return Action[]|ActionGroup[] */ /** @return Action[]|ActionGroup[] */
public static function getPowerActions(): array public static function getPowerActions(string $view): array
{ {
return [ $actions = [
ActionGroup::make([
Action::make('start') Action::make('start')
->color('primary') ->color('primary')
->icon('tabler-player-play-filled') ->icon('tabler-player-play-filled')
@ -250,7 +249,13 @@ class ListServers extends ListRecords
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isKillable()) ->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isKillable())
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'kill']), ->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'kill']),
]) ];
if ($view === 'table') {
return $actions;
} else {
return [
ActionGroup::make($actions)
->icon(fn (Server $server) => $server->condition->getIcon()) ->icon(fn (Server $server) => $server->condition->getIcon())
->color(fn (Server $server) => $server->condition->getColor()) ->color(fn (Server $server) => $server->condition->getColor())
->tooltip(fn (Server $server) => $server->condition->getLabel()) ->tooltip(fn (Server $server) => $server->condition->getLabel())
@ -258,3 +263,4 @@ class ListServers extends ListRecords
]; ];
} }
} }
}

View File

@ -11,7 +11,7 @@
<div class="end-0" x-on:click.stop> <div class="end-0" x-on:click.stop>
<div class="flex-1 dark:bg-gray-800 dark:text-white rounded-b-lg overflow-hidden p-1"> <div class="flex-1 dark:bg-gray-800 dark:text-white rounded-b-lg overflow-hidden p-1">
<x-filament-tables::actions <x-filament-tables::actions
:actions="\App\Filament\App\Resources\ServerResource\Pages\ListServers::getPowerActions()" :actions="\App\Filament\App\Resources\ServerResource\Pages\ListServers::getPowerActions(view: 'grid')"
:alignment="\Filament\Support\Enums\Alignment::Center" :alignment="\Filament\Support\Enums\Alignment::Center"
:record="$server" :record="$server"
/> />