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,18 @@
|
||||
<script setup lang="ts">
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { actionErrorTitle, type ActionFailure } from "./state";
|
||||
|
||||
/**
|
||||
* One failed operator action. The title comes from the classified kind, so an
|
||||
* expired session reads differently from a rejected one; the message under it
|
||||
* is archied's own, which is the part an operator can act on.
|
||||
*/
|
||||
defineProps<{ failure: ActionFailure }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Alert variant="destructive">
|
||||
<AlertTitle>{{ actionErrorTitle(failure.kind) }}</AlertTitle>
|
||||
<AlertDescription>{{ failure.message }}</AlertDescription>
|
||||
</Alert>
|
||||
</template>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import { Trash2 } from "@lucide/vue";
|
||||
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogMedia,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { cancelDelete, confirmDelete, pendingDelete } from "./state";
|
||||
|
||||
/**
|
||||
* The destructive confirmation for one mapping. Deleting unprompted is not
|
||||
* offered: a playbook binding (t2db.4) points at a mapping by id, so removing
|
||||
* one without being asked would break a binding the operator still has.
|
||||
*/
|
||||
function onOpenChange(open: boolean) {
|
||||
if (!open) cancelDelete();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog :open="pendingDelete !== null" @update:open="onOpenChange">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogMedia class="bg-danger-soft text-danger">
|
||||
<Trash2 />
|
||||
</AlertDialogMedia>
|
||||
<AlertDialogTitle>Delete this mapping?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
"{{ pendingDelete?.name }}" will be removed. Anything bound to it stops resolving.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel @click="cancelDelete">Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" @click="confirmDelete">Delete</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import MappingActionError from "./MappingActionError.vue";
|
||||
import MappingFieldsTable from "./MappingFieldsTable.vue";
|
||||
import MappingForm from "./MappingForm.vue";
|
||||
import PayloadTree from "./PayloadTree.vue";
|
||||
import { actionError, addField, closeEditor, draft, editorOpen, runPreview, saveMapping, saving } from "./state";
|
||||
|
||||
/**
|
||||
* One editing session, in an overlay: the mapping's own fields, the fields
|
||||
* bound to payload paths, and the example event they were bound from.
|
||||
*
|
||||
* The payload panel is the editor's primary control rather than a preview of
|
||||
* one: a field is bound by clicking a value that really is in a captured event,
|
||||
* so no JSON path is ever typed by hand.
|
||||
*/
|
||||
function onOpenChange(open: boolean) {
|
||||
if (!open) closeEditor();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog :open="editorOpen" @update:open="onOpenChange">
|
||||
<DialogContent class="max-h-[85vh] overflow-y-auto sm:max-w-3xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ draft.id === null ? "New mapping" : "Edit mapping" }}</DialogTitle>
|
||||
<DialogDescription>
|
||||
Bind named fields to JSON paths from a real captured event, ready for a playbook binding.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<MappingActionError v-if="actionError" :failure="actionError" />
|
||||
|
||||
<Card>
|
||||
<CardContent>
|
||||
<MappingForm />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Bound fields</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<MappingFieldsTable />
|
||||
</CardContent>
|
||||
<CardFooter>
|
||||
<Button variant="outline" @click="runPreview">Preview</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Payload — click a value to bind it</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Alert v-if="draft.payloadError" variant="destructive">
|
||||
<AlertDescription>{{ draft.payloadError }}</AlertDescription>
|
||||
</Alert>
|
||||
<PayloadTree v-else-if="draft.payload !== null" :value="draft.payload" @pick="addField" />
|
||||
<p v-else class="text-sm text-fg-muted">Pick a captured event above to see its payload.</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" @click="closeEditor">Cancel</Button>
|
||||
<Button :disabled="saving" @click="saveMapping">
|
||||
<Spinner v-if="saving" data-icon="inline-start" />
|
||||
{{ saving ? "Saving..." : "Save" }}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import { Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { TableCell, TableRow } from "@/components/ui/table";
|
||||
import { FIELD_TYPES, asFieldType } from "./mapping-fields";
|
||||
import MappingPreviewStatus from "./MappingPreviewStatus.vue";
|
||||
import type { MappingField, Preview, PreviewFailure } from "./state";
|
||||
|
||||
/**
|
||||
* One bound field: the name the workflow receives, the path it resolves from,
|
||||
* the shape it claims, and whether it must resolve at all.
|
||||
*
|
||||
* The path is shown but not editable. It is set by clicking a value in the
|
||||
* payload, so a path that does not exist in the captured event cannot be typed
|
||||
* in by hand -- which is the whole point of authoring against a real one.
|
||||
*
|
||||
* The type is a Select rather than a ToggleGroup: six options do not fit a
|
||||
* table cell at 720px, and a segmented control there would push the row wider
|
||||
* than the dialog it sits in.
|
||||
*/
|
||||
defineProps<{ field: MappingField; preview: Preview | null; failure?: PreviewFailure }>();
|
||||
const emit = defineEmits<{ update: [patch: Partial<MappingField>]; remove: [] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<Input
|
||||
:model-value="field.name"
|
||||
aria-label="Field name"
|
||||
@update:model-value="(value) => emit('update', { name: String(value) })"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell class="font-mono text-xs">
|
||||
<span class="block max-w-56 truncate" :title="field.path">{{ field.path }}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Select :model-value="field.type" @update:model-value="(value) => emit('update', { type: asFieldType(value) })">
|
||||
<SelectTrigger size="sm" :aria-label="`Type for ${field.name}`">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem v-for="type in FIELD_TYPES" :key="type" :value="type">{{ type }}</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Checkbox
|
||||
:model-value="field.required"
|
||||
:aria-label="`Required: ${field.name}`"
|
||||
@update:model-value="(value) => emit('update', { required: value === true })"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<MappingPreviewStatus :field="field" :preview="preview" :failure="failure" />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Button variant="ghost" size="icon-xs" :aria-label="`Remove ${field.name}`" @click="emit('remove')">
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import MappingFieldRow from "./MappingFieldRow.vue";
|
||||
import { draft, removeField, updateField, type PreviewFailure } from "./state";
|
||||
|
||||
/**
|
||||
* The fields bound so far, each with what the last preview said about it.
|
||||
*
|
||||
* With nothing bound there is no table to show, and the next move is in the
|
||||
* payload panel, so the empty state points there rather than presenting an
|
||||
* empty grid.
|
||||
*/
|
||||
const fields = computed(() => draft.value.fields);
|
||||
const preview = computed(() => draft.value.preview);
|
||||
|
||||
/** Preview failures are keyed by field name: the daemon reports a failure by
|
||||
* name, and a field is what the operator renamed. */
|
||||
const failureByField = computed(
|
||||
() => new Map<string, PreviewFailure>((preview.value?.failures || []).map((failure) => [failure.field_name, failure])),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<p v-if="!fields.length" class="py-3 text-sm text-fg-muted">Click a value in the payload to bind a field.</p>
|
||||
|
||||
<Table v-else>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Field name</TableHead>
|
||||
<TableHead>Path</TableHead>
|
||||
<TableHead>Type</TableHead>
|
||||
<TableHead>Required</TableHead>
|
||||
<TableHead>Preview</TableHead>
|
||||
<TableHead><span class="sr-only">Actions</span></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<MappingFieldRow
|
||||
v-for="(field, index) in fields"
|
||||
:key="index"
|
||||
:field="field"
|
||||
:preview="preview"
|
||||
:failure="failureByField.get(field.name)"
|
||||
@update="(patch) => updateField(index, patch)"
|
||||
@remove="removeField(index)"
|
||||
/>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</template>
|
||||
@@ -0,0 +1,75 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { ago } from "@/lib/format";
|
||||
import { captures, capturesEnabled, draft, selectCapture, type Capture } from "./state";
|
||||
|
||||
/**
|
||||
* The mapping's own fields: the name it is saved under, the organisational
|
||||
* source hint, and the captured event the payload and the preview resolve
|
||||
* against. The hint is a note to a human, never a matcher -- t2db.4 decides
|
||||
* which events a mapping applies to.
|
||||
*
|
||||
* Laid out as labelled controls rather than the FieldGroup/Field pair, which
|
||||
* this project has not installed; each label is bound to its control by id so
|
||||
* the association survives a click on either.
|
||||
*/
|
||||
|
||||
/** The picker's value for "no capture chosen". Capture ids are numeric, so no
|
||||
* real option can collide with this one, and reka-ui refuses an empty-string
|
||||
* item value outright. */
|
||||
const NO_CAPTURE = "none";
|
||||
|
||||
const captureValue = computed(() => (draft.value.captureId === null ? NO_CAPTURE : String(draft.value.captureId)));
|
||||
|
||||
function onCaptureChange(value: unknown): void {
|
||||
selectCapture(String(value));
|
||||
}
|
||||
|
||||
function captureLabel(capture: Capture): string {
|
||||
return `${capture.source || "(unknown)"} — ${ago(capture.received_at)}`;
|
||||
}
|
||||
|
||||
/** What an empty picker means, which is not the same on every deployment. */
|
||||
const captureHint = computed(() => {
|
||||
if (captures.value.length) return null;
|
||||
return capturesEnabled.value
|
||||
? "No events have been captured yet, so there is nothing to bind against."
|
||||
: "Capture is not configured on this deployment, so there is nothing to preview against.";
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label for="mapping-name">Name</Label>
|
||||
<Input id="mapping-name" v-model="draft.name" />
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label for="mapping-source-hint">Source hint (organisational only)</Label>
|
||||
<Input id="mapping-source-hint" v-model="draft.sourceHint" />
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label for="mapping-capture">Preview against captured event</Label>
|
||||
<Select :model-value="captureValue" @update:model-value="onCaptureChange">
|
||||
<SelectTrigger id="mapping-capture" class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="NO_CAPTURE">— pick a captured event —</SelectItem>
|
||||
<SelectItem v-for="capture in captures" :key="capture.id" :value="String(capture.id)">
|
||||
{{ captureLabel(capture) }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p v-if="captureHint" class="text-xs text-fg-subtle">{{ captureHint }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { MappingField, Preview, PreviewFailure } from "./state";
|
||||
|
||||
/**
|
||||
* What the last preview said about one field: the value it resolved to, the
|
||||
* reason it could not resolve, or an explicit "not previewed".
|
||||
*
|
||||
* A null preview means nothing has been claimed yet, and a field that was not
|
||||
* previewed must never render as though it passed -- an unresolved field is not
|
||||
* the same claim as a resolved one.
|
||||
*/
|
||||
const props = defineProps<{ field: MappingField; preview: Preview | null; failure?: PreviewFailure }>();
|
||||
|
||||
const status = computed<{ variant: "ok" | "danger" | "idle"; text: string }>(() => {
|
||||
if (!props.preview) return { variant: "idle", text: "not previewed" };
|
||||
if (props.failure) return { variant: "danger", text: props.failure.reason };
|
||||
if (Object.prototype.hasOwnProperty.call(props.preview.values || {}, props.field.name)) {
|
||||
return { variant: "ok", text: JSON.stringify(props.preview.values?.[props.field.name]) };
|
||||
}
|
||||
// Absent from values and absent from failures: an optional field the payload
|
||||
// did not carry, which is not a failure.
|
||||
return { variant: "idle", text: "skipped (optional)" };
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Badge :variant="status.variant">{{ status.text }}</Badge>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { TableCell, TableRow } from "@/components/ui/table";
|
||||
import type { Mapping } from "./state";
|
||||
|
||||
/** One saved mapping's summary row. Both of its actions are the page's, not the
|
||||
* row's: editing opens the editor overlay, deleting opens the confirmation. */
|
||||
defineProps<{ mapping: Mapping }>();
|
||||
const emit = defineEmits<{ edit: [mapping: Mapping]; delete: [mapping: Mapping] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TableRow>
|
||||
<TableCell class="font-medium">{{ mapping.name }}</TableCell>
|
||||
<TableCell class="font-mono">{{ mapping.source_hint || "—" }}</TableCell>
|
||||
<TableCell>{{ mapping.fields?.length ?? 0 }}</TableCell>
|
||||
<TableCell>
|
||||
<div class="flex justify-end gap-2">
|
||||
<Button variant="outline" size="xs" @click="emit('edit', mapping)">Edit</Button>
|
||||
<Button variant="destructive" size="xs" @click="emit('delete', mapping)">Delete</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { Plus } from "@lucide/vue";
|
||||
import { onMounted } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import MappingActionError from "./MappingActionError.vue";
|
||||
import MappingDeleteDialog from "./MappingDeleteDialog.vue";
|
||||
import MappingEditorDialog from "./MappingEditorDialog.vue";
|
||||
import MappingsTable from "./MappingsTable.vue";
|
||||
import { actionError, loadMappings, startCreate } from "./state";
|
||||
|
||||
/**
|
||||
* Payload field mapping (t2db.3): bind named fields to JSON paths inside a real
|
||||
* captured event, preview the resolution before saving, and manage saved
|
||||
* mappings. See docs/prds/payload-field-mapping.md. Binding a mapping and a
|
||||
* matcher to a workflow (t2db.4) is a separate, not-yet-built page -- this one
|
||||
* only produces the mapping entity and its preview.
|
||||
*
|
||||
* Composes the list and the two overlays; it holds no state of its own.
|
||||
*/
|
||||
onMounted(loadMappings);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="mb-5 flex flex-wrap items-start justify-between gap-5">
|
||||
<div>
|
||||
<h1 class="text-3xl font-semibold tracking-[-0.03em]">Field mappings</h1>
|
||||
<p class="mt-2 text-sm text-fg-muted">
|
||||
Bind named fields to JSON paths from a real captured event, ready for a playbook binding.
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Button @click="startCreate">
|
||||
<Plus data-icon="inline-start" />
|
||||
New mapping
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MappingActionError v-if="actionError" class="mb-4" :failure="actionError" />
|
||||
|
||||
<MappingsTable />
|
||||
|
||||
<MappingEditorDialog />
|
||||
<MappingDeleteDialog />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,60 @@
|
||||
<script setup lang="ts">
|
||||
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 MappingRow from "./MappingRow.vue";
|
||||
import { listLoading, loadError, mappings, requestDelete, startEdit } from "./state";
|
||||
|
||||
/**
|
||||
* The saved mappings, in all four states: still loading, unreadable, none yet,
|
||||
* and the table. A list that cannot be read says so instead of rendering empty,
|
||||
* because "no mappings yet" and "cannot reach archied" call for different
|
||||
* actions from whoever is looking.
|
||||
*/
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="listLoading" class="flex flex-col gap-2" aria-busy="true">
|
||||
<Skeleton class="h-10 w-full" />
|
||||
<Skeleton class="h-28 w-full" />
|
||||
</div>
|
||||
|
||||
<Empty v-else-if="loadError">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>Cannot reach archied</EmptyTitle>
|
||||
<EmptyDescription>{{ loadError }}</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
|
||||
<Empty v-else-if="!mappings.length">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>No mappings yet</EmptyTitle>
|
||||
<EmptyDescription>Create one from a captured event to reuse its fields in a future playbook binding.</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
|
||||
<Card v-else>
|
||||
<CardContent>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Name</TableHead>
|
||||
<TableHead>Source hint</TableHead>
|
||||
<TableHead>Fields</TableHead>
|
||||
<TableHead><span class="sr-only">Actions</span></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<MappingRow
|
||||
v-for="mapping in mappings"
|
||||
:key="mapping.id"
|
||||
:mapping="mapping"
|
||||
@edit="startEdit"
|
||||
@delete="requestDelete"
|
||||
/>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
@@ -0,0 +1,65 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import { fieldTypeFromValue, pathAppendIndex, pathAppendKey, type FieldPick } from "./mapping-fields";
|
||||
|
||||
/**
|
||||
* One level of a captured payload, with every key and every leaf clickable, so
|
||||
* a field is bound by clicking through the real payload rather than by typing a
|
||||
* JSON path -- "click through its payload, bind JSON paths" per
|
||||
* docs/prds/payload-field-mapping.md. Recurses into itself for child objects
|
||||
* and arrays, so depth costs nothing to support.
|
||||
*
|
||||
* A key is clickable in its own right: binding `data` whole is a legitimate
|
||||
* choice, and the type is inferred from whatever that node happens to hold.
|
||||
*/
|
||||
const props = withDefaults(defineProps<{ value: unknown; path?: string; name?: string }>(), { path: "", name: "" });
|
||||
const emit = defineEmits<{ pick: [pick: FieldPick] }>();
|
||||
|
||||
const isBranch = computed(() => props.value !== null && typeof props.value === "object");
|
||||
|
||||
/** This level's children, each with the path that addresses it. */
|
||||
const entries = computed<Array<{ key: string; value: unknown; path: string }>>(() => {
|
||||
if (!isBranch.value) return [];
|
||||
if (Array.isArray(props.value)) {
|
||||
return props.value.map((child, index) => ({
|
||||
key: String(index),
|
||||
value: child,
|
||||
path: pathAppendIndex(props.path, index),
|
||||
}));
|
||||
}
|
||||
return Object.entries(props.value as Record<string, unknown>).map(([key, child]) => ({
|
||||
key,
|
||||
value: child,
|
||||
path: pathAppendKey(props.path, key),
|
||||
}));
|
||||
});
|
||||
|
||||
function pick(path: string, key: string, value: unknown): void {
|
||||
emit("pick", { path, type: fieldTypeFromValue(value), name: key });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul v-if="isBranch" class="flex list-none flex-col gap-0.5 pl-4 font-mono text-xs">
|
||||
<li v-for="entry in entries" :key="entry.path">
|
||||
<button
|
||||
type="button"
|
||||
class="focus-visible:ring-ring rounded-sm px-1 text-left outline-none hover:bg-muted focus-visible:ring-2"
|
||||
@click="pick(entry.path, entry.key, entry.value)"
|
||||
>
|
||||
{{ entry.key }}
|
||||
</button>
|
||||
<PayloadTree :value="entry.value" :path="entry.path" :name="entry.key" @pick="emit('pick', $event)" />
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="focus-visible:ring-ring ml-1 rounded-sm px-1 text-fg-subtle outline-none hover:bg-muted focus-visible:ring-2"
|
||||
@click="pick(path, name, value)"
|
||||
>
|
||||
{{ JSON.stringify(value) }}
|
||||
</button>
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* The field-mapping vocabulary and its pure path/type logic, split out of the
|
||||
* components so it can be reasoned about and tested without their fetch
|
||||
* wiring -- the split the Preact build made with mapping-editor.jsx.
|
||||
*/
|
||||
|
||||
/** The JSON shapes a bound field can claim, matching mapping.FieldType in Go. */
|
||||
export type FieldType = "string" | "number" | "bool" | "object" | "array" | "any";
|
||||
|
||||
export const FIELD_TYPES: FieldType[] = ["string", "number", "bool", "object", "array", "any"];
|
||||
|
||||
const FIELD_TYPE_SET: ReadonlySet<string> = new Set(FIELD_TYPES);
|
||||
|
||||
/** One value clicked in the payload tree, ready to become a bound field. */
|
||||
export interface FieldPick {
|
||||
path: string;
|
||||
type: FieldType;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Infers the FieldType a freshly-clicked example value suggests. A null value
|
||||
* claims nothing about its shape, so it binds as `any` rather than as a type
|
||||
* the payload did not actually demonstrate.
|
||||
*/
|
||||
export function fieldTypeFromValue(value: unknown): FieldType {
|
||||
if (value === null || value === undefined) return "any";
|
||||
if (Array.isArray(value)) return "array";
|
||||
switch (typeof value) {
|
||||
case "string":
|
||||
return "string";
|
||||
case "number":
|
||||
return "number";
|
||||
case "boolean":
|
||||
return "bool";
|
||||
case "object":
|
||||
return "object";
|
||||
default:
|
||||
return "any";
|
||||
}
|
||||
}
|
||||
|
||||
/** Narrows a control's value back to a FieldType, refusing anything else. */
|
||||
export function asFieldType(value: unknown): FieldType {
|
||||
return typeof value === "string" && FIELD_TYPE_SET.has(value) ? (value as FieldType) : "any";
|
||||
}
|
||||
|
||||
export function pathAppendKey(path: string, key: string): string {
|
||||
return path ? `${path}.${key}` : key;
|
||||
}
|
||||
|
||||
export function pathAppendIndex(path: string, index: number): string {
|
||||
return `${path}[${index}]`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A field name no other bound field is using. The daemon rejects a mapping
|
||||
* whose fields repeat a name -- a duplicate would let one field silently
|
||||
* overwrite another's resolved value at resolve time -- so a click that
|
||||
* collides is suffixed rather than refused.
|
||||
*/
|
||||
export function uniqueFieldName(taken: Iterable<string>, name: string): string {
|
||||
const existing = new Set(taken);
|
||||
const base = name || "field";
|
||||
let candidate = base;
|
||||
let n = 1;
|
||||
while (existing.has(candidate)) candidate = `${base}_${++n}`;
|
||||
return candidate;
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
|
||||
import { uniqueFieldName, type FieldPick, type FieldType } from "./mapping-fields";
|
||||
|
||||
/**
|
||||
* The mappings page's shared state: the saved mappings, the captured events a
|
||||
* mapping can be previewed against, and the one editing session in flight.
|
||||
*
|
||||
* The list, the editor overlay, the bound-fields table and the payload tree all
|
||||
* read and mutate it, so it lives in a module rather than being threaded down
|
||||
* through a chain of props.
|
||||
*/
|
||||
|
||||
/** One bound field, as the daemon stores it (mapping.Field). */
|
||||
export interface MappingField {
|
||||
name: string;
|
||||
path: string;
|
||||
type: FieldType;
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A named, reusable set of bindings (mapping.Mapping). The source hint is
|
||||
* organisational only: a mapping is authored by clicking through one example
|
||||
* captured event but is not pinned to that event or its source, because
|
||||
* t2db.4's matcher decides which events a mapping applies to.
|
||||
*/
|
||||
export interface Mapping {
|
||||
id: number;
|
||||
name: string;
|
||||
source_hint?: string;
|
||||
fields?: MappingField[];
|
||||
}
|
||||
|
||||
/** A captured inbound event. Its body is redacted before it is stored, and is
|
||||
* the only thing a path is ever resolved against. */
|
||||
export interface Capture {
|
||||
id: number;
|
||||
source?: string;
|
||||
received_at?: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
/** One field the preview could not resolve, and why. */
|
||||
export interface PreviewFailure {
|
||||
field_name: string;
|
||||
path?: string;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
/** What POST /api/mappings/preview answers: the fields that resolved, by name,
|
||||
* and every field that did not. */
|
||||
export interface Preview {
|
||||
values?: Record<string, unknown>;
|
||||
failures?: PreviewFailure[];
|
||||
}
|
||||
|
||||
/** One editing session: the working copy of a mapping, the example payload it
|
||||
* is bound from, and the last preview of the two together. */
|
||||
export interface MappingDraft {
|
||||
/** null until the first save. */
|
||||
id: number | null;
|
||||
name: string;
|
||||
sourceHint: string;
|
||||
fields: MappingField[];
|
||||
/** The capture the payload and the preview resolve against, or null. */
|
||||
captureId: number | null;
|
||||
/** The parsed capture body, or null when no capture is picked. */
|
||||
payload: unknown;
|
||||
payloadError: string | null;
|
||||
preview: Preview | null;
|
||||
}
|
||||
|
||||
/** An action failure: the daemon's three kinds, plus a local one for an action
|
||||
* the editor cannot attempt yet. */
|
||||
export type MappingErrorKind = ActionErrorKind | "incomplete";
|
||||
|
||||
export interface ActionFailure {
|
||||
kind: MappingErrorKind;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export const mappings = ref<Mapping[]>([]);
|
||||
export const captures = ref<Capture[]>([]);
|
||||
/** Whether this deployment has capture storage at all. GET /api/captures
|
||||
* answers {"enabled": false} rather than failing, which is what lets an empty
|
||||
* picker say whether nothing has been captured yet or nothing can be. */
|
||||
export const capturesEnabled = ref(true);
|
||||
/** true until the first list load settles. */
|
||||
export const listLoading = ref(true);
|
||||
/** A failed list load. Distinct from an action failure: the list is unusable,
|
||||
* where a refused action leaves it perfectly readable. */
|
||||
export const loadError = ref<string | null>(null);
|
||||
|
||||
/** Whether the editor overlay is showing the draft. */
|
||||
export const editorOpen = ref(false);
|
||||
/** The editing session. Always present, so the form's bindings need no null
|
||||
* branch; `editorOpen` says whether it is on screen. */
|
||||
export const draft = ref<MappingDraft>(blankDraft());
|
||||
export const saving = ref(false);
|
||||
|
||||
/** The last failed operator action, classified for rendering. One slot, as
|
||||
* Preact had: preview and save report into the same place. */
|
||||
export const actionError = ref<ActionFailure | null>(null);
|
||||
|
||||
/** The mapping awaiting delete confirmation. */
|
||||
export const pendingDelete = ref<Mapping | null>(null);
|
||||
|
||||
function blankDraft(): MappingDraft {
|
||||
return {
|
||||
id: null,
|
||||
name: "",
|
||||
sourceHint: "",
|
||||
fields: [],
|
||||
captureId: null,
|
||||
payload: null,
|
||||
payloadError: null,
|
||||
preview: null,
|
||||
};
|
||||
}
|
||||
|
||||
export async function loadMappings(): Promise<void> {
|
||||
listLoading.value = true;
|
||||
try {
|
||||
// Capture storage is optional infrastructure -- a deployment can serve
|
||||
// mappings without it -- so a failing capture leg degrades to an empty
|
||||
// picker instead of taking the mappings list down with it.
|
||||
const [listed, captured] = await Promise.all([
|
||||
api.mappings<{ mappings?: Mapping[] }>(),
|
||||
api.captures<{ captures?: Capture[]; enabled?: boolean }>(100).catch(() => null),
|
||||
]);
|
||||
mappings.value = listed.mappings || [];
|
||||
captures.value = captured?.captures || [];
|
||||
capturesEnabled.value = captured?.enabled !== false;
|
||||
loadError.value = null;
|
||||
} catch (err) {
|
||||
loadError.value = String((err as Error).message || err);
|
||||
} finally {
|
||||
listLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
export function startCreate(): void {
|
||||
draft.value = blankDraft();
|
||||
actionError.value = null;
|
||||
editorOpen.value = true;
|
||||
}
|
||||
|
||||
export function startEdit(mapping: Mapping): void {
|
||||
draft.value = {
|
||||
...blankDraft(),
|
||||
id: mapping.id,
|
||||
name: mapping.name,
|
||||
sourceHint: mapping.source_hint || "",
|
||||
// Copied, not aliased: the editor must not write through to the loaded list.
|
||||
fields: (mapping.fields || []).map((field) => ({ ...field })),
|
||||
};
|
||||
actionError.value = null;
|
||||
editorOpen.value = true;
|
||||
}
|
||||
|
||||
export function closeEditor(): void {
|
||||
editorOpen.value = false;
|
||||
actionError.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Picks the example event the payload panel and the preview resolve against.
|
||||
* The body is parsed once, here, so a body that is not JSON reads as exactly
|
||||
* that rather than as a payload whose paths all failed.
|
||||
*/
|
||||
export function selectCapture(value: string): void {
|
||||
const capture = captures.value.find((candidate) => String(candidate.id) === value) ?? null;
|
||||
const current = draft.value;
|
||||
current.captureId = capture ? capture.id : null;
|
||||
current.preview = null;
|
||||
if (!capture) {
|
||||
current.payload = null;
|
||||
current.payloadError = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
current.payload = JSON.parse(capture.body);
|
||||
current.payloadError = null;
|
||||
} catch {
|
||||
current.payload = null;
|
||||
current.payloadError = "This capture's body is not valid JSON, so its fields cannot be mapped by path.";
|
||||
}
|
||||
}
|
||||
|
||||
/** Binds one clicked payload value as a new required field. */
|
||||
export function addField(pick: FieldPick): void {
|
||||
const current = draft.value;
|
||||
const name = uniqueFieldName(
|
||||
current.fields.map((field) => field.name),
|
||||
pick.name,
|
||||
);
|
||||
current.fields.push({ name, path: pick.path, type: pick.type, required: true });
|
||||
// Any edit invalidates the preview: it described the fields as they were.
|
||||
current.preview = null;
|
||||
}
|
||||
|
||||
export function updateField(index: number, patch: Partial<MappingField>): void {
|
||||
const current = draft.value;
|
||||
current.fields[index] = { ...current.fields[index], ...patch };
|
||||
current.preview = null;
|
||||
}
|
||||
|
||||
export function removeField(index: number): void {
|
||||
draft.value.fields.splice(index, 1);
|
||||
draft.value.preview = null;
|
||||
}
|
||||
|
||||
export async function runPreview(): Promise<void> {
|
||||
const current = draft.value;
|
||||
if (current.captureId === null) {
|
||||
actionError.value = { kind: "incomplete", message: "Pick a captured event to preview against." };
|
||||
return;
|
||||
}
|
||||
try {
|
||||
current.preview = await api.mappingPreview<Preview>(current.captureId, current.fields);
|
||||
actionError.value = null;
|
||||
} catch (err) {
|
||||
actionError.value = classifyActionError(err);
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveMapping(): Promise<void> {
|
||||
if (saving.value) return;
|
||||
const current = draft.value;
|
||||
const body = { name: current.name, source_hint: current.sourceHint, fields: current.fields };
|
||||
saving.value = true;
|
||||
try {
|
||||
if (current.id !== null) await api.mappingUpdate(String(current.id), body);
|
||||
else await api.mappingCreate(body);
|
||||
closeEditor();
|
||||
await loadMappings();
|
||||
} catch (err) {
|
||||
actionError.value = classifyActionError(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
export function requestDelete(mapping: Mapping): void {
|
||||
pendingDelete.value = mapping;
|
||||
}
|
||||
|
||||
export function cancelDelete(): void {
|
||||
pendingDelete.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms the pending delete. A failure lands in the action alert and leaves
|
||||
* the list as it was: a refused delete says nothing about whether the daemon is
|
||||
* reachable, and reporting it as "cannot reach archied" would be untrue.
|
||||
*/
|
||||
export async function confirmDelete(): Promise<void> {
|
||||
const target = pendingDelete.value;
|
||||
if (!target) return;
|
||||
pendingDelete.value = null;
|
||||
try {
|
||||
await api.mappingDelete(String(target.id));
|
||||
await loadMappings();
|
||||
} catch (err) {
|
||||
actionError.value = classifyActionError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/** How a failed action reads as an Alert title. The message under it is the
|
||||
* server's own, which is the part an operator can act on. */
|
||||
export function actionErrorTitle(kind: MappingErrorKind): string {
|
||||
switch (kind) {
|
||||
case "session-expired":
|
||||
return "Your session expired";
|
||||
case "refused":
|
||||
return "archied refused that";
|
||||
case "incomplete":
|
||||
return "Not ready to preview";
|
||||
default:
|
||||
return "archied could not complete that";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user