From a03c1b3b4b69e0f21a24f136fd79e1aa5a1dfcaf Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 30 Sep 2025 11:43:30 +0200 Subject: [PATCH] refactor(dashboard): remove deployment loading logic and introduce DeploymentsIndicator component for better UI management --- app/Livewire/Dashboard.php | 33 ------- app/Livewire/DeploymentsIndicator.php | 49 ++++++++++ .../Project/Application/PreviewsCompose.php | 2 +- app/Livewire/Project/Shared/HealthChecks.php | 6 +- app/Livewire/Server/Advanced.php | 5 - app/Traits/ExecuteRemoteCommand.php | 2 +- bootstrap/helpers/socialite.php | 2 +- database/factories/TeamFactory.php | 4 +- resources/views/layouts/app.blade.php | 1 + resources/views/livewire/dashboard.blade.php | 48 ---------- .../livewire/deployments-indicator.blade.php | 92 +++++++++++++++++++ 11 files changed, 150 insertions(+), 94 deletions(-) create mode 100644 app/Livewire/DeploymentsIndicator.php create mode 100644 resources/views/livewire/deployments-indicator.blade.php diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php index 18dbde0d3..45781af30 100644 --- a/app/Livewire/Dashboard.php +++ b/app/Livewire/Dashboard.php @@ -2,13 +2,10 @@ namespace App\Livewire; -use App\Models\Application; -use App\Models\ApplicationDeploymentQueue; use App\Models\PrivateKey; use App\Models\Project; use App\Models\Server; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\Artisan; use Livewire\Component; class Dashboard extends Component @@ -19,41 +16,11 @@ class Dashboard extends Component public Collection $privateKeys; - public array $deploymentsPerServer = []; - public function mount() { $this->privateKeys = PrivateKey::ownedByCurrentTeam()->get(); $this->servers = Server::ownedByCurrentTeam()->get(); $this->projects = Project::ownedByCurrentTeam()->get(); - $this->loadDeployments(); - } - - public function cleanupQueue() - { - try { - $this->authorize('cleanupDeploymentQueue', Application::class); - } catch (\Illuminate\Auth\Access\AuthorizationException $e) { - return handleError($e, $this); - } - - Artisan::queue('cleanup:deployment-queue', [ - '--team-id' => currentTeam()->id, - ]); - } - - public function loadDeployments() - { - $this->deploymentsPerServer = ApplicationDeploymentQueue::whereIn('status', ['in_progress', 'queued'])->whereIn('server_id', $this->servers->pluck('id'))->get([ - 'id', - 'application_id', - 'application_name', - 'deployment_url', - 'pull_request_id', - 'server_name', - 'server_id', - 'status', - ])->sortBy('id')->groupBy('server_name')->toArray(); } public function navigateToProject($projectUuid) diff --git a/app/Livewire/DeploymentsIndicator.php b/app/Livewire/DeploymentsIndicator.php new file mode 100644 index 000000000..34529a7e7 --- /dev/null +++ b/app/Livewire/DeploymentsIndicator.php @@ -0,0 +1,49 @@ +get(); + + return ApplicationDeploymentQueue::whereIn('status', ['in_progress', 'queued']) + ->whereIn('server_id', $servers->pluck('id')) + ->get([ + 'id', + 'application_id', + 'application_name', + 'deployment_url', + 'pull_request_id', + 'server_name', + 'server_id', + 'status', + ]) + ->sortBy('id'); + } + + #[Computed] + public function deploymentCount() + { + return $this->deployments->count(); + } + + public function toggleExpanded() + { + $this->expanded = ! $this->expanded; + } + + public function render() + { + return view('livewire.deployments-indicator'); + } +} diff --git a/app/Livewire/Project/Application/PreviewsCompose.php b/app/Livewire/Project/Application/PreviewsCompose.php index 7641edcc5..cfb364b6d 100644 --- a/app/Livewire/Project/Application/PreviewsCompose.php +++ b/app/Livewire/Project/Application/PreviewsCompose.php @@ -73,7 +73,7 @@ public function generate() $host = $url->getHost(); $schema = $url->getScheme(); $portInt = $url->getPort(); - $port = $portInt !== null ? ':' . $portInt : ''; + $port = $portInt !== null ? ':'.$portInt : ''; $random = new Cuid2; $preview_fqdn = str_replace('{{random}}', $random, $template); $preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn); diff --git a/app/Livewire/Project/Shared/HealthChecks.php b/app/Livewire/Project/Shared/HealthChecks.php index ee11c496d..c0714fe03 100644 --- a/app/Livewire/Project/Shared/HealthChecks.php +++ b/app/Livewire/Project/Shared/HealthChecks.php @@ -52,13 +52,13 @@ public function toggleHealthcheck() try { $this->authorize('update', $this->resource); $wasEnabled = $this->resource->health_check_enabled; - $this->resource->health_check_enabled = !$this->resource->health_check_enabled; + $this->resource->health_check_enabled = ! $this->resource->health_check_enabled; $this->resource->save(); - if ($this->resource->health_check_enabled && !$wasEnabled && $this->resource->isRunning()) { + if ($this->resource->health_check_enabled && ! $wasEnabled && $this->resource->isRunning()) { $this->dispatch('info', 'Health check has been enabled. A restart is required to apply the new settings.'); } else { - $this->dispatch('success', 'Health check ' . ($this->resource->health_check_enabled ? 'enabled' : 'disabled') . '.'); + $this->dispatch('success', 'Health check '.($this->resource->health_check_enabled ? 'enabled' : 'disabled').'.'); } } catch (\Throwable $e) { return handleError($e, $this); diff --git a/app/Livewire/Server/Advanced.php b/app/Livewire/Server/Advanced.php index bbc3bd96a..8d17bb557 100644 --- a/app/Livewire/Server/Advanced.php +++ b/app/Livewire/Server/Advanced.php @@ -2,10 +2,7 @@ namespace App\Livewire\Server; -use App\Models\InstanceSettings; use App\Models\Server; -use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Hash; use Livewire\Attributes\Validate; use Livewire\Component; @@ -39,8 +36,6 @@ public function mount(string $server_uuid) } } - - public function syncData(bool $toModel = false) { if ($toModel) { diff --git a/app/Traits/ExecuteRemoteCommand.php b/app/Traits/ExecuteRemoteCommand.php index 8fa47f543..4aa5aae8b 100644 --- a/app/Traits/ExecuteRemoteCommand.php +++ b/app/Traits/ExecuteRemoteCommand.php @@ -269,4 +269,4 @@ private function addRetryLogEntry(int $attempt, int $maxRetries, int $delay, str $this->application_deployment_queue->save(); } -} \ No newline at end of file +} diff --git a/bootstrap/helpers/socialite.php b/bootstrap/helpers/socialite.php index 3b20f2d89..fd3fbe74b 100644 --- a/bootstrap/helpers/socialite.php +++ b/bootstrap/helpers/socialite.php @@ -75,7 +75,7 @@ function get_socialite_provider(string $provider) $config ); - if ($provider == 'gitlab' && !empty($oauth_setting->base_url)) { + if ($provider == 'gitlab' && ! empty($oauth_setting->base_url)) { $socialite->setHost($oauth_setting->base_url); } diff --git a/database/factories/TeamFactory.php b/database/factories/TeamFactory.php index 0e95842b4..26748c54e 100644 --- a/database/factories/TeamFactory.php +++ b/database/factories/TeamFactory.php @@ -20,7 +20,7 @@ class TeamFactory extends Factory public function definition(): array { return [ - 'name' => $this->faker->company() . ' Team', + 'name' => $this->faker->company().' Team', 'description' => $this->faker->sentence(), 'personal_team' => false, 'show_boarding' => false, @@ -34,7 +34,7 @@ public function personal(): static { return $this->state(fn (array $attributes) => [ 'personal_team' => true, - 'name' => $this->faker->firstName() . "'s Team", + 'name' => $this->faker->firstName()."'s Team", ]); } } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index bb6533932..409f66ad9 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -7,6 +7,7 @@ @auth +
-

Deployments

- @if (count($deploymentsPerServer) > 0) - - @endif - @can('cleanupDeploymentQueue', Application::class) - - @endcan -
- - - @endif diff --git a/resources/views/livewire/deployments-indicator.blade.php b/resources/views/livewire/deployments-indicator.blade.php new file mode 100644 index 000000000..0ebaab9f8 --- /dev/null +++ b/resources/views/livewire/deployments-indicator.blade.php @@ -0,0 +1,92 @@ +
+ @if ($this->deploymentCount > 0) + + @endif +