fix(ui): repair settings editing and workflow diagnostics

This commit is contained in:
sam committed 2026-10-16 23:55:58 +11:00
1 parent 3229de9b3b
commit 41cd938748
46 files changed
+708 -240

No files matched your search

+3 -2
View File
@@ -73,6 +73,7 @@ function setQuery(patch: Record<string, string | undefined>) {
}
const windows: Record<string, number> = { "24h": 86_400_000, "7d": 604_800_000, "30d": 2_592_000_000 };
const actorName = (id: string) => entries.value.find((entry) => entry.actor === id)?.actor_name || id;
const actors = computed(() => [...new Set(entries.value.map((e) => e.actor))].sort());
const sectionOptions = computed(() => {
const options = catalog.value.map((r) => ({ value: r.kind, label: r.title }));
@@ -130,7 +131,7 @@ const restorable = (entry: AuditEntry) =>
<SelectTrigger class="w-48" aria-label="Changed by"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem :value="ALL">Anyone</SelectItem>
<SelectItem v-for="a in actors" :key="a" :value="a">{{ a }}</SelectItem>
<SelectItem v-for="a in actors" :key="a" :value="a">{{ actorName(a) }}</SelectItem>
</SelectContent>
</Select>
<Select v-model="since">
@@ -178,7 +179,7 @@ const restorable = (entry: AuditEntry) =>
</TableCell>
<TableCell class="font-mono text-xs">{{ entry.version }}</TableCell>
<TableCell class="truncate" :title="`${entry.actor} · ${entry.source}`">
{{ entry.actor }}<span class="text-fg-subtle"> · {{ entry.source }}</span>
{{ entry.actor_name || entry.actor }}<span class="text-fg-subtle"> · {{ entry.source }}</span>
</TableCell>
<TableCell class="py-1 text-right">
<Button
+7 -15
View File
@@ -45,7 +45,7 @@ const resources = computed(() => resourcesForPage(catalog.value, "schedules"));
const jobs = computed(() => store.drafts[KIND]?.value as Job[] | undefined);
const error = computed(() => store.pageErrorFor(KIND));
const issues = computed(() => store.issuesFor(KIND));
const jobIssue = (i: number) => issues.value.find((entry) => entry.path === `${i}.id`);
const jobIssue = (i: number) => issues.value.find((entry) => entry.path.startsWith(`${i}.`));
const whenKinds = [
{ value: "interval", label: "Every" },
@@ -67,9 +67,9 @@ const unsaved = computed(() => store.changesFor(KIND).length > 0);
function add() {
if (unsaved.value || !jobs.value) return;
jobs.value.push({
id: "",
id: crypto.randomUUID(),
kind: "workflow",
detail: "",
detail: "Scheduled task",
pool: "",
schedule: { kind: "interval", interval: "24h0m0s" },
target: {},
@@ -122,12 +122,10 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
<span v-if="job.next_run" class="text-xs text-fg-subtle">Next run {{ new Date(job.next_run).toLocaleString() }}</span>
</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" />
<DraftHint :kind="KIND" :path="`${i}.id`" />
</div>
<p v-if="jobIssue(i)" class="mt-1.5 text-xs text-danger">{{ jobIssue(i)?.message }}</p>
<SettingRow label="Schedule name" :for="`job-${i}-name`" hint="Used as the task title for scheduled workflows.">
<Input :id="`job-${i}-name`" v-model="job.detail" class="max-w-md" />
<DraftHint :kind="KIND" :path="`${i}.detail`" />
<p v-if="jobIssue(i)" class="mt-1.5 text-xs text-danger" role="alert">{{ jobIssue(i)?.message }}</p>
</SettingRow>
<SettingRow label="Does">
<div class="flex flex-wrap items-center gap-3">
@@ -144,12 +142,6 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
<DraftHint :kind="KIND" :path="`${i}.target.chat_id`" />
</div>
</SettingRow>
<SettingRow v-else label="Task title" :for="`job-${i}-title`" hint="Empty: the ID.">
<div class="flex flex-wrap items-center gap-3">
<Input :id="`job-${i}-title`" v-model="job.detail" class="max-w-md" />
<DraftHint :kind="KIND" :path="`${i}.detail`" />
</div>
</SettingRow>
<SettingRow :label="job.kind === 'chat' ? 'Message' : 'Instructions'" :for="`job-${i}-text`">
<Textarea :id="`job-${i}-text`" v-model="job.payload.text" :rows="3" />
<DraftHint :kind="KIND" :path="`${i}.payload.text`" />
+24 -10
View File
@@ -14,7 +14,8 @@ import {
import { Spinner } from "@/components/ui/spinner";
import { Badge } from "@/components/ui/badge";
import { useSettingsStore } from "@/stores/settings";
import { formatValue } from "./changes";
import { diffValues, formatValue } from "./changes";
import type { SettingsSchema } from "@/workflows/workflow-yaml";
const store = useSettingsStore();
const { reviewing } = storeToRefs(store);
@@ -23,11 +24,24 @@ const saving = ref(false);
const titleOf = (kind: string) =>
store.catalog.find((item) => item.kind === kind)?.title ?? kind;
function fieldLabel(kind: string, path: string): string {
let schema: SettingsSchema;
try { schema = JSON.parse(store.catalog.find((item) => item.kind === kind)?.schema_json || "{}"); }
catch { schema = {}; }
return path.split(".").map((part) => {
if (/^\d+$/.test(part)) {
schema = schema.items ?? {};
return `Item ${Number(part) + 1}`;
}
schema = schema.properties?.[part] ?? schema.additionalProperties ?? {};
return schema.title || part.replaceAll("_", " ");
}).join(" · ");
}
const sections = computed(() =>
store.dirtyKinds.map((kind) => ({
kind,
title: titleOf(kind),
changes: store.changesFor(kind),
changes: store.changesFor(kind).flatMap((change) => diffValues(change.before, change.after, change.path, true)),
issues: store.issuesFor(kind),
error: store.stateFor(kind).error,
restart:
@@ -36,7 +50,7 @@ const sections = computed(() =>
})),
);
const count = computed(() =>
sections.value.reduce((n, s) => n + s.changes.length, 0),
store.dirtyKinds.reduce((n, kind) => n + store.changesFor(kind).length, 0),
);
// Invalid fields block Save, and are listed in the bar so the operator knows
// before opening the review. Both read the store's one draft diff.
@@ -63,18 +77,18 @@ async function save() {
<template>
<div
v-if="count > 0"
class="sticky bottom-4 z-30 mt-auto rounded-lg border border-border bg-popover shadow-[var(--shadow-md)]"
class="sticky bottom-24 z-30 mt-auto rounded-lg border border-border bg-popover shadow-[var(--shadow-md)]"
role="region"
aria-label="Unsaved changes"
>
<div class="flex items-center gap-3 px-4 py-3">
<div class="flex flex-wrap items-center gap-3 px-4 py-3">
<span
class="size-2 shrink-0 rounded-full"
:class="invalid.length ? 'bg-danger' : 'bg-primary'"
aria-hidden="true"
/>
<p class="min-w-0 flex-1 truncate text-sm">
<span class="font-medium">{{ count }} unsaved {{ count === 1 ? "change" : "changes" }}</span>
<p class="min-w-40 flex-1 text-sm">
<span class="font-medium">{{ count }} unsaved settings {{ count === 1 ? "change" : "changes" }}</span>
<span class="text-fg-subtle"> · {{ sections.map((s) => s.title).join(", ") }}</span>
</p>
<Button variant="ghost" size="sm" @click="discardAll">Discard</Button>
@@ -123,9 +137,9 @@ async function save() {
</header>
<ul class="divide-y divide-border font-mono text-xs">
<li v-for="change in section.changes" :key="change.path" class="px-3 py-2">
<p class="mb-1 text-fg-subtle">{{ change.path }}</p>
<p class="truncate text-danger">− {{ formatValue(change.before) }}</p>
<p class="truncate text-ok">+ {{ formatValue(change.after) }}</p>
<p class="mb-1 font-sans font-medium">{{ fieldLabel(section.kind, change.path) }}</p>
<p class="whitespace-pre-wrap break-words text-danger"><span class="font-sans">Before: </span>{{ formatValue(change.before) }}</p>
<p class="whitespace-pre-wrap break-words text-ok"><span class="font-sans">After: </span>{{ formatValue(change.after) }}</p>
</li>
</ul>
<ul
+3 -20
View File
@@ -1,11 +1,10 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import { computed } from "vue";
import { useRoute } from "vue-router";
import { hiddenPaths, settingsNav } from "@/lib/nav";
import { cn } from "@/lib/utils";
import { useSessionStore } from "@/stores/session";
import { useSettingsStore } from "@/stores/settings";
import RestartPendingBanner from "./RestartPendingBanner.vue";
import SettingsSaveBar from "./SettingsSaveBar.vue";
@@ -13,22 +12,6 @@ const route = useRoute();
const session = useSessionStore();
const items = computed(() => settingsNav(hiddenPaths(session.sections)));
// Drafts live in the store, so moving between Settings pages keeps them;
// leaving Settings, or the page, with edits unsaved asks first.
const store = useSettingsStore();
const dirty = () => store.dirtyKinds.length > 0;
const removeGuard = useRouter().beforeEach((to) => {
if (to.meta.settings || !dirty()) return true;
return window.confirm("Leave Settings with unsaved changes?");
});
const warnUnload = (event: BeforeUnloadEvent) => {
if (dirty()) event.preventDefault();
};
onMounted(() => window.addEventListener("beforeunload", warnUnload));
onBeforeUnmount(() => {
removeGuard();
window.removeEventListener("beforeunload", warnUnload);
});
</script>
<template>
@@ -65,7 +48,7 @@ onBeforeUnmount(() => {
</nav>
<!-- At least a screen tall, so the sticky save bar always rests at the
viewport's bottom edge rather than under the last setting. -->
<div class="flex min-h-screen min-w-0 flex-1 flex-col">
<div class="mx-auto flex min-h-screen w-full min-w-0 max-w-[80ch] flex-1 flex-col">
<RestartPendingBanner />
<!-- Room below the last setting, so it can be scrolled up to eye level. -->
<div class="pb-[40vh]">
+7 -5
View File
@@ -23,18 +23,20 @@ const same = (a: unknown, b: unknown) =>
* array of plain values is one leaf, because its entries have no identity of
* their own. A row added or removed is a single change.
*/
export function diffValues(before: unknown, after: unknown, path = ""): Change[] {
export function diffValues(before: unknown, after: unknown, path = "", expandRows = false): Change[] {
if (same(before, after)) return [];
const at = (key: string | number) => (path ? `${path}.${key}` : String(key));
if (isRecord(before) && isRecord(after)) {
const keys = [...new Set([...Object.keys(before), ...Object.keys(after)])];
return keys.flatMap((key) => diffValues(before[key], after[key], at(key)));
if ((isRecord(before) && isRecord(after)) || (expandRows && (isRecord(before) || isRecord(after)))) {
const left = isRecord(before) ? before : {};
const right = isRecord(after) ? after : {};
const keys = [...new Set([...Object.keys(left), ...Object.keys(right)])];
return keys.flatMap((key) => diffValues(left[key], right[key], at(key), expandRows));
}
const rows = (v: unknown) => Array.isArray(v) && v.some(isRecord);
if (Array.isArray(before) && Array.isArray(after) && (rows(before) || rows(after))) {
const length = Math.max(before.length, after.length);
return Array.from({ length }, (_, i) => diffValues(before[i], after[i], at(i))).flat();
return Array.from({ length }, (_, i) => diffValues(before[i], after[i], at(i), expandRows)).flat();
}
return [{ path, before, after }];
}