Skip to content

Commit

Permalink
fix(env): shared variables can not be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
peaklabs-dev committed Jan 22, 2025
1 parent c3c032e commit 9f3c6b4
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions app/Livewire/Project/Shared/EnvironmentVariable/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,28 @@ public function refresh()
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;
Expand Down Expand Up @@ -141,30 +151,15 @@ public function instantSave()
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');
Expand Down

0 comments on commit 9f3c6b4

Please sign in to comment.