From 623d367a2ad13a0235e11cb628f381d09e38e146 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 29 Oct 2026 11:18:02 +0100 Subject: [PATCH] fix(env): keep preview variable order when sorting is disabled Closes #9876 --- app/Models/Application.php | 10 +--------- .../EnvironmentVariableDevViewDirectiveTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Models/Application.php b/app/Models/Application.php index ce6ca04afe..1ea0bc9114 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1216,15 +1216,7 @@ class Application extends BaseModel public function environment_variables_preview() { return $this->morphMany(EnvironmentVariable::class, 'resourceable') - ->where('is_preview', true) - ->orderByRaw(" - CASE - WHEN is_required = true THEN 1 - WHEN LOWER(key) LIKE 'service_%' THEN 2 - ELSE 3 - END, - LOWER(key) ASC - "); + ->where('is_preview', true); } public function runtime_environment_variables_preview() diff --git a/tests/Feature/EnvironmentVariableDevViewDirectiveTest.php b/tests/Feature/EnvironmentVariableDevViewDirectiveTest.php index 2a963edbef..8ce8a51e20 100644 --- a/tests/Feature/EnvironmentVariableDevViewDirectiveTest.php +++ b/tests/Feature/EnvironmentVariableDevViewDirectiveTest.php @@ -144,3 +144,15 @@ it('names the preview text area in a directive error', function () { ->call('submit') ->assertDispatched('error', 'Preview deployments: Line 2: a "# coolify:" line must be directly above a KEY=value line.'); }); + +it('keeps the saved order of preview variables when alphabetical sorting is disabled', function () { + $component = ($this->devView)() + ->assertSet('showPreview', true) + ->assertSet('is_env_sorting_enabled', false) + ->set('variablesPreview', "ZEBRA=1\nALPHA=2\nMIDDLE=3") + ->call('submit') + ->assertNotDispatched('error'); + + expect($component->get('variablesPreview'))->toBe("ZEBRA=1\nALPHA=2\nMIDDLE=3") + ->and($component->instance()->environmentVariablesPreview->pluck('key')->all())->toBe(['ZEBRA', 'ALPHA', 'MIDDLE']); +});