Add ability to delete configurations

This commit is contained in:
Dominic Ferrando
2026-07-10 11:41:15 -04:00
parent 19da9e62f6
commit 0ed1945b06
3 changed files with 62 additions and 3 deletions
@@ -54,6 +54,7 @@
let saveError = $state<string | null>(null);
let saving = $state(false);
let settingLive = $state(false);
let deleting = $state(false);
const allStandards = $derived(
editor
@@ -229,6 +230,26 @@
await loadConfig(editor.configId, { skipDirtyCheck: true });
}
async function deleteConfig() {
if (!editor?.configId || isLive) return;
if (!confirm(`Delete "${editor.name || "(untitled)"}"? This cannot be undone.`))
return;
const configId = editor.configId;
saveError = null;
deleting = true;
try {
const res = await api.standards.configs({ id: configId }).delete();
if (res.error) throw res.error;
localStorage.removeItem(DRAFT_KEY);
await refreshLists();
if (liveConfigId) await loadConfig(liveConfigId, { skipDirtyCheck: true });
} catch (err) {
saveError = errorMessage(err);
} finally {
deleting = false;
}
}
async function setLive() {
if (!editor?.configId || isDirty) return;
const configId = editor.configId;
@@ -346,7 +367,7 @@
class="btn btn-ghost btn-sm btn-square"
title="Save as new configuration"
aria-label="Save as new configuration"
disabled={saving}
disabled={saving || deleting}
onclick={promptSaveAsNew}
>
<span class="text-lg leading-none">+</span>
@@ -377,7 +398,7 @@
<button
class="btn btn-primary btn-sm"
hidden={isLive && !isDirty}
disabled={saving || !isDirty || isLive}
disabled={saving || !isDirty || isLive || deleting}
onclick={save}
>
{saving ? "Saving..." : "Save"}
@@ -385,11 +406,34 @@
<button
class="btn btn-outline btn-sm"
hidden={currentEditor.configId === liveConfigId}
disabled={settingLive || isDirty}
disabled={settingLive || isDirty || deleting}
onclick={setLive}
>
{settingLive ? "Setting live..." : "Set as live"}
</button>
<details hidden={isLive} class="dropdown dropdown-end">
<summary
class="btn btn-ghost btn-sm btn-square list-none"
title="More actions"
aria-label="More actions"
>
<span class="text-lg leading-none"></span>
</summary>
<ul
class="dropdown-content menu bg-base-200 border border-base-300 rounded-box z-20 w-40 p-2 shadow-lg mt-2"
>
<li>
<button
class="text-error"
disabled={deleting || isLive || !currentEditor.configId}
onclick={deleteConfig}
>
{deleting ? "Deleting..." : "Delete"}
</button>
</li>
</ul>
</details>
</div>
{#if saveError}