Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions ui/src/ChangeVersionModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

let trains: Record<string, { version: string; tag: string }[]> = {};
let loading = true;
// Why the list could not be had, kept apart from a registry that simply
// has no tags: the two read the same otherwise, and a failed request
// looked like an image with nothing published.
let loadError = '';
let train = '';
let versionTag = '';
let customTag = '';
Expand Down Expand Up @@ -49,11 +53,27 @@
} catch {}
}

onMount(async () => {
async function load() {
loading = true;
loadError = '';
try {
const res = await fetch(`/api/registry/versions?image=${encodeURIComponent(repo)}`);
if (res.ok) trains = await res.json();
} catch {}
if (res.ok) trains = (await res.json()) ?? {};
else {
let msg = (await res.text()).trim();
try {
msg = JSON.parse(msg).error || msg; // the sign-in gate answers in JSON
} catch {}
loadError = msg || `${res.status} ${res.statusText}`;
}
} catch (e) {
loadError = e instanceof Error ? e.message : String(e);
}
pickDefault();
loading = false;
}

function pickDefault() {
// Default the picker to the suggested tag (an upgrade target) if given,
// else the currently-deployed tag.
const target = suggestTag || currentTag;
Expand All @@ -68,8 +88,9 @@
}
}
if (!train) train = trainList[0] || currentTag;
loading = false;
});
}

onMount(load);

function apply() {
if (!tag) return;
Expand All @@ -94,6 +115,11 @@

{#if loading}
<p class="text-fjord-fg-dim text-sm">Loading published versions…</p>
{:else if loadError}
<p class="text-fjord-warning text-sm">
Could not load the published versions: {loadError}
<button on:click={load} class="ml-1 underline decoration-dotted hover:text-fjord-warning/80">Try again</button>
</p>
{:else if trainList.length === 0}
<p class="text-fjord-fg-dim text-sm">No published tags found for this image.</p>
{:else}
Expand Down Expand Up @@ -121,6 +147,9 @@
</select>
</div>
</div>
{/if}

{#if !loading}
<div class="flex items-center gap-2 mt-3">
<input
bind:value={customTag}
Expand All @@ -132,9 +161,6 @@
{#if noBuild}
<p class="text-xs text-fjord-warning mt-2">{noBuild}</p>
{/if}
{/if}

{#if !loading}
<label class="flex items-start gap-2 mt-4 cursor-pointer select-none">
<input type="checkbox" bind:checked={pin} class="mt-0.5 accent-fjord-accent" />
<span class="text-sm text-fjord-fg-secondary">
Expand All @@ -159,7 +185,13 @@
disabled={applying || !tag || !dirty || !!noBuild}
title={noBuild || undefined}
class="px-4 py-2 rounded-md font-medium text-white bg-fjord-accent hover:bg-fjord-accent-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
>{applying ? 'Applying…' : tag !== currentTag ? 'Change & Redeploy' : pin ? 'Pin' : 'Unpin'}</button
>{applying
? 'Applying…'
: tag === currentTag && pin !== currentlyPinned
? pin
? 'Pin'
: 'Unpin'
: 'Change & Redeploy'}</button
>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions ui/src/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -4869,3 +4869,8 @@ msgstr "New stack"
#: src/App.svelte
msgid "Write the compose file yourself"
msgstr "Write the compose file yourself"

#. 0: loadError
#: src/ChangeVersionModal.svelte
msgid "Could not load the published versions: {0} <0>Try again</0>"
msgstr "Could not load the published versions: {0} <0>Try again</0>"
5 changes: 5 additions & 0 deletions ui/src/locales/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -4858,3 +4858,8 @@ msgstr "Nouvelle pile"
#: src/App.svelte
msgid "Write the compose file yourself"
msgstr "Écrivez vous-même le fichier compose"

#. 0: loadError
#: src/ChangeVersionModal.svelte
msgid "Could not load the published versions: {0} <0>Try again</0>"
msgstr "Impossible de charger les versions publiées : {0} <0>Réessayer</0>"
Loading