diff --git a/app/Filament/App/Resources/Servers/Pages/ListServers.php b/app/Filament/App/Resources/Servers/Pages/ListServers.php index 2d8dc0219..1294d16a6 100644 --- a/app/Filament/App/Resources/Servers/Pages/ListServers.php +++ b/app/Filament/App/Resources/Servers/Pages/ListServers.php @@ -112,7 +112,7 @@ class ListServers extends ListRecords ->poll('15s') ->columns($usingGrid ? $this->gridColumns() : $this->tableColumns()) ->recordUrl(!$usingGrid ? (fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)) : null) - ->recordActions(!$usingGrid ? ActionGroup::make(static::getPowerActions(view: 'table')) : []) + ->recordActions(!$usingGrid ? static::getPowerActionGroup() : []) ->recordActionsAlignment(Alignment::Center->value) ->contentGrid($usingGrid ? ['default' => 1, 'md' => 2] : null) ->emptyStateIcon('tabler-brand-docker') @@ -225,47 +225,43 @@ class ListServers extends ListRecords } } - /** @return Action[]|ActionGroup[] */ - public static function getPowerActions(string $view): array + public static function getPowerActionGroup(): ActionGroup { - $actions = [ + return ActionGroup::make([ Action::make('start') + ->label(trans('server/console.power_actions.start')) ->color('primary') ->icon('tabler-player-play-filled') ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_START, $server)) - ->visible(fn (Server $server) => !$server->isInConflictState() && $server->retrieveStatus()->isStartable()) + ->visible(fn (Server $server) => $server->retrieveStatus()->isStartable()) ->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'start']), Action::make('restart') + ->label(trans('server/console.power_actions.restart')) ->color('gray') ->icon('tabler-reload') ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server)) - ->visible(fn (Server $server) => !$server->isInConflictState() && $server->retrieveStatus()->isRestartable()) + ->visible(fn (Server $server) => $server->retrieveStatus()->isRestartable()) ->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'restart']), Action::make('stop') + ->label(trans('server/console.power_actions.stop')) ->color('danger') ->icon('tabler-player-stop-filled') ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) - ->visible(fn (Server $server) => !$server->isInConflictState() && $server->retrieveStatus()->isStoppable()) + ->visible(fn (Server $server) => $server->retrieveStatus()->isStoppable() && !$server->retrieveStatus()->isKillable()) ->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'stop']), Action::make('kill') + ->label(trans('server/console.power_actions.kill')) ->color('danger') ->icon('tabler-alert-square') - ->tooltip('This can result in data corruption and/or data loss!') + ->tooltip(trans('server/console.power_actions.kill_tooltip')) ->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->retrieveStatus()->isKillable()) ->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'kill']), - ]; - - if ($view === 'table') { - return $actions; - } else { - return [ - ActionGroup::make($actions) - ->icon('tabler-power') - ->color('primary') - ->tooltip('Power Actions') - ->iconSize(IconSize::Large), - ]; - } + ]) + ->icon('tabler-power') + ->color('primary') + ->tooltip(trans('server/dashboard.power_actions')) + ->hidden(fn (Server $server) => $server->isInConflictState()) + ->iconSize(IconSize::Large); } } diff --git a/app/Filament/Server/Pages/Console.php b/app/Filament/Server/Pages/Console.php index ef63364ab..2862c6d4e 100644 --- a/app/Filament/Server/Pages/Console.php +++ b/app/Filament/Server/Pages/Console.php @@ -158,45 +158,52 @@ class Console extends Page /** @return array */ protected function getDefaultHeaderActions(): array { - /** @var Server $server */ - $server = Filament::getTenant(); - return [ - Action::make('start') - ->label(trans('server/console.power_actions.start')) - ->color('primary') - ->size(Size::ExtraLarge) - ->action(fn () => $this->dispatch('setServerState', state: 'start', uuid: $server->uuid)) - ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_START, $server)) - ->disabled(fn () => $server->isInConflictState() || !$this->status->isStartable()) - ->icon('tabler-player-play-filled'), - Action::make('restart') - ->label(trans('server/console.power_actions.restart')) - ->color('gray') - ->size(Size::ExtraLarge) - ->action(fn () => $this->dispatch('setServerState', state: 'restart', uuid: $server->uuid)) - ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server)) - ->disabled(fn () => $server->isInConflictState() || !$this->status->isRestartable()) - ->icon('tabler-reload'), - Action::make('stop') - ->label(trans('server/console.power_actions.stop')) - ->color('danger') - ->size(Size::ExtraLarge) - ->action(fn () => $this->dispatch('setServerState', state: 'stop', uuid: $server->uuid)) - ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) - ->hidden(fn () => $this->status->isStartingOrStopping() || $this->status->isKillable()) - ->disabled(fn () => $server->isInConflictState() || !$this->status->isStoppable()) - ->icon('tabler-player-stop-filled'), - Action::make('kill') - ->label(trans('server/console.power_actions.kill')) - ->color('danger') - ->tooltip(trans('server/console.power_actions.kill_tooltip')) - ->requiresConfirmation() - ->size(Size::ExtraLarge) - ->action(fn () => $this->dispatch('setServerState', state: 'kill', uuid: $server->uuid)) - ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) - ->hidden(fn () => $server->isInConflictState() || !$this->status->isKillable()) - ->icon('tabler-alert-square'), + ActionGroup::make([ + Action::make('start') + ->label(trans('server/console.power_actions.start')) + ->color('primary') + ->icon('tabler-player-play-filled') + ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_START, $server)) + ->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isStartable()) + ->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'start')) + ->size(Size::ExtraLarge), + Action::make('restart') + ->label(trans('server/console.power_actions.restart')) + ->color('gray') + ->icon('tabler-reload') + ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server)) + ->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isRestartable()) + ->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'restart')) + ->size(Size::ExtraLarge), + Action::make('stop') + ->label(trans('server/console.power_actions.stop')) + ->color('danger') + ->icon('tabler-player-stop-filled') + ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) + ->visible(fn () => !$this->status->isKillable()) + ->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isStoppable()) + ->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'stop')) + ->size(Size::ExtraLarge), + Action::make('kill') + ->label(trans('server/console.power_actions.kill')) + ->color('danger') + ->icon('tabler-alert-square') + ->tooltip(trans('server/console.power_actions.kill_tooltip')) + ->requiresConfirmation() + ->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) + ->visible(fn () => $this->status->isKillable()) + ->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isKillable()) + ->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'kill')) + ->size(Size::ExtraLarge), + ]) + ->record(function () { + /** @var Server $server */ + $server = Filament::getTenant(); + + return $server; + }) + ->buttonGroup(), ]; } diff --git a/resources/views/livewire/server-entry.blade.php b/resources/views/livewire/server-entry.blade.php index 86b7b98ca..178f31ce2 100644 --- a/resources/views/livewire/server-entry.blade.php +++ b/resources/views/livewire/server-entry.blade.php @@ -1,3 +1,7 @@ +@php + $actiongroup = \App\Filament\App\Resources\Servers\Pages\ListServers::getPowerActionGroup()->record($server); +@endphp +
@@ -20,13 +24,13 @@ ({{ $server->formatResource(\App\Enums\ServerResourceType::Uptime) }}) -
-
- @foreach (\App\Filament\App\Resources\Servers\Pages\ListServers::getPowerActions(view: 'grid') as $action) - {{ $action->record($server) }} - @endforeach + @if ($actiongroup->isVisible()) +
+
+ {{ $actiongroup }} +
-
+ @endif