From 6820fcc084d7d5dae6c31c56a6d5284fd04492b4 Mon Sep 17 00:00:00 2001 From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:53:49 +0200 Subject: [PATCH] Fix name for services and DBs --- app/Livewire/Project/Shared/Danger.php | 69 ++++++++++-- .../components/modal-confirmation.blade.php | 103 ++++-------------- 2 files changed, 76 insertions(+), 96 deletions(-) diff --git a/app/Livewire/Project/Shared/Danger.php b/app/Livewire/Project/Shared/Danger.php index 85eeb8249..18a9e5d6b 100644 --- a/app/Livewire/Project/Shared/Danger.php +++ b/app/Livewire/Project/Shared/Danger.php @@ -32,16 +32,61 @@ class Danger extends Component $this->projectUuid = data_get($parameters, 'project_uuid'); $this->environmentName = data_get($parameters, 'environment_name'); - // Determine the resource name based on the available properties - if ($this->resource) { - $this->resourceName = $this->resource->name ?? 'Resource'; - } elseif ($this->service) { - $this->resourceName = $this->service->name ?? 'Service'; //this does not get the name of the service - } else { - $this->resourceName = 'Unknown Resource'; //service is here? + ray('Mount method called'); + + if ($this->resource === null) { + if (isset($parameters['service_uuid'])) { + $this->resource = Service::where('uuid', $parameters['service_uuid'])->first(); + } elseif (isset($parameters['stack_service_uuid'])) { + $this->resource = ServiceApplication::where('uuid', $parameters['stack_service_uuid'])->first() + ?? ServiceDatabase::where('uuid', $parameters['stack_service_uuid'])->first(); + } + } + + ray('Resource:', $this->resource); + + if ($this->resource === null) { + ray('Resource is null'); + $this->resourceName = 'Unknown Resource'; + return; + } + + if (!method_exists($this->resource, 'type')) { + ray('Resource does not have type() method'); + $this->resourceName = 'Unknown Resource'; + return; + } + + ray('Resource type:', $this->resource->type()); + + switch ($this->resource->type()) { + case 'application': + $this->resourceName = $this->resource->name ?? 'Application'; + break; + case 'standalone-postgresql': + case 'standalone-redis': + case 'standalone-mongodb': + case 'standalone-mysql': + case 'standalone-mariadb': + case 'standalone-keydb': + case 'standalone-dragonfly': + case 'standalone-clickhouse': + $this->resourceName = $this->resource->name ?? 'Database'; + break; + case 'service': + $this->resourceName = $this->resource->name ?? 'Service'; + break; + case 'service-application': + $this->resourceName = $this->resource->name ?? 'Service Application'; + break; + case 'service-database': + $this->resourceName = $this->resource->name ?? 'Service Database'; + break; + default: + $this->resourceName = 'Unknown Resource'; } - ray($this->resourceName); + ray('Final resource name:', $this->resourceName); } public function delete($password) @@ -76,8 +121,8 @@ class Danger extends Component } } - public function render() - { - return view('livewire.project.shared.danger'); - } + // public function render() + // { + // return view('livewire.project.shared.danger'); + // } } diff --git a/resources/views/components/modal-confirmation.blade.php b/resources/views/components/modal-confirmation.blade.php index ce5d7177d..2b86fe475 100644 --- a/resources/views/components/modal-confirmation.blade.php +++ b/resources/views/components/modal-confirmation.blade.php @@ -114,34 +114,13 @@ @endif @endif - -