Skip to content

Commit c2c0afa

Browse files
committed
fix: service env orders, application env orders
1 parent 611f70d commit c2c0afa

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

app/Livewire/Project/Shared/EnvironmentVariable/All.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,15 @@ public function instantSave()
5353

5454
public function sortEnvironmentVariables()
5555
{
56-
if ($this->resource->type() === 'application') {
57-
$this->resource->load(['environment_variables', 'environment_variables_preview']);
58-
} else {
59-
$this->resource->load(['environment_variables']);
60-
}
61-
62-
$sortBy = data_get($this->resource, 'settings.is_env_sorting_enabled') ? 'key' : 'order';
63-
64-
$sortFunction = function ($variables) use ($sortBy) {
65-
if (! $variables) {
66-
return $variables;
56+
if (! data_get($this->resource, 'settings.is_env_sorting_enabled')) {
57+
if ($this->resource->environment_variables) {
58+
$this->resource->environment_variables = $this->resource->environment_variables->sortBy('order')->values();
6759
}
68-
if ($sortBy === 'key') {
69-
return $variables->sortBy(function ($item) {
70-
return strtolower($item->key);
71-
}, SORT_NATURAL | SORT_FLAG_CASE)->values();
72-
} else {
73-
return $variables->sortBy('order')->values();
74-
}
75-
};
7660

77-
$this->resource->environment_variables = $sortFunction($this->resource->environment_variables);
78-
$this->resource->environment_variables_preview = $sortFunction($this->resource->environment_variables_preview);
61+
if ($this->resource->environment_variables_preview) {
62+
$this->resource->environment_variables_preview = $this->resource->environment_variables_preview->sortBy('order')->values();
63+
}
64+
}
7965

8066
$this->getDevView();
8167
}
@@ -121,6 +107,8 @@ public function submit($data = null)
121107
$this->sortEnvironmentVariables();
122108
} catch (\Throwable $e) {
123109
return handleError($e, $this);
110+
} finally {
111+
$this->refreshEnvs();
124112
}
125113
}
126114

app/Models/Service.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,12 +1076,12 @@ public function scheduled_tasks(): HasMany
10761076
public function environment_variables(): HasMany
10771077
{
10781078

1079-
return $this->hasMany(EnvironmentVariable::class)->orderByRaw("key LIKE 'SERVICE%' DESC, value ASC");
1079+
return $this->hasMany(EnvironmentVariable::class)->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
10801080
}
10811081

10821082
public function environment_variables_preview(): HasMany
10831083
{
1084-
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->orderBy('key', 'asc');
1084+
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
10851085
}
10861086

10871087
public function workdir()

resources/views/livewire/project/shared/environment-variable/all.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
@else
5757
<form wire:submit.prevent='submit' class="flex flex-col gap-2">
5858
<x-forms.textarea rows="10" class="whitespace-pre-wrap" id="variables" wire:model="variables" label="Production Environment Variables"></x-forms.textarea>
59-
59+
6060
@if ($showPreview)
6161
<x-forms.textarea rows="10" class="whitespace-pre-wrap" label="Preview Deployments Environment Variables"
6262
id="variablesPreview" wire:model="variablesPreview"></x-forms.textarea>
6363
@endif
64-
64+
6565
<x-forms.button type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
6666
</form>
6767
@endif
68-
</div>
68+
</div>

0 commit comments

Comments
 (0)