diff --git a/app/Livewire/Project/Service/Heading.php b/app/Livewire/Project/Service/Heading.php index e8d5375038..9f26871500 100644 --- a/app/Livewire/Project/Service/Heading.php +++ b/app/Livewire/Project/Service/Heading.php @@ -35,11 +35,18 @@ class Heading extends Component public $title = 'Configuration'; + /** + * The container statuses of the stack resources at the last check. + * The heading polls them, so it tells the resource cards when they change. + */ + public ?string $resourceStatuses = null; + public function mount() { $this->authorizeService('view'); $this->checkDeployments(); + $this->resourceStatuses = $this->currentResourceStatuses(); if (str($this->service->status)->contains('running') && is_null($this->service->config_hash)) { $this->service->isConfigurationChanged(true); @@ -64,6 +71,7 @@ class Heading extends Component $this->authorizeService('view'); $this->checkDeployments(); + $this->dispatchIfResourceStatusesChanged(); if ($this->service->server->isFunctional()) { GetContainersStatus::dispatch($this->service->server); @@ -72,6 +80,24 @@ class Heading extends Component } } + private function dispatchIfResourceStatusesChanged(): void + { + $statuses = $this->currentResourceStatuses(); + if ($statuses === $this->resourceStatuses) { + return; + } + + $this->resourceStatuses = $statuses; + $this->dispatch('serviceResourceStatusesChanged'); + } + + private function currentResourceStatuses(): string + { + return $this->service->applications->pluck('status', 'uuid') + ->merge($this->service->databases->pluck('status', 'uuid')) + ->toJson(); + } + public function manualCheckStatus() { $this->checkStatus(); diff --git a/app/Livewire/Project/Service/ResourceCard.php b/app/Livewire/Project/Service/ResourceCard.php index 5b67baab01..5aed2df256 100644 --- a/app/Livewire/Project/Service/ResourceCard.php +++ b/app/Livewire/Project/Service/ResourceCard.php @@ -23,10 +23,13 @@ class ResourceCard extends Component public function getListeners(): array { - return $this->teamChannelListeners([ - 'ServiceStatusChanged' => 'refreshResource', - 'ServiceChecked' => 'refreshResource', - ]); + return [ + 'serviceResourceStatusesChanged' => 'refreshResource', + ...$this->teamChannelListeners([ + 'ServiceStatusChanged' => 'refreshResource', + 'ServiceChecked' => 'refreshResource', + ]), + ]; } public function refreshResource(): void diff --git a/app/Livewire/Project/Service/Status.php b/app/Livewire/Project/Service/Status.php index e807e22171..45df443dc8 100644 --- a/app/Livewire/Project/Service/Status.php +++ b/app/Livewire/Project/Service/Status.php @@ -22,10 +22,13 @@ class Status extends Component public function getListeners(): array { - return $this->teamChannelListeners([ - 'ServiceStatusChanged' => 'refreshStatus', - 'ServiceChecked' => 'refreshStatus', - ]); + return [ + 'serviceResourceStatusesChanged' => 'refreshStatus', + ...$this->teamChannelListeners([ + 'ServiceStatusChanged' => 'refreshStatus', + 'ServiceChecked' => 'refreshStatus', + ]), + ]; } public function refreshStatus(): void