components/ui and the pages now use only the style.css scale: text-[0.8rem]→text-label, text-[0.625rem]→text-micro, text-base/text-sm→ text-label (rows and controls), text-xs→text-caption (captions and secondary text), text-lg/text-xl/text-2xl→text-title (panel and page titles). Rendered markdown (ChatMarkdown/ChatInline/markdown.ts) keeps Tailwind steps as the issue allows. 196 files, class-token swaps only.
150 lines
6.0 KiB
Vue
150 lines
6.0 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { computed, onUnmounted, ref } from "vue";
|
|
import { storeToRefs } from "pinia";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Sheet,
|
|
SheetContent,
|
|
SheetDescription,
|
|
SheetFooter,
|
|
SheetHeader,
|
|
SheetTitle,
|
|
} from "@/components/ui/sheet";
|
|
import { Section } from "@/components/ui/section";
|
|
import { StatusDot } from "@/components/ui/status-dot";
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
import ChangeList from "@/components/ChangeList.vue";
|
|
import { diffValues } from "@/lib/changes";
|
|
import type { SettingsSchema } from "@/workflows/workflow-yaml";
|
|
|
|
const store = useSettingsStore();
|
|
const { reviewing } = storeToRefs(store);
|
|
onUnmounted(() => { reviewing.value = false; });
|
|
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}`;
|
|
}
|
|
const named = schema.properties?.[part];
|
|
schema = named ?? schema.additionalProperties ?? {};
|
|
// A map entry is named by its key; its schema title names every entry alike.
|
|
return named ? schema.title || part.replaceAll("_", " ") : part;
|
|
}).join(" · ");
|
|
}
|
|
const sections = computed(() =>
|
|
store.dirtyKinds.map((kind) => ({
|
|
kind,
|
|
title: titleOf(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:
|
|
store.catalog.find((item) => item.kind === kind)?.apply_mode ===
|
|
"restart-required",
|
|
})),
|
|
);
|
|
const count = computed(() =>
|
|
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.
|
|
const invalid = computed(() => store.invalidFields);
|
|
|
|
function discardAll() {
|
|
for (const kind of store.dirtyKinds) store.resetDraft(kind);
|
|
reviewing.value = false;
|
|
}
|
|
|
|
async function save() {
|
|
if (invalid.value.length) return;
|
|
saving.value = true;
|
|
try {
|
|
const outcome = await store.saveDrafts();
|
|
if (!outcome.failed) reviewing.value = false;
|
|
} finally {
|
|
saving.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
v-if="count > 0"
|
|
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 flex-wrap items-center gap-3 px-4 py-3">
|
|
<StatusDot :tone="invalid.length ? 'danger' : 'warn'" />
|
|
<p class="min-w-40 flex-1 text-label">
|
|
<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>
|
|
<Button size="sm" @click="reviewing = true">Review and save</Button>
|
|
</div>
|
|
<ul
|
|
v-if="invalid.length"
|
|
class="space-y-0.5 border-t border-danger/30 px-4 py-2 text-caption text-danger"
|
|
role="alert"
|
|
>
|
|
<li v-for="issue in invalid" :key="`${issue.kind}.${issue.path}`">
|
|
<span class="font-medium">{{ titleOf(issue.kind) }} · {{ issue.label }}</span>:
|
|
{{ issue.message }}
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<Sheet :open="reviewing && count > 0" @update:open="(open) => (reviewing = open)">
|
|
<SheetContent class="flex w-full flex-col gap-0 sm:max-w-[480px]">
|
|
<SheetHeader>
|
|
<SheetTitle>Review {{ count }} {{ count === 1 ? "change" : "changes" }}</SheetTitle>
|
|
<SheetDescription>
|
|
{{ sections.length }} {{ sections.length === 1 ? "section" : "sections" }}
|
|
</SheetDescription>
|
|
</SheetHeader>
|
|
<div class="flex-1 space-y-3 overflow-y-auto px-4 pb-4">
|
|
<Alert variant="destructive" class="rounded-md border border-danger/40 bg-danger-soft px-3 py-2"
|
|
v-if="invalid.length"><AlertDescription>
|
|
{{ invalid.length }} invalid {{ invalid.length === 1 ? "field" : "fields" }} must be fixed before saving.</AlertDescription></Alert>
|
|
<Section v-for="section in sections" :key="section.kind" :title="section.title" class="mb-0">
|
|
<template #action>
|
|
<div class="flex items-center gap-2">
|
|
<Badge v-if="section.restart" variant="warn">After restart</Badge>
|
|
<Button variant="ghost" size="sm" @click="store.resetDraft(section.kind)">Revert</Button>
|
|
</div>
|
|
</template>
|
|
<ChangeList
|
|
:changes="section.changes"
|
|
:label="(path) => fieldLabel(section.kind, path)"
|
|
@revert="(change) => store.revertDraftChange(section.kind, change)"
|
|
/>
|
|
<ul v-if="section.issues.length" class="mt-2 space-y-0.5 text-caption text-danger" role="alert">
|
|
<li v-for="issue in section.issues" :key="issue.path">
|
|
<span class="font-medium">{{ issue.label }}</span>: {{ issue.message }}
|
|
</li>
|
|
</ul>
|
|
<Alert v-if="section.error" variant="destructive" class="mt-2"><AlertDescription>{{ section.error }}</AlertDescription></Alert>
|
|
</Section>
|
|
</div>
|
|
<SheetFooter class="flex-row justify-end gap-2 border-t border-border">
|
|
<Button variant="ghost" @click="discardAll">Discard all</Button>
|
|
<Button :disabled="saving || invalid.length > 0" @click="save">
|
|
<Spinner v-if="saving" data-icon="inline-start" />Save</Button>
|
|
</SheetFooter>
|
|
</SheetContent>
|
|
</Sheet>
|
|
</template>
|