diff --git a/app/Livewire/Server/Charts.php b/app/Livewire/Server/Charts.php index 7c555959f..1cda771a7 100644 --- a/app/Livewire/Server/Charts.php +++ b/app/Livewire/Server/Charts.php @@ -32,7 +32,7 @@ class Charts extends Component } } - public function toggleMetrics() + public function toggleMetrics(): void { try { $this->authorize('update', $this->server); @@ -42,14 +42,16 @@ class Charts extends Component if ($this->server->isMetricsEnabled()) { StartSentinel::run($this->server, true); - $this->dispatch('success', 'Metrics enabled. Restarting Sentinel.'); + $this->dispatch('success', 'Metrics enabled. Starting Sentinel.'); + $this->dispatch('refreshServerShow'); $this->redirect(route('server.metrics', ['server_uuid' => $this->server->uuid]), navigate: true); } else { $this->server->restartSentinel(); $this->dispatch('success', 'Metrics disabled. Restarting Sentinel.'); + $this->dispatch('refreshServerShow'); } } catch (\Throwable $e) { - return handleError($e, $this); + handleError($e, $this); } } diff --git a/app/Livewire/Server/Sentinel.php b/app/Livewire/Server/Sentinel.php index 73889378a..909ed54f9 100644 --- a/app/Livewire/Server/Sentinel.php +++ b/app/Livewire/Server/Sentinel.php @@ -104,7 +104,7 @@ class Sentinel extends Component } } - public function toggleSentinel() + public function toggleSentinel(): void { try { $this->authorize('manageSentinel', $this->server); @@ -124,8 +124,9 @@ class Sentinel extends Component StopSentinel::dispatch($this->server); } $this->submit(); + $this->dispatch('refreshServerShow'); } catch (\Throwable $e) { - return handleError($e, $this); + handleError($e, $this); } } diff --git a/app/Livewire/Server/Sentinel/Logs.php b/app/Livewire/Server/Sentinel/Logs.php index 513776a6f..6619e101e 100644 --- a/app/Livewire/Server/Sentinel/Logs.php +++ b/app/Livewire/Server/Sentinel/Logs.php @@ -3,28 +3,26 @@ namespace App\Livewire\Server\Sentinel; use App\Models\Server; +use Illuminate\View\View; use Livewire\Component; class Logs extends Component { public ?Server $server = null; - public $parameters = []; + public array $parameters = []; - public function mount() + public function mount(): void { $this->parameters = get_route_parameters(); try { - $this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->first(); - if (is_null($this->server)) { - return redirect()->route('server.index'); - } + $this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail(); } catch (\Throwable $e) { - return handleError($e, $this); + handleError($e, $this); } } - public function render() + public function render(): View { return view('livewire.server.sentinel.logs'); } diff --git a/app/Livewire/Server/Sentinel/Show.php b/app/Livewire/Server/Sentinel/Show.php index 4bfc4c398..7070a09ce 100644 --- a/app/Livewire/Server/Sentinel/Show.php +++ b/app/Livewire/Server/Sentinel/Show.php @@ -3,25 +3,26 @@ namespace App\Livewire\Server\Sentinel; use App\Models\Server; +use Illuminate\View\View; use Livewire\Component; class Show extends Component { public ?Server $server = null; - public $parameters = []; + public array $parameters = []; - public function mount() + public function mount(): void { $this->parameters = get_route_parameters(); try { $this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail(); } catch (\Throwable $e) { - return handleError($e, $this); + handleError($e, $this); } } - public function render() + public function render(): View { return view('livewire.server.sentinel.show'); } diff --git a/resources/views/components/server/sidebar-sentinel.blade.php b/resources/views/components/server/sidebar-sentinel.blade.php index 8249c9413..8125fe22c 100644 --- a/resources/views/components/server/sidebar-sentinel.blade.php +++ b/resources/views/components/server/sidebar-sentinel.blade.php @@ -3,7 +3,7 @@ href="{{ route('server.sentinel', $parameters) }}"> Configuration - Logs diff --git a/resources/views/livewire/server/sentinel.blade.php b/resources/views/livewire/server/sentinel.blade.php index bbe0b7037..9ba361662 100644 --- a/resources/views/livewire/server/sentinel.blade.php +++ b/resources/views/livewire/server/sentinel.blade.php @@ -35,7 +35,8 @@ $wire.set('sentinelCustomDockerImage', this.customImage); } }" x-init="$wire.set('sentinelCustomDockerImage', customImage)"> - diff --git a/tests/Feature/Livewire/SentinelComponentTest.php b/tests/Feature/Livewire/SentinelComponentTest.php new file mode 100644 index 000000000..47cad4e22 --- /dev/null +++ b/tests/Feature/Livewire/SentinelComponentTest.php @@ -0,0 +1,21 @@ +.*?)\n \}/s', $componentSource, $matches); + + expect($matches['body'] ?? '') + ->toContain('$this->sentinelUpdatedAt = $this->server->sentinel_updated_at;') + ->not->toContain('$this->syncData();'); +}); + +it('dispatches a server navbar refresh after toggling sentinel', function () { + $componentSource = file_get_contents(app_path('Livewire/Server/Sentinel.php')); + + preg_match('/public function toggleSentinel\([^)]*\).*?\{(?.*?) + \}/s', $componentSource, $matches); + + expect($matches['body'] ?? '') + ->toContain("\$this->dispatch('refreshServerShow');"); +});