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(server): list the active private key first

Andras Bacsai64b748008e56
diff --git a/app/Livewire/Server/PrivateKey/Show.php b/app/Livewire/Server/PrivateKey/Show.php
index 7bc02aa03d..97eb760d2c 100644
--- a/app/Livewire/Server/PrivateKey/Show.php
+++ b/app/Livewire/Server/PrivateKey/Show.php
@@ -30,7 +30,10 @@ class Show extends Component
private function loadPrivateKeys(): void
{
- $this->privateKeys = PrivateKey::where('team_id', $this->server->team_id)->get()->where('is_git_related', false);
+ $this->privateKeys = PrivateKey::where('team_id', $this->server->team_id)->get()
+ ->where('is_git_related', false)
+ ->sortBy(fn (PrivateKey $privateKey) => $privateKey->id !== $this->server->private_key_id)
+ ->values();
}
public function setPrivateKey($privateKeyId)
@@ -51,6 +54,7 @@ class Show extends Component
throw new \Exception($error);
}
});
+ $this->loadPrivateKeys();
$this->dispatch('success', 'Private key updated successfully.');
$this->dispatch('refreshServerShow');
} catch (\Exception $e) {
diff --git a/tests/Feature/ServerPrivateKeyDropdownTest.php b/tests/Feature/ServerPrivateKeyDropdownTest.php
index 8951491a97..a8d9aaeced 100644
--- a/tests/Feature/ServerPrivateKeyDropdownTest.php
+++ b/tests/Feature/ServerPrivateKeyDropdownTest.php
@@ -135,4 +135,13 @@ describe('after the user switches the session team', function () {
expect($this->server->fresh()->private_key_id)->toBe($this->sameTeamKey->id);
});
+
+ test('lists the active key first', function () {
+ expect($this->component->get('privateKeys')->first()->id)->toBe($this->currentPrivateKey->id);
+
+ $keys = $this->component->call('setPrivateKey', $this->sameTeamKey->id)->get('privateKeys');
+
+ expect($keys->first()->id)->toBe($this->sameTeamKey->id)
+ ->and($keys->pluck('id'))->toContain($this->currentPrivateKey->id);
+ });
});