feat(webui): port the dashboard (Phases 3-5)
Every page from the deleted Preact dashboard, rebuilt in Vue 3 + shadcn-vue.
The navigation restructure landed earlier on this branch; this is the surfaces
behind it, and the two are now one app.
Dashboard, Tasks (list and detail), Configuration split six ways, Logs,
Inspector, Mappings, Bindings, Workflows, Skills, Curators, Channels, chat.
Components, not files: docs/prds/dashboard-port-brief.md requires one
component, one job, one file, with shared state in a module beside it. So a
page file composes and holds nothing, and a shape repeated across panes becomes
its own component (LogRow, PageHeader, PanelLoading, WorkflowBar).
Behaviour that had to survive, because each was a fix:
- Live activity's detail is clamped to one line with the payload on the title.
Unclamped, one row made the dashboard 7,481px tall.
- Each health card takes its own height. Equalising left a mostly-empty box
taking a quarter of the first screen once setup was done.
- Tasks: `tab`/`attempt` live in the query string and are written with
router.replace, so a tab click adds no history entry and does not remount.
The list's deep-link reveal honours prefers-reduced-motion.
- LOG_LEVELS is a wire contract (the server matches that CSV server-side), used
unchanged by both log panes.
- The chat panel's Phase 5 list: a FAB that is the only toggle, a morph whose
scale, radius and position interpolate together, no scrim, no close button,
Escape returning focus to the launcher, Stop only while streaming.
- Unconfigured is not broken. A 501 on /api/version or the log stream renders
what is true ("Not configured on this deployment") rather than blank, and a
read-only Configuration says so instead of offering controls that cannot work.
Three things the port decided rather than carried:
- Button gains an `attention` variant and Badge the five status tones, in the
project's own cva. The pill's dot did not come across: the Badge's shape is
the affordance, and the same tone now covers a trend indicator.
- The icon module is not ported. Its name-to-glyph lookup is the pattern
shadcn-vue's rules call out as wrong, so icons come from @lucide/vue at the
call site. The five bespoke glyphs have no consumer yet and become components
if a page draws them.
- The theme control left the topbar for /system/appearance, per the approved
navigation design. ThemeToggle.vue and Placeholder.vue are deleted rather
than orphaned: every route now resolves to a real page.
Also fixes the bundle freshness check failing on the first build after every
change. ui/dist is committed, so nothing ignores it and Tailwind's content
detection scanned it, making each build an input to the next.
This commit is contained in:
1 parent
5fe25045d1
commit
b9daa01b4b
276 files changed
+12888
-563
No files matched your search
@@ -0,0 +1,152 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import {
|
||||
draftFromBinding,
|
||||
emptyDraft,
|
||||
type Binding,
|
||||
type BindingDraft,
|
||||
type MappingOption,
|
||||
type WorkflowOption,
|
||||
} from "./binding-draft";
|
||||
|
||||
/**
|
||||
* The binding editor: name, the matcher source senders POST to, the field
|
||||
* mapping, the workflow, an optional repo pin, and the shared secret their
|
||||
* signature is checked against.
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
/** null is a new binding; a binding is an edit. */
|
||||
binding: Binding | null;
|
||||
mappings: MappingOption[];
|
||||
workflows: WorkflowOption[];
|
||||
saving: boolean;
|
||||
error: string | null;
|
||||
}>();
|
||||
|
||||
const open = defineModel<boolean>("open", { required: true });
|
||||
const emit = defineEmits<{ save: [draft: BindingDraft] }>();
|
||||
|
||||
// The draft is re-seeded on every open, so an edit that was cancelled -- or a
|
||||
// save that failed -- never leaks into the next binding's form.
|
||||
const draft = ref<BindingDraft>(emptyDraft());
|
||||
watch(
|
||||
open,
|
||||
(isOpen) => {
|
||||
if (isOpen) draft.value = props.binding ? draftFromBinding(props.binding) : emptyDraft();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
|
||||
const secretHint = computed(() =>
|
||||
props.binding
|
||||
? "Leave blank to keep the current secret."
|
||||
: "Senders sign with this via HMAC-SHA256.",
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<!-- Seven fields make this taller than a short window; the dialog itself
|
||||
scrolls rather than clipping its own Save button. -->
|
||||
<DialogContent class="max-h-[85vh] overflow-y-auto sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ title }}</DialogTitle>
|
||||
<DialogDescription>
|
||||
A binding is not armed until it is approved, and editing one drops it back to pending approval.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<Alert v-if="props.error" variant="destructive">
|
||||
<AlertTitle>Could not save</AlertTitle>
|
||||
<AlertDescription>{{ props.error }}</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<form @submit.prevent="emit('save', draft)">
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel for="binding-name">Name</FieldLabel>
|
||||
<Input id="binding-name" v-model="draft.name" />
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="binding-source">Source</FieldLabel>
|
||||
<Input id="binding-source" v-model="draft.source" />
|
||||
<FieldDescription>The path segment senders POST to, for example "sentry".</FieldDescription>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="binding-mapping">Field mapping</FieldLabel>
|
||||
<Select v-model="draft.mappingId">
|
||||
<SelectTrigger id="binding-mapping" class="w-full">
|
||||
<SelectValue placeholder="Pick a saved mapping" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem v-for="mapping in props.mappings" :key="mapping.id" :value="String(mapping.id)">
|
||||
{{ mapping.name }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="binding-workflow">Workflow</FieldLabel>
|
||||
<Select v-model="draft.workflow">
|
||||
<SelectTrigger id="binding-workflow" class="w-full">
|
||||
<SelectValue placeholder="Pick a workflow" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem v-for="workflow in props.workflows" :key="workflow.id" :value="workflow.id">
|
||||
{{ workflow.name }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<div class="grid grid-cols-2 items-start gap-3">
|
||||
<Field>
|
||||
<FieldLabel for="binding-owner">Pinned owner</FieldLabel>
|
||||
<Input id="binding-owner" v-model="draft.owner" />
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel for="binding-repo">Pinned repo</FieldLabel>
|
||||
<Input id="binding-repo" v-model="draft.repo" />
|
||||
</Field>
|
||||
</div>
|
||||
<FieldDescription>
|
||||
Optional. A pin is both halves or neither, so leave both blank to use the single configured repo.
|
||||
</FieldDescription>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="binding-secret">Shared secret</FieldLabel>
|
||||
<Input id="binding-secret" v-model="draft.secret" type="password" autocomplete="off" />
|
||||
<FieldDescription>{{ secretHint }}</FieldDescription>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
|
||||
<DialogFooter class="mt-4">
|
||||
<Button type="button" variant="outline" @click="open = false">Cancel</Button>
|
||||
<Button type="submit" :disabled="props.saving">
|
||||
<Spinner v-if="props.saving" data-icon="inline-start" />
|
||||
{{ props.saving ? "Saving" : "Save" }}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import { Check, Pencil, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { TableCell, TableRow } from "@/components/ui/table";
|
||||
import BindingStatusBadge from "./BindingStatusBadge.vue";
|
||||
import { matcherSource, repoPin, type Binding } from "./binding-draft";
|
||||
|
||||
/** One saved binding's summary row. */
|
||||
const props = defineProps<{ binding: Binding }>();
|
||||
const emit = defineEmits<{
|
||||
edit: [binding: Binding];
|
||||
approve: [binding: Binding];
|
||||
delete: [binding: Binding];
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TableRow>
|
||||
<TableCell class="font-medium">{{ props.binding.name }}</TableCell>
|
||||
<TableCell class="font-mono text-fg-muted">{{ matcherSource(props.binding) }}</TableCell>
|
||||
<TableCell>{{ props.binding.workflow || "—" }}</TableCell>
|
||||
<TableCell class="font-mono text-fg-muted">{{ repoPin(props.binding) }}</TableCell>
|
||||
<TableCell><BindingStatusBadge :status="props.binding.status" /></TableCell>
|
||||
<TableCell>
|
||||
<div class="flex items-center justify-end gap-1">
|
||||
<Button variant="outline" size="sm" @click="emit('edit', props.binding)">
|
||||
<Pencil data-icon="inline-start" />
|
||||
Edit
|
||||
</Button>
|
||||
<!-- Only a pending binding can be approved. A draft is not a state you
|
||||
approve from and an armed binding is already firing, so the button
|
||||
would be a no-op -- or worse, a misleading one. -->
|
||||
<Button v-if="props.binding.status === 'pending_approval'" size="sm" @click="emit('approve', props.binding)">
|
||||
<Check data-icon="inline-start" />
|
||||
Approve
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" @click="emit('delete', props.binding)">
|
||||
<Trash2 data-icon="inline-start" />
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { statusKind, statusLabel } from "./binding-draft";
|
||||
|
||||
/** A binding's lifecycle state: draft, pending approval, or armed. The
|
||||
* colour ramp is shared with every other status in the dashboard, so the
|
||||
* same colour means the same thing here as it does on a task. */
|
||||
const props = defineProps<{ status?: string }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Badge :variant="statusKind(props.status)">{{ statusLabel(props.status) }}</Badge>
|
||||
</template>
|
||||
@@ -0,0 +1,112 @@
|
||||
<script setup lang="ts">
|
||||
import { Plus, RefreshCw } from "@lucide/vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import BindingEditor from "./BindingEditor.vue";
|
||||
import BindingsTable from "./BindingsTable.vue";
|
||||
import DeleteBindingDialog from "./DeleteBindingDialog.vue";
|
||||
import type { Binding, BindingDraft } from "./binding-draft";
|
||||
import { useBindings } from "./use-bindings";
|
||||
|
||||
/**
|
||||
* Playbook bindings (t2db.8): tie a matcher + payload mapping + workflow
|
||||
* together, with a draft -> pending_approval -> armed state machine so nothing
|
||||
* self-arms. See docs/architecture/bindings.md and
|
||||
* docs/prds/payload-field-mapping.md. Owner/Repo optionally pin a multi-repo
|
||||
* deployment's dispatch target (archie-core-t2db.8's backend fix, commit
|
||||
* ac42f64).
|
||||
*/
|
||||
|
||||
const {
|
||||
bindings,
|
||||
mappings,
|
||||
workflows,
|
||||
failure,
|
||||
actionFailure,
|
||||
saving,
|
||||
saveFailure,
|
||||
load,
|
||||
resetSaveFailure,
|
||||
save,
|
||||
approve,
|
||||
remove,
|
||||
} = useBindings();
|
||||
|
||||
const editorOpen = ref(false);
|
||||
// null is a new binding; a binding is an edit.
|
||||
const editing = ref<Binding | null>(null);
|
||||
const deleting = ref<Binding | null>(null);
|
||||
|
||||
onMounted(load);
|
||||
|
||||
function startCreate(): void {
|
||||
editing.value = null;
|
||||
resetSaveFailure();
|
||||
editorOpen.value = true;
|
||||
}
|
||||
|
||||
function startEdit(binding: Binding): void {
|
||||
editing.value = binding;
|
||||
resetSaveFailure();
|
||||
editorOpen.value = true;
|
||||
}
|
||||
|
||||
async function handleSave(draft: BindingDraft): Promise<void> {
|
||||
// The editor stays open on failure so the server's reason and the fields it
|
||||
// is about are still on screen together.
|
||||
if (await save(draft)) editorOpen.value = false;
|
||||
}
|
||||
|
||||
async function handleDelete(binding: Binding): Promise<void> {
|
||||
deleting.value = null;
|
||||
await remove(binding);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader
|
||||
title="Playbook bindings"
|
||||
subtitle="Tie a matcher, a field mapping, and a workflow together. New and edited bindings need explicit approval before they can fire."
|
||||
>
|
||||
<Button v-if="failure" @click="load">
|
||||
<RefreshCw data-icon="inline-start" />
|
||||
Retry
|
||||
</Button>
|
||||
<Button v-else @click="startCreate">
|
||||
<Plus data-icon="inline-start" />
|
||||
New binding
|
||||
</Button>
|
||||
</PageHeader>
|
||||
|
||||
<!-- A mutation that failed leaves the list on screen accurate, so its
|
||||
failure sits beside the list rather than replacing it. -->
|
||||
<Alert v-if="actionFailure" variant="destructive" class="mb-4">
|
||||
<AlertTitle>That did not take effect</AlertTitle>
|
||||
<AlertDescription>{{ actionFailure.message }}</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<BindingsTable
|
||||
:bindings="bindings"
|
||||
:failure="failure"
|
||||
@edit="startEdit"
|
||||
@approve="approve"
|
||||
@delete="deleting = $event"
|
||||
/>
|
||||
|
||||
<BindingEditor
|
||||
v-model:open="editorOpen"
|
||||
:binding="editing"
|
||||
:mappings="mappings"
|
||||
:workflows="workflows"
|
||||
:saving="saving"
|
||||
:error="saveFailure"
|
||||
@save="handleSave"
|
||||
/>
|
||||
|
||||
<DeleteBindingDialog :binding="deleting" @confirm="handleDelete" @cancel="deleting = null" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import BindingRow from "./BindingRow.vue";
|
||||
import type { Binding } from "./binding-draft";
|
||||
import type { LoadFailure } from "./use-bindings";
|
||||
|
||||
const props = defineProps<{
|
||||
/** null means loading, [] means loaded and empty. */
|
||||
bindings: Binding[] | null;
|
||||
failure: LoadFailure | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
edit: [binding: Binding];
|
||||
approve: [binding: Binding];
|
||||
delete: [binding: Binding];
|
||||
}>();
|
||||
|
||||
const loading = computed(() => props.bindings === null);
|
||||
const rows = computed(() => props.bindings ?? []);
|
||||
|
||||
// The failure description is the daemon's own words. "bindings not configured"
|
||||
// answers a deployment with no binding store wired, and the operator can act on
|
||||
// that, where a blanket "cannot reach archied" would be false about a daemon
|
||||
// that answered.
|
||||
const failureTitle = computed(() =>
|
||||
props.failure?.kind === "unconfigured" ? "Bindings are not configured" : "Cannot reach archied",
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Empty v-if="props.failure">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>{{ failureTitle }}</EmptyTitle>
|
||||
<EmptyDescription>{{ props.failure.message }}</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
|
||||
<Empty v-else-if="!loading && !rows.length">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>No bindings yet</EmptyTitle>
|
||||
<EmptyDescription>
|
||||
Create one from a saved field mapping to turn a captured webhook into a workflow.
|
||||
</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
|
||||
<Card v-else>
|
||||
<CardContent>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Name</TableHead>
|
||||
<TableHead>Source</TableHead>
|
||||
<TableHead>Workflow</TableHead>
|
||||
<TableHead>Repo pin</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<template v-if="loading">
|
||||
<TableRow v-for="row in 3" :key="row">
|
||||
<TableCell v-for="col in 6" :key="col"><Skeleton class="h-4 w-full" /></TableCell>
|
||||
</TableRow>
|
||||
</template>
|
||||
<template v-else>
|
||||
<BindingRow
|
||||
v-for="binding in rows"
|
||||
:key="binding.id"
|
||||
:binding="binding"
|
||||
@edit="emit('edit', $event)"
|
||||
@approve="emit('approve', $event)"
|
||||
@delete="emit('delete', $event)"
|
||||
/>
|
||||
</template>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import type { Binding } from "./binding-draft";
|
||||
|
||||
/** Confirming a delete, and nothing else. A binding cannot be recovered, so
|
||||
* the action is behind a dialog rather than a click. */
|
||||
const props = defineProps<{ binding: Binding | null }>();
|
||||
const emit = defineEmits<{ confirm: [binding: Binding]; cancel: [] }>();
|
||||
|
||||
// The binding is handed back by value so the confirmation stands on its own:
|
||||
// the dialog closes on the click, and the caller must not have to re-read
|
||||
// state that the close has already cleared.
|
||||
function confirm(): void {
|
||||
if (props.binding) emit("confirm", props.binding);
|
||||
}
|
||||
|
||||
// Reka closes the dialog on the action click, so this is what tells the caller
|
||||
// to forget the pending binding -- whether the delete happened or not.
|
||||
function onOpenChange(open: boolean): void {
|
||||
if (!open) emit("cancel");
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog :open="props.binding !== null" @update:open="onOpenChange">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete "{{ props.binding?.name }}"?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
It stops dispatching immediately and cannot be recovered. Captured events for its source keep
|
||||
arriving; they just stop starting tasks.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" @click="confirm">Delete</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* The bindings vocabulary: the wire shapes the daemon returns, the draft the
|
||||
* editor form edits, and the status ramp the list renders. Pure, so it reads
|
||||
* (and would test) without the page's fetch wiring -- the same split
|
||||
* binding-editor.jsx had from bindings.jsx in the Preact build.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A binding as GET /api/bindings returns it. Secret is never returned: the
|
||||
* daemon strips it from every read, and a blank secret on update is its
|
||||
* server-side "keep the current one".
|
||||
*/
|
||||
export interface Binding {
|
||||
id: number;
|
||||
name: string;
|
||||
matcher?: { source?: string };
|
||||
mapping_id?: number;
|
||||
workflow?: string;
|
||||
/** A pin is a complete owner/repo pair or not a pin at all. */
|
||||
owner?: string;
|
||||
repo?: string;
|
||||
status?: string;
|
||||
version?: number;
|
||||
}
|
||||
|
||||
/** The fields of GET /api/mappings this page needs. */
|
||||
export interface MappingOption {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/** One entry of GET /api/workflows' `definitions`. */
|
||||
export interface WorkflowOption {
|
||||
id: string;
|
||||
name: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
/** The Badge variants a binding status maps onto. */
|
||||
export type StatusKind = "ok" | "warn" | "idle";
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
draft: "draft",
|
||||
pending_approval: "pending approval",
|
||||
armed: "armed",
|
||||
};
|
||||
|
||||
const STATUS_KINDS: Record<string, StatusKind> = {
|
||||
draft: "idle",
|
||||
pending_approval: "warn",
|
||||
armed: "ok",
|
||||
};
|
||||
|
||||
/** A status the daemon grows later renders as itself in the neutral kind,
|
||||
* rather than as an unlabelled pill. */
|
||||
export function statusLabel(status?: string): string {
|
||||
if (!status) return "unknown";
|
||||
return STATUS_LABELS[status] ?? status;
|
||||
}
|
||||
|
||||
export function statusKind(status?: string): StatusKind {
|
||||
return STATUS_KINDS[status ?? ""] ?? "idle";
|
||||
}
|
||||
|
||||
/**
|
||||
* The editor's field state. mappingId is the select's string value because a
|
||||
* select's model is its option values; the store's mapping_id is a number.
|
||||
*/
|
||||
export interface BindingDraft {
|
||||
id: number | null;
|
||||
name: string;
|
||||
source: string;
|
||||
mappingId: string;
|
||||
workflow: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
secret: string;
|
||||
}
|
||||
|
||||
export function emptyDraft(): BindingDraft {
|
||||
return {
|
||||
id: null,
|
||||
name: "",
|
||||
source: "",
|
||||
mappingId: "",
|
||||
workflow: "",
|
||||
owner: "",
|
||||
repo: "",
|
||||
secret: "",
|
||||
};
|
||||
}
|
||||
|
||||
export function draftFromBinding(binding: Binding): BindingDraft {
|
||||
return {
|
||||
id: binding.id,
|
||||
name: binding.name,
|
||||
source: binding.matcher?.source || "",
|
||||
mappingId: binding.mapping_id ? String(binding.mapping_id) : "",
|
||||
workflow: binding.workflow || "",
|
||||
owner: binding.owner || "",
|
||||
repo: binding.repo || "",
|
||||
// Deliberately blank: the secret is never sent to the browser, and an
|
||||
// empty one on update keeps whatever the sender already signs with.
|
||||
secret: "",
|
||||
};
|
||||
}
|
||||
|
||||
/** The body POST /api/bindings and PATCH /api/bindings/{id} both accept. A
|
||||
* blank mapping is 0, which the store rejects -- a binding with no mapping
|
||||
* could never be dispatched. */
|
||||
export function bindingPayload(draft: BindingDraft): Record<string, unknown> {
|
||||
return {
|
||||
name: draft.name,
|
||||
matcher: { source: draft.source },
|
||||
mapping_id: Number(draft.mappingId) || 0,
|
||||
workflow: draft.workflow,
|
||||
owner: draft.owner,
|
||||
repo: draft.repo,
|
||||
secret: draft.secret,
|
||||
};
|
||||
}
|
||||
|
||||
/** The repo pin a row shows, or an em dash when the binding takes the
|
||||
* single-configured-repo default. */
|
||||
export function repoPin(binding: Binding): string {
|
||||
return binding.owner && binding.repo ? `${binding.owner}/${binding.repo}` : "—";
|
||||
}
|
||||
|
||||
/** The matcher source a row shows: the path segment senders POST to. */
|
||||
export function matcherSource(binding: Binding): string {
|
||||
return binding.matcher?.source || "—";
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
import { api, ApiError } from "@/lib/api";
|
||||
import {
|
||||
bindingPayload,
|
||||
type Binding,
|
||||
type BindingDraft,
|
||||
type MappingOption,
|
||||
type WorkflowOption,
|
||||
} from "./binding-draft";
|
||||
|
||||
/**
|
||||
* Why the page has nothing to show. "unconfigured" is a daemon with no
|
||||
* bindings store wired (501/503) -- the feature is off, which reads very
|
||||
* differently from a daemon that answered badly.
|
||||
*/
|
||||
export type LoadFailureKind = "unconfigured" | "failed";
|
||||
|
||||
export interface LoadFailure {
|
||||
kind: LoadFailureKind;
|
||||
message: string;
|
||||
}
|
||||
|
||||
function failureFor(err: unknown): LoadFailure {
|
||||
const message = err instanceof Error && err.message ? err.message : String(err);
|
||||
const status = err instanceof ApiError ? err.status : undefined;
|
||||
return { kind: status === 501 || status === 503 ? "unconfigured" : "failed", message };
|
||||
}
|
||||
|
||||
/**
|
||||
* The bindings page's data: the three lists the list and the editor read, the
|
||||
* load that fills them, and the three mutations. Every mutation goes through
|
||||
* api.* so the CSRF and Content-Type headers are sent -- a bare fetch is
|
||||
* refused 403/415 by archied's mutation guard.
|
||||
*/
|
||||
export function useBindings() {
|
||||
// null means loading, [] means loaded and empty.
|
||||
const bindings = ref<Binding[] | null>(null);
|
||||
const mappings = ref<MappingOption[]>([]);
|
||||
const workflows = ref<WorkflowOption[]>([]);
|
||||
const failure = ref<LoadFailure | null>(null);
|
||||
// A failed mutation is not a failed load: the list on screen is still
|
||||
// accurate, so it keeps rendering and the failure lands beside it.
|
||||
const actionFailure = ref<LoadFailure | null>(null);
|
||||
const saving = ref(false);
|
||||
const saveFailure = ref<string | null>(null);
|
||||
|
||||
async function load(): Promise<void> {
|
||||
failure.value = null;
|
||||
try {
|
||||
const [b, m, w] = await Promise.all([
|
||||
api.bindings<{ bindings?: Binding[] }>(),
|
||||
api.mappings<{ mappings?: MappingOption[] }>(),
|
||||
api.workflows<{ definitions?: WorkflowOption[] }>(),
|
||||
]);
|
||||
bindings.value = b.bindings || [];
|
||||
mappings.value = m.mappings || [];
|
||||
// Only enabled definitions are offerable: binding to a disabled one
|
||||
// would persist a binding that can never dispatch.
|
||||
workflows.value = (w.definitions || []).filter((d) => d.enabled);
|
||||
} catch (err) {
|
||||
failure.value = failureFor(err);
|
||||
bindings.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
function resetSaveFailure(): void {
|
||||
saveFailure.value = null;
|
||||
}
|
||||
|
||||
/** True when the binding was written, so the caller knows to close. */
|
||||
async function save(draft: BindingDraft): Promise<boolean> {
|
||||
saving.value = true;
|
||||
saveFailure.value = null;
|
||||
try {
|
||||
const body = bindingPayload(draft);
|
||||
if (draft.id) {
|
||||
await api.bindingUpdate(String(draft.id), body);
|
||||
} else {
|
||||
await api.bindingCreate(body);
|
||||
}
|
||||
await load();
|
||||
return true;
|
||||
} catch (err) {
|
||||
saveFailure.value = err instanceof Error && err.message ? err.message : String(err);
|
||||
return false;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function approve(binding: Binding): Promise<void> {
|
||||
actionFailure.value = null;
|
||||
try {
|
||||
await api.bindingApprove(String(binding.id));
|
||||
await load();
|
||||
} catch (err) {
|
||||
actionFailure.value = failureFor(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(binding: Binding): Promise<void> {
|
||||
actionFailure.value = null;
|
||||
try {
|
||||
await api.bindingDelete(String(binding.id));
|
||||
await load();
|
||||
} catch (err) {
|
||||
actionFailure.value = failureFor(err);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
bindings,
|
||||
mappings,
|
||||
workflows,
|
||||
failure,
|
||||
actionFailure,
|
||||
saving,
|
||||
saveFailure,
|
||||
load,
|
||||
resetSaveFailure,
|
||||
save,
|
||||
approve,
|
||||
remove,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user