Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: service env orders, application env orders

Andras Bacsaic2c0afa0bab4
diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php
index 055788b576..5a711259b2 100644
--- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php
+++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php
@@ -53,29 +53,15 @@ class All extends Component
public function sortEnvironmentVariables()
{
- if ($this->resource->type() === 'application') {
- $this->resource->load(['environment_variables', 'environment_variables_preview']);
- } else {
- $this->resource->load(['environment_variables']);
- }
-
- $sortBy = data_get($this->resource, 'settings.is_env_sorting_enabled') ? 'key' : 'order';
-
- $sortFunction = function ($variables) use ($sortBy) {
- if (! $variables) {
- return $variables;
+ if (! data_get($this->resource, 'settings.is_env_sorting_enabled')) {
+ if ($this->resource->environment_variables) {
+ $this->resource->environment_variables = $this->resource->environment_variables->sortBy('order')->values();
}
- if ($sortBy === 'key') {
- return $variables->sortBy(function ($item) {
- return strtolower($item->key);
- }, SORT_NATURAL | SORT_FLAG_CASE)->values();
- } else {
- return $variables->sortBy('order')->values();
- }
- };
- $this->resource->environment_variables = $sortFunction($this->resource->environment_variables);
- $this->resource->environment_variables_preview = $sortFunction($this->resource->environment_variables_preview);
+ if ($this->resource->environment_variables_preview) {
+ $this->resource->environment_variables_preview = $this->resource->environment_variables_preview->sortBy('order')->values();
+ }
+ }
$this->getDevView();
}
@@ -121,6 +107,8 @@ class All extends Component
$this->sortEnvironmentVariables();
} catch (\Throwable $e) {
return handleError($e, $this);
+ } finally {
+ $this->refreshEnvs();
}
}
diff --git a/app/Models/Service.php b/app/Models/Service.php
index 6329345240..1c5979644e 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -1076,12 +1076,12 @@ class Service extends BaseModel
public function environment_variables(): HasMany
{
- return $this->hasMany(EnvironmentVariable::class)->orderByRaw("key LIKE 'SERVICE%' DESC, value ASC");
+ return $this->hasMany(EnvironmentVariable::class)->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
}
public function environment_variables_preview(): HasMany
{
- return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->orderBy('key', 'asc');
+ return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
}
public function workdir()
diff --git a/resources/views/livewire/project/shared/environment-variable/all.blade.php b/resources/views/livewire/project/shared/environment-variable/all.blade.php
index bd6f315517..5e8aa7d63a 100644
--- a/resources/views/livewire/project/shared/environment-variable/all.blade.php
+++ b/resources/views/livewire/project/shared/environment-variable/all.blade.php
@@ -56,13 +56,13 @@
@else
<form wire:submit.prevent='submit' class="flex flex-col gap-2">
<x-forms.textarea rows="10" class="whitespace-pre-wrap" id="variables" wire:model="variables" label="Production Environment Variables"></x-forms.textarea>
-
+
@if ($showPreview)
<x-forms.textarea rows="10" class="whitespace-pre-wrap" label="Preview Deployments Environment Variables"
id="variablesPreview" wire:model="variablesPreview"></x-forms.textarea>
@endif
-
+
<x-forms.button type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
</form>
@endif
-</div>
\ No newline at end of file
+</div>