feat(webui): settings lists share a card accordion that opens the new item and blocks adding while unsaved
This commit is contained in:
1 parent
30742f9c57
commit
b12a58aae6
13 files changed
+176
-130
No files matched your search
@@ -6,6 +6,7 @@ import { Input } from "@/components/ui/input";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import CardAccordion from "./CardAccordion.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
|
||||
interface Profile { image?: string; kit?: string; adapter?: string; tools?: string[] }
|
||||
@@ -14,7 +15,11 @@ const store = useSettingsStore();
|
||||
onMounted(store.load);
|
||||
const profiles = computed(() => store.drafts[KIND]?.value as Record<string, Profile> | null);
|
||||
const name = ref("");
|
||||
const open = ref("");
|
||||
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
||||
const entries = computed(() => Object.entries(profiles.value ?? {}));
|
||||
function add() {
|
||||
if (unsaved.value) return;
|
||||
const key = name.value.trim();
|
||||
if (!key || profiles.value?.[key]) return;
|
||||
const draft = store.drafts[KIND];
|
||||
@@ -22,6 +27,7 @@ function add() {
|
||||
if (!draft.value) draft.value = {};
|
||||
(draft.value as Record<string, Profile>)[key] = { image: "", kit: "", adapter: "", tools: [] };
|
||||
name.value = "";
|
||||
open.value = String(Object.keys(draft.value as Record<string, Profile>).indexOf(key));
|
||||
}
|
||||
function tools(profile: Profile, value: string | number) {
|
||||
profile.tools = String(value).split(",").map(tool => tool.trim()).filter(Boolean);
|
||||
@@ -33,16 +39,17 @@ function tools(profile: Profile, value: string | number) {
|
||||
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
||||
<p v-if="store.catalogError || store.pageErrorFor(KIND)" class="mb-4 text-sm text-destructive" role="alert">{{ store.catalogError || store.pageErrorFor(KIND) }}</p>
|
||||
<form class="mb-4 flex gap-2" @submit.prevent="add">
|
||||
<Input v-model="name" aria-label="Profile name" placeholder="Profile name" class="max-w-xs" />
|
||||
<Button type="submit" :disabled="!name.trim() || !!profiles?.[name.trim()]">Add profile</Button>
|
||||
<Input v-model="name" aria-label="Profile name" placeholder="Profile name" class="max-w-xs" :disabled="unsaved" />
|
||||
<Button type="submit" :disabled="unsaved || !name.trim() || !!profiles?.[name.trim()]">Add profile</Button>
|
||||
</form>
|
||||
<p v-if="!Object.keys(profiles ?? {}).length" class="text-sm text-fg-muted">No agent profiles.</p>
|
||||
<section v-for="(profile, key) in profiles" :key="key" class="mb-6 border-t pt-4">
|
||||
<div class="flex items-center justify-between"><h2 class="font-mono text-sm">{{ key }}</h2><Button variant="ghost" size="sm" @click="delete profiles![key]">Remove profile</Button></div>
|
||||
<CardAccordion v-model:open="open" :items="entries" :title="([key]) => key" remove-label="Remove" mono @remove="delete profiles![entries[$event]![0]]">
|
||||
<template #default="{ item: [key, profile] }">
|
||||
<SettingRow label="Image" :for="`${key}-image`"><Input :id="`${key}-image`" v-model="profile.image" placeholder="Container image" /></SettingRow>
|
||||
<SettingRow label="Kit" :for="`${key}-kit`" hint="Pinned digest. Used only when Image is empty."><Input :id="`${key}-kit`" v-model="profile.kit" placeholder="registry/kit@sha256:…" /></SettingRow>
|
||||
<SettingRow label="Adapter" :for="`${key}-adapter`"><Input :id="`${key}-adapter`" v-model="profile.adapter" /></SettingRow>
|
||||
<SettingRow label="Tools" :for="`${key}-tools`" hint="Comma-separated tool names."><Input :id="`${key}-tools`" :model-value="(profile.tools ?? []).join(', ')" @update:model-value="tools(profile, $event)" /></SettingRow>
|
||||
</section>
|
||||
</template>
|
||||
</CardAccordion>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts" generic="T">
|
||||
import { Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
/**
|
||||
* A list of configuration cards where one is open at a time. The owning page
|
||||
* opens a new card when it adds one and refuses to add another while unsaved
|
||||
* changes exist.
|
||||
*/
|
||||
defineProps<{
|
||||
items: T[];
|
||||
title: (item: T, index: number) => string;
|
||||
removeLabel: string;
|
||||
mono?: boolean;
|
||||
}>();
|
||||
const open = defineModel<string>("open", { default: "" });
|
||||
defineEmits<{ remove: [index: number] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Accordion v-model="open" type="single" collapsible class="mb-4 gap-4">
|
||||
<AccordionItem
|
||||
v-for="(item, i) in items"
|
||||
:key="i"
|
||||
:value="String(i)"
|
||||
class="rounded-lg border border-border bg-card px-5 not-last:border-b"
|
||||
>
|
||||
<header class="flex items-center gap-2 [&>h3]:min-w-0 [&>h3]:flex-1">
|
||||
<AccordionTrigger class="min-w-0 flex-1 items-center text-[15px] hover:no-underline" :class="mono && 'font-mono'">
|
||||
<span class="truncate">{{ title(item, i) }}</span>
|
||||
</AccordionTrigger>
|
||||
<slot name="aside" :item="item" :index="i" />
|
||||
<Button variant="ghost" size="icon" :aria-label="`${removeLabel} ${title(item, i)}`" @click="$emit('remove', i)"><Trash2 /></Button>
|
||||
</header>
|
||||
<AccordionContent>
|
||||
<slot :item="item" :index="i" />
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</template>
|
||||
@@ -1,11 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import CardAccordion from "./CardAccordion.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
import SecretRefField from "./SecretRefField.vue";
|
||||
interface Binding { service: string; org?: string; secret: { engine: string; key: string } }
|
||||
@@ -13,24 +14,29 @@ const KIND = "credential-bindings";
|
||||
const store = useSettingsStore();
|
||||
onMounted(store.load);
|
||||
const bindings = computed(() => store.drafts[KIND]?.value as Binding[] | null);
|
||||
const open = ref("");
|
||||
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
||||
function add() {
|
||||
if (unsaved.value) return;
|
||||
const draft = store.drafts[KIND];
|
||||
if (!draft) return;
|
||||
if (!draft.value) draft.value = [];
|
||||
(draft.value as Binding[]).push({ service: "", org: "", secret: { engine: "", key: "" } });
|
||||
open.value = String((draft.value as Binding[]).length - 1);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Credential bindings"><HistoryLink :kinds="[KIND]" /><Button @click="add">Add binding</Button></PageHeader>
|
||||
<PageHeader title="Credential bindings"><HistoryLink :kinds="[KIND]" /><Button :disabled="unsaved" @click="add">Add binding</Button></PageHeader>
|
||||
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
||||
<p v-if="store.catalogError || store.pageErrorFor(KIND)" class="mb-4 text-sm text-destructive" role="alert">{{ store.catalogError || store.pageErrorFor(KIND) }}</p>
|
||||
<p v-if="!bindings?.length" class="text-sm text-fg-muted">No credential bindings.</p>
|
||||
<section v-for="(binding, index) in bindings" :key="index" class="mb-6 border-t pt-4">
|
||||
<div class="flex justify-end"><Button variant="ghost" size="sm" @click="bindings!.splice(index, 1)">Remove binding</Button></div>
|
||||
<CardAccordion v-model:open="open" :items="bindings ?? []" :title="(b) => b.service || 'New binding'" remove-label="Remove" mono @remove="bindings!.splice($event, 1)">
|
||||
<template #default="{ item: binding, index }">
|
||||
<SettingRow label="Service" :for="`binding-${index}-service`"><Input :id="`binding-${index}-service`" v-model="binding.service" /></SettingRow>
|
||||
<SettingRow label="Organisation" :for="`binding-${index}-org`" hint="Empty uses the default organisation."><Input :id="`binding-${index}-org`" v-model="binding.org" /></SettingRow>
|
||||
<SettingRow label="Secret"><SecretRefField v-model="binding.secret" :id-prefix="`binding-${index}-secret`" /></SettingRow>
|
||||
</section>
|
||||
</template>
|
||||
</CardAccordion>
|
||||
</div>
|
||||
</template>
|
||||
@@ -6,6 +6,7 @@ import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import CardAccordion from "./CardAccordion.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
interface Playbook { id: string; yaml: string }
|
||||
const KIND = "eda-playbooks";
|
||||
@@ -13,7 +14,10 @@ const store = useSettingsStore();
|
||||
onMounted(store.load);
|
||||
const collection = computed(() => store.drafts[KIND]?.value as { playbooks: Playbook[] } | null);
|
||||
const id = ref("");
|
||||
const open = ref("");
|
||||
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
||||
function add() {
|
||||
if (unsaved.value) return;
|
||||
const key = id.value.trim();
|
||||
if (!key || collection.value?.playbooks.some(entry => entry.id === key)) return;
|
||||
const draft = store.drafts[KIND];
|
||||
@@ -21,6 +25,7 @@ function add() {
|
||||
if (!draft.value) draft.value = { playbooks: [] };
|
||||
(draft.value as { playbooks: Playbook[] }).playbooks.push({ id: key, yaml: "" });
|
||||
id.value = "";
|
||||
open.value = String((draft.value as { playbooks: Playbook[] }).playbooks.length - 1);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
@@ -28,11 +33,12 @@ function add() {
|
||||
<PageHeader title="Playbooks"><HistoryLink :kinds="[KIND]" /></PageHeader>
|
||||
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
||||
<p v-if="store.catalogError || store.pageErrorFor(KIND)" class="mb-4 text-sm text-destructive" role="alert">{{ store.catalogError || store.pageErrorFor(KIND) }}</p>
|
||||
<form class="mb-4 flex gap-2" @submit.prevent="add"><Input v-model="id" aria-label="Playbook ID" placeholder="Playbook ID" class="max-w-xs" /><Button type="submit" :disabled="!id.trim() || collection?.playbooks.some(entry => entry.id === id.trim())">Add playbook</Button></form>
|
||||
<form class="mb-4 flex gap-2" @submit.prevent="add"><Input v-model="id" aria-label="Playbook ID" placeholder="Playbook ID" class="max-w-xs" :disabled="unsaved" /><Button type="submit" :disabled="unsaved || !id.trim() || collection?.playbooks.some(entry => entry.id === id.trim())">Add playbook</Button></form>
|
||||
<p v-if="!collection?.playbooks.length" class="text-sm text-fg-muted">No playbooks installed.</p>
|
||||
<section v-for="(entry, index) in collection?.playbooks" :key="index" class="mb-6 border-t pt-4">
|
||||
<div class="mb-3 flex items-center justify-between"><label :for="`playbook-${index}`" class="font-mono text-sm">{{ entry.id }}</label><Button variant="ghost" size="sm" @click="collection!.playbooks.splice(index, 1)">Remove playbook</Button></div>
|
||||
<Textarea :id="`playbook-${index}`" v-model="entry.yaml" :aria-label="`${entry.id} YAML`" class="min-h-64 font-mono" spellcheck="false" />
|
||||
</section>
|
||||
<CardAccordion v-model:open="open" :items="collection?.playbooks ?? []" :title="(entry) => entry.id" remove-label="Remove" mono @remove="collection!.playbooks.splice($event, 1)">
|
||||
<template #default="{ item: entry, index }">
|
||||
<Textarea :id="`playbook-${index}`" v-model="entry.yaml" :aria-label="`${entry.id} YAML`" class="mb-3 min-h-64 font-mono" spellcheck="false" />
|
||||
</template>
|
||||
</CardAccordion>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import { computed, onMounted } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { CalendarClock, Plus, Trash2 } from "@lucide/vue";
|
||||
import { CalendarClock, Plus } from "@lucide/vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -19,6 +19,7 @@ import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
||||
import CardAccordion from "./CardAccordion.vue";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
|
||||
@@ -60,8 +61,12 @@ const pools = [
|
||||
{ value: "parallel", label: "Parallel" },
|
||||
];
|
||||
|
||||
const open = ref("");
|
||||
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
||||
|
||||
function add() {
|
||||
jobs.value?.push({
|
||||
if (unsaved.value || !jobs.value) return;
|
||||
jobs.value.push({
|
||||
id: "",
|
||||
kind: "workflow",
|
||||
detail: "",
|
||||
@@ -70,6 +75,7 @@ function add() {
|
||||
target: {},
|
||||
payload: { text: "" },
|
||||
});
|
||||
open.value = String(jobs.value.length - 1);
|
||||
}
|
||||
|
||||
// datetime-local speaks local wall time without a zone; the document stores
|
||||
@@ -90,7 +96,7 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
|
||||
<div>
|
||||
<PageHeader title="Schedules">
|
||||
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
||||
<Button v-if="jobs?.length" size="sm" @click="add"><Plus data-icon="inline-start" />Add schedule</Button>
|
||||
<Button v-if="jobs?.length" size="sm" :disabled="unsaved" @click="add"><Plus data-icon="inline-start" />Add schedule</Button>
|
||||
</PageHeader>
|
||||
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
|
||||
|
||||
@@ -111,17 +117,11 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
|
||||
</EmptyContent>
|
||||
</Empty>
|
||||
|
||||
<section
|
||||
v-for="(job, i) in jobs"
|
||||
:key="i"
|
||||
class="mb-4 rounded-lg border border-border bg-card px-5 pt-4 pb-2"
|
||||
:aria-label="job.detail || job.id || 'New schedule'"
|
||||
>
|
||||
<header class="flex items-center gap-2">
|
||||
<h2 class="min-w-0 flex-1 truncate text-[15px] font-medium">{{ job.detail || job.id || "New schedule" }}</h2>
|
||||
<CardAccordion v-model:open="open" :items="jobs" :title="(job) => job.detail || job.id || 'New schedule'" remove-label="Delete" @remove="jobs.splice($event, 1)">
|
||||
<template #aside="{ item: job }">
|
||||
<span v-if="job.next_run" class="text-xs text-fg-subtle">Next run {{ new Date(job.next_run).toLocaleString() }}</span>
|
||||
<Button variant="ghost" size="icon" aria-label="Delete schedule" @click="jobs.splice(i, 1)"><Trash2 /></Button>
|
||||
</header>
|
||||
</template>
|
||||
<template #default="{ item: job, index: i }">
|
||||
<SettingRow label="ID" :for="`job-${i}-id`">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`job-${i}-id`" v-model="job.id" class="max-w-sm font-mono" :aria-invalid="jobIssue(i) ? true : undefined" />
|
||||
@@ -190,7 +190,8 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
|
||||
<DraftHint :kind="KIND" :path="`${i}.pool`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</section>
|
||||
</template>
|
||||
</CardAccordion>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,9 +2,8 @@
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { Plus, Trash2 } from "@lucide/vue";
|
||||
import { Plus } from "@lucide/vue";
|
||||
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -33,6 +32,7 @@ import {
|
||||
TagsInputItemText,
|
||||
} from "@/components/ui/tags-input";
|
||||
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
||||
import CardAccordion from "./CardAccordion.vue";
|
||||
import CommandListEditor from "./CommandListEditor.vue";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
@@ -91,20 +91,8 @@ const protectOf = (repo: Repo) => repo.protect ?? [];
|
||||
<p v-if="catalogError || error" class="mb-4 text-sm text-danger" role="alert">{{ catalogError || error }}</p>
|
||||
|
||||
<template v-if="draft">
|
||||
<Accordion v-model="open" type="single" collapsible class="mb-4 gap-4">
|
||||
<AccordionItem
|
||||
v-for="(repo, i) in repos"
|
||||
:key="i"
|
||||
:value="String(i)"
|
||||
class="rounded-lg border border-border bg-card px-5 not-last:border-b"
|
||||
>
|
||||
<header class="flex items-center gap-2 [&>h3]:min-w-0 [&>h3]:flex-1">
|
||||
<AccordionTrigger class="min-w-0 flex-1 items-center font-mono text-[15px] hover:no-underline">
|
||||
<span class="truncate">{{ repo.owner }}/{{ repo.name }}</span>
|
||||
</AccordionTrigger>
|
||||
<Button variant="ghost" size="icon" :aria-label="`Remove ${repo.owner}/${repo.name}`" @click="repos.splice(i, 1)"><Trash2 /></Button>
|
||||
</header>
|
||||
<AccordionContent>
|
||||
<CardAccordion v-model:open="open" :items="repos" :title="(r) => `${r.owner}/${r.name}`" remove-label="Remove" mono @remove="repos.splice($event, 1)">
|
||||
<template #default="{ item: repo, index: i }">
|
||||
<SettingRow label="Base branch" :for="`repo-${i}-base`">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`repo-${i}-base`" v-model="repo.base" class="max-w-56 font-mono" />
|
||||
@@ -181,9 +169,8 @@ const protectOf = (repo: Repo) => repo.protect ?? [];
|
||||
<DraftHint :kind="KIND" :path="`${i}.allow_concurrent`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</template>
|
||||
</CardAccordion>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<Input v-model="newRepo" class="max-w-72 font-mono" placeholder="owner/repository" aria-label="New repository" :disabled="unsaved" @keydown.enter="addRepo" />
|
||||
|
||||
Reference in new issue
Block a user