From 9f3c6b4b76347805a03cf12a1baca245f1a4cf4e Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Wed, 22 Jan 2025 17:02:11 +0100 Subject: [PATCH] fix(env): shared variables can not be updated --- .../Shared/EnvironmentVariable/Show.php | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php index 4b66bfdcb..3a7d0faa5 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php @@ -77,18 +77,28 @@ class Show extends Component public function syncData(bool $toModel = false) { if ($toModel) { - $this->validate(); + if ($this->isSharedVariable) { + $this->validate([ + 'key' => 'required|string', + 'value' => 'nullable', + 'is_multiline' => 'required|boolean', + 'is_literal' => 'required|boolean', + 'is_shown_once' => 'required|boolean', + 'real_value' => 'nullable', + ]); + } else { + $this->validate(); + $this->env->is_build_time = $this->is_build_time; + $this->env->is_required = $this->is_required; + $this->env->is_shared = $this->is_shared; + } $this->env->key = $this->key; $this->env->value = $this->value; - $this->env->is_build_time = $this->is_build_time; $this->env->is_multiline = $this->is_multiline; $this->env->is_literal = $this->is_literal; $this->env->is_shown_once = $this->is_shown_once; - $this->env->is_required = $this->is_required; - $this->env->is_shared = $this->is_shared; $this->env->save(); } else { - $this->key = $this->env->key; $this->value = $this->env->value; $this->is_build_time = $this->env->is_build_time ?? false; @@ -141,30 +151,15 @@ class Show extends Component public function submit() { try { - if ($this->isSharedVariable) { - $this->validate([ - 'key' => 'required|string', - 'value' => 'nullable', - 'is_shown_once' => 'required|boolean', - ]); - } else { - $this->validate(); - } - if (! $this->isSharedVariable && $this->is_required && str($this->value)->isEmpty()) { $oldValue = $this->env->getOriginal('value'); $this->value = $oldValue; - $this->dispatch('error', 'Required environment variable cannot be empty.'); + $this->dispatch('error', 'Required environment variables cannot be empty.'); return; } $this->serialize(); - - if ($this->isSharedVariable) { - unset($this->is_required); - } - $this->syncData(true); $this->dispatch('success', 'Environment variable updated.'); $this->dispatch('envsUpdated');