F
Filamentβ€’3mo ago
Martin Oscar

"live" headerActions

So i have a SimplePage used to display the console problem is actions are not live I want to "live" disable/enable the start button once the server is 'starting' / 'running'; change stop to kill once the server's is 'stopping' and disable stop if server is 'offline'
protected function getHeaderActions(): array
{
/** @var Server $server */
$server = Filament::getTenant();

return [
Action::make('start')
->color('primary')
->action(fn () => $this->dispatch('setServerState', state: 'start'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() === 'starting' || $server->retrieveStatus() === 'running'),
Action::make('restart')
->color('gray')
->action(fn () => $this->dispatch('setServerState', state: 'restart'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() === 'offline'),
Action::make('stop')
->label(fn () => $server->retrieveStatus() === 'stopping' ? 'kill' : 'stop')
->color('danger')
->action(fn () => $this->dispatch('setServerState', state: $server->retrieveStatus() === 'stopping' ? 'kill' : 'stop'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() === 'offline'),
];
}
protected function getHeaderActions(): array
{
/** @var Server $server */
$server = Filament::getTenant();

return [
Action::make('start')
->color('primary')
->action(fn () => $this->dispatch('setServerState', state: 'start'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() === 'starting' || $server->retrieveStatus() === 'running'),
Action::make('restart')
->color('gray')
->action(fn () => $this->dispatch('setServerState', state: 'restart'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() === 'offline'),
Action::make('stop')
->label(fn () => $server->retrieveStatus() === 'stopping' ? 'kill' : 'stop')
->color('danger')
->action(fn () => $this->dispatch('setServerState', state: $server->retrieveStatus() === 'stopping' ? 'kill' : 'stop'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() === 'offline'),
];
}
Also tried with two different actions & hidden/visible without much success either
No description
2 Replies
Povilas K
Povilas Kβ€’3mo ago
If you want to use live updates like this, a better way is to use Reverb or other socket tool, we have a tutorial about it: https://laraveldaily.com/post/configure-laravel-reverb-filament-broadcasting You can also probably do something with Livewire custom component and wire:poll But not sure if it's possible in the simple straightforward "static" way you're trying
Martin Oscar
Martin OscarOPβ€’3mo ago
Hey thank for your quick reply; Since we are already handling websockets via JS (for console and to send power actions) i don't want to use reverb. I'll try using Livewire custom component kinda like we already with cpu, ram, disk, network Widgets
That would be so cool if the static way worked out of the box in the future πŸ‘Œ
OK so its because of headerActions being forcefully cached HeaderActions.php#L19 HasHeaderActions.php#L39 If this was somehow a boolean like ->cache(false) that'd be amazing

Did you find this page helpful?