fix(env): keep preview variable order when sorting is disabled

Closes #9876
This commit is contained in:
Andras Bacsai
2026-10-29 11:18:02 +01:00
parent 6f8cf50402
commit 623d367a2a
2 changed files with 13 additions and 9 deletions
+1 -9
View File
@@ -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()
@@ -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']);
});