diff --git a/ui/src/captures/capture-row.jsx b/ui/src/captures/capture-row.jsx index dbc817a85..c17500259 100644 --- a/ui/src/captures/capture-row.jsx +++ b/ui/src/captures/capture-row.jsx @@ -1,54 +1,68 @@ -import { ago, el, pill } from "../base/dom.jsx"; +import { h, Fragment } from "preact"; +import { ago } from "../base/dom.jsx"; + +export function Pill({ text, kind = "idle" }) { + return {text}; +} /** * One captured event's summary row, plus its expandable detail row when * expanded is true. Split out from captures.js so it can be unit tested * without the page's fetch/SSE wiring, mirroring tasks/task-row.js. */ -export function captureRow(c, { expanded, onToggle }) { - const row = el( - "tr.capture-row", - { - tabindex: "0", - "aria-expanded": String(expanded), - onclick: onToggle, - onkeydown: (e) => { - if (e.key !== "Enter" && e.key !== " ") return; - e.preventDefault(); - onToggle(e); - }, - }, - el("td.mono", c.source || "(unknown)"), - el("td", { title: c.received_at || "" }, ago(c.received_at)), - // Every captured event is unbound today: no playbook binding data model - // exists yet (t2db.4). Once a binding can match an event, this pill - // distinguishes bound from unbound instead of always reading "Unbound" - // -- see docs/prds/event-capture-storage.md's "what this does not decide". - el("td", pill("Unbound", "idle")), - el("td.mono", c.content_type || "—"), - el("td", el("button.btn.btn-small", { type: "button" }, expanded ? "Hide" : "View")), - ); - return expanded ? [row, captureDetailRow(c)] : [row]; -} +export function CaptureRow({ capture: c, expanded, onToggle }) { + const handleKeyDown = (e) => { + if (e.key !== "Enter" && e.key !== " ") return; + e.preventDefault(); + onToggle(e); + }; -export function captureDetailRow(c) { - return el( - "tr.capture-detail-row", - el( - "td", - { colspan: 5 }, - el( - "div.capture-detail", - el("div.capture-detail-section", el("div.capture-detail-title", "Payload"), payloadView(c.body)), - el("div.capture-detail-section", el("div.capture-detail-title", "Headers"), payloadView(c.headers)), - ), - ), + return ( + + + {c.source || "(unknown)"} + {ago(c.received_at)} + + {c.content_type || "—"} + + + + + {expanded && } + ); } -function payloadView(raw) { - if (!raw) return el("div.capture-empty", "(empty)"); - return el("pre.capture-payload", prettyPrint(raw)); +export function CaptureDetailRow({ capture: c }) { + return ( + + +
+
+
Payload
+ +
+
+
Headers
+ +
+
+ + + ); +} + +function PayloadView({ raw }) { + if (!raw) return
(empty)
; + return
{prettyPrint(raw)}
; } // prettyPrint indents valid JSON for readability; a non-JSON payload (the diff --git a/ui/src/captures/captures.jsx b/ui/src/captures/captures.jsx index ef4b5116b..96704a018 100644 --- a/ui/src/captures/captures.jsx +++ b/ui/src/captures/captures.jsx @@ -1,7 +1,17 @@ +import { h, Fragment } from "preact"; +import { useState, useEffect } from "preact/hooks"; import "./captures.css"; import { api, subscribeEvents } from "../base/api.jsx"; -import { el, empty, mount, pill } from "../base/dom.jsx"; -import { captureRow } from "./capture-row.jsx"; +import { CaptureRow, Pill } from "./capture-row.jsx"; + +export function Empty({ title, detail }) { + return ( +
+
{title}
+ {detail &&
{detail}
} +
+ ); +} /** * Event inspector (t2db.2): the operator-facing half of capture. Recent @@ -17,100 +27,95 @@ import { captureRow } from "./capture-row.jsx"; * as an invalidation signal, triggering a refetch of the authoritative list * rather than being merged into local state directly. */ -export function capturesPage() { - const root = el("div"); - const list = el("div.card"); - const streamState = pill("connecting", "idle"); +export function capturesPage(query) { + return ; +} - let captures = []; - let expandedId = null; - let loadError = null; - let enabled = true; +function CapturesApp({ query }) { + const [captures, setCaptures] = useState([]); + const [expandedId, setExpandedId] = useState(null); + const [loadError, setLoadError] = useState(null); + const [enabled, setEnabled] = useState(true); + const [streamState, setStreamState] = useState({ text: "connecting", kind: "idle" }); - render(); - load(); - - const unsubscribe = subscribeEvents( - (event) => { - if (event.kind !== "capture") return; - load(); - }, - (state) => { - streamState.className = `pill pill-${state === "live" ? "ok" : "warn"}`; - streamState.textContent = state; - }, - ); - root.addEventListener("archie:teardown", unsubscribe); - - async function load() { + const load = async () => { try { const res = await api.captures(100); - enabled = res.enabled !== false; - captures = res.captures || []; - loadError = null; + setEnabled(res.enabled !== false); + setCaptures(res.captures || []); + setLoadError(null); } catch (err) { - loadError = String(err.message || err); + setLoadError(String(err.message || err)); } - renderRows(); - } + }; - function render() { - mount( - root, - el( - "div.page-head", - el( - "div", - el("h1.page-title", "Event inspector"), - el("p.page-sub", "Real inbound payloads archie has captured, most recent first."), - ), - el("div.page-actions", streamState, el("button.btn", { onclick: load }, "Refresh")), - ), - list, + useEffect(() => { + load(); + const unsubscribe = subscribeEvents( + (event) => { + if (event.kind !== "capture") return; + load(); + }, + (state) => { + setStreamState({ + text: state, + kind: state === "live" ? "ok" : "warn", + }); + } ); - renderRows(); - } + return () => unsubscribe(); + }, []); - function renderRows() { + const renderRows = () => { if (loadError) { - mount(list, empty("Cannot reach archied", loadError)); - return; + return ; } if (!enabled) { - mount(list, empty("Capture is not configured", "This deployment has no capture storage wired up.")); - return; + return ; } if (!captures.length) { - mount( - list, - empty("No captures yet", "Point a webhook at /webhooks/capture/ and it will show up here."), - ); - return; + return ; } - mount( - list, - el( - "div.table-scroll", - el( - "table.table", - el( - "thead", - el( - "tr", - ...["Source", "Received", "Binding", "Content type", ""].map((h) => el("th", h)), - ), - ), - el("tbody", ...captures.flatMap((c) => captureRow(c, { - expanded: expandedId === c.id, - onToggle: () => { - expandedId = expandedId === c.id ? null : c.id; - renderRows(); - }, - }))), - ), - ), + return ( +
+ + + + {["Source", "Received", "Binding", "Content type", ""].map((h, i) => ( + + ))} + + + + {captures.map((c) => ( + setExpandedId(expandedId === c.id ? null : c.id)} + /> + ))} + +
{h}
+
); - } + }; - return root; + return ( +
+
+
+

Event inspector

+

Real inbound payloads archie has captured, most recent first.

+
+
+ + +
+
+
+ {renderRows()} +
+
+ ); } diff --git a/ui/src/curators/curators.jsx b/ui/src/curators/curators.jsx index 3ff24b148..72f4a98a5 100644 --- a/ui/src/curators/curators.jsx +++ b/ui/src/curators/curators.jsx @@ -1,6 +1,21 @@ +import { h, Fragment } from "preact"; +import { useState, useEffect } from "preact/hooks"; import "./curators.css"; import { api } from "../base/api.jsx"; -import { el, empty, mount, pill, ago } from "../base/dom.jsx"; +import { ago } from "../base/dom.jsx"; + +function Pill({ text, kind = "idle" }) { + return {text}; +} + +function Empty({ title, detail }) { + return ( +
+
{title}
+ {detail &&
{detail}
} +
+ ); +} /** * Curator observability (archie-core-1786637489932-6). Backed by GET @@ -9,96 +24,104 @@ import { el, empty, mount, pill, ago } from "../base/dom.jsx"; * activity (last run, action count, and the actions themselves with the * reason each one happened) -- see internal/webui/api_curators.go. */ -export function curatorsPage() { - const root = el("div"); - const cardGrid = el("div.grid.grid-2"); +export function curatorsPage(query) { + return ; +} - render(); - load(); +function CuratorsApp({ query }) { + const [curators, setCurators] = useState([]); + const [loadError, setLoadError] = useState(null); - function render() { - mount( - root, - el( - "div.page-head", - el( - "div", - el("h1.page-title", "Curators"), - el("p.page-sub", "Background agents that maintain memory and skills: what ran, and why."), - ), - el("div.page-actions", el("button.btn", { onclick: load }, "Refresh")), - ), - cardGrid, - ); - } - - async function load() { + const load = async () => { try { const res = await api.curators(); - renderCards(res?.curators || []); + setCurators(res?.curators || []); + setLoadError(null); } catch (err) { - mount(cardGrid, empty("Cannot reach archied", String(err.message || err))); + setLoadError(String(err.message || err)); } - } + }; - function renderCards(curators) { + useEffect(() => { + load(); + }, []); + + const renderCards = () => { + if (loadError) { + return ; + } if (!curators.length) { - mount( - cardGrid, - empty( - "No curators registered", - "Curators are background agent loops that maintain memory and skills. None are registered on this daemon.", - ), + return ( + ); - return; } - mount(cardGrid, ...curators.map(curatorCard)); - } + return curators.map(c => ); + }; - function healthKind(status) { - switch (status) { - case "healthy": - return "ok"; - case "degraded": - return "warn"; - case "unhealthy": - return "danger"; - default: - return "idle"; - } + return ( +
+
+
+

Curators

+

Background agents that maintain memory and skills: what ran, and why.

+
+
+ +
+
+
+ {renderCards()} +
+
+ ); +} + +function healthKind(status) { + switch (status) { + case "healthy": + return "ok"; + case "degraded": + return "warn"; + case "unhealthy": + return "danger"; + default: + return "idle"; } +} - function curatorCard(c) { - const actions = c.recent_actions || []; - return el( - "div.card.curator-card", - el( - "div.card-head", - el("h3.card-title", c.name), - pill(c.health?.status || "unknown", healthKind(c.health?.status)), - ), - c.health?.message && el("p.curator-health-message", c.health.message), - el( - "p.curator-meta", - c.last_run_at +function CuratorCard({ curator: c }) { + const actions = c.recent_actions || []; + return ( +
+
+

{c.name}

+ +
+ {c.health?.message &&

{c.health.message}

} +

+ {c.last_run_at ? `Last ran ${ago(c.last_run_at)} · ${c.last_run_actions} action${c.last_run_actions === 1 ? "" : "s"}` - : "Has not run yet", - ), - actions.length - ? el( - "ul.curator-actions", - ...actions.map((a) => - el( - "li.curator-action", - el("div.curator-action-head", el("span.curator-action-type", a.type || "action"), el("span.curator-action-time", ago(a.at))), - a.detail && el("p.curator-action-detail", a.detail), - a.reason && el("p.curator-action-reason", `Why: ${a.reason}`), - ), - ), - ) - : el("p.curator-meta", "No recorded activity yet."), - ); - } - - return root; + : "Has not run yet"} +

+ {actions.length ? ( +
    + {actions.map((a, i) => ( +
  • +
    + {a.type || "action"} + {ago(a.at)} +
    + {a.detail &&

    {a.detail}

    } + {a.reason &&

    Why: {a.reason}

    } +
  • + ))} +
+ ) : ( +

No recorded activity yet.

+ )} +
+ ); } diff --git a/ui/src/mappings/mapping-editor.jsx b/ui/src/mappings/mapping-editor.jsx index 31bdc92c0..3561aedc0 100644 --- a/ui/src/mappings/mapping-editor.jsx +++ b/ui/src/mappings/mapping-editor.jsx @@ -1,4 +1,8 @@ -import { el, pill } from "../base/dom.jsx"; +import { h, Fragment } from "preact"; + +export function Pill({ text, kind = "idle" }) { + return {text}; +} /** * Pure rendering + path/type logic for the mapping editor, split out from @@ -40,30 +44,40 @@ export function pathAppendIndex(path, index) { * without the operator ever typing a JSON path by hand -- "click through * its payload, bind JSON paths" per docs/prds/payload-field-mapping.md. */ -export function payloadTree(value, { path = "", name = "", onPick } = {}) { +export function PayloadTree({ value, path = "", name = "", onPick }) { if (value !== null && typeof value === "object") { const entries = Array.isArray(value) ? value.map((v, i) => [String(i), v, pathAppendIndex(path, i)]) : Object.entries(value).map(([k, v]) => [k, v, pathAppendKey(path, k)]); - return el( - "ul.mapping-tree-list", - ...entries.map(([key, child, childPath]) => - el( - "li.mapping-tree-item", - el( - "span.mapping-tree-key", - { onclick: (e) => { e.stopPropagation(); onPick?.({ path: childPath, type: fieldTypeFromValue(child), name: key }); } }, - key, - ), - payloadTree(child, { path: childPath, name: key, onPick }), - ), - ), + return ( +
    + {entries.map(([key, child, childPath]) => ( +
  • + { + e.stopPropagation(); + if (onPick) onPick({ path: childPath, type: fieldTypeFromValue(child), name: key }); + }} + > + {key} + + +
  • + ))} +
); } - return el( - "span.mapping-tree-value", - { onclick: (e) => { e.stopPropagation(); onPick?.({ path, type: fieldTypeFromValue(value), name }); } }, - JSON.stringify(value), + return ( + { + e.stopPropagation(); + if (onPick) onPick({ path, type: fieldTypeFromValue(value), name }); + }} + > + {JSON.stringify(value)} + ); } @@ -73,69 +87,83 @@ export function payloadTree(value, { path = "", name = "", onPick } = {}) { * rather than a false pass, since an unresolved field is not the same * claim as a resolved one. */ -export function fieldsTable(fields, { preview, onRemove, onNameChange, onTypeChange, onRequiredChange } = {}) { +export function FieldsTable({ fields, preview, onRemove, onNameChange, onTypeChange, onRequiredChange }) { if (!fields.length) { - return el("div.mapping-empty-fields", "Click a value in the payload to bind a field."); + return
Click a value in the payload to bind a field.
; } const failureByField = new Map((preview?.failures || []).map((f) => [f.field_name, f])); - return el( - "table.table.mapping-fields-table", - el( - "thead", - el("tr", ...["Field name", "Path", "Type", "Required", "Preview", ""].map((h) => el("th", h))), - ), - el( - "tbody", - ...fields.map((f, i) => - el( - "tr", - el("td", el("input.mapping-input", { - value: f.name, - oninput: (e) => onNameChange?.(i, e.target.value), - })), - el("td.mono", f.path), - el( - "td", - el( - "select.mapping-select", - { onchange: (e) => onTypeChange?.(i, e.target.value) }, - ...FIELD_TYPES.map((t) => el("option", { value: t, selected: t === f.type }, t)), - ), - ), - el("td", el("input", { - type: "checkbox", - checked: f.required, - onchange: (e) => onRequiredChange?.(i, e.target.checked), - })), - el("td", previewStatus(f, preview, failureByField)), - el("td", el("button.btn.btn-small", { type: "button", onclick: () => onRemove?.(i) }, "Remove")), - ), - ), - ), + return ( + + + + {["Field name", "Path", "Type", "Required", "Preview", ""].map((h, i) => ( + + ))} + + + + {fields.map((f, i) => ( + + + + + + + + + ))} + +
{h}
+ onNameChange?.(i, e.target.value)} + /> + {f.path} + + + onRequiredChange?.(i, e.target.checked)} + /> + + + + +
); } -function previewStatus(field, preview, failureByField) { - if (!preview) return pill("not previewed", "idle"); +function PreviewStatus({ field, preview, failureByField }) { + if (!preview) return ; const failure = failureByField.get(field.name); - if (failure) return pill(failure.reason, "danger"); + if (failure) return ; if (Object.prototype.hasOwnProperty.call(preview.values || {}, field.name)) { - return pill(JSON.stringify(preview.values[field.name]), "ok"); + return ; } - return pill("skipped (optional)", "idle"); + return ; } /** One saved mapping's summary row for the mapping list. */ -export function mappingRow(m, { onEdit, onDelete }) { - return el( - "tr", - el("td", m.name), - el("td.mono", m.source_hint || "—"), - el("td", String(m.fields?.length ?? 0)), - el( - "td", - el("button.btn.btn-small", { type: "button", onclick: () => onEdit?.(m) }, "Edit"), - el("button.btn.btn-small", { type: "button", onclick: () => onDelete?.(m) }, "Delete"), - ), +export function MappingRow({ mapping: m, onEdit, onDelete }) { + return ( + + {m.name} + {m.source_hint || "—"} + {String(m.fields?.length ?? 0)} + + + + + ); } diff --git a/ui/src/mappings/mappings.jsx b/ui/src/mappings/mappings.jsx index 7c86ded4f..0e5c60c56 100644 --- a/ui/src/mappings/mappings.jsx +++ b/ui/src/mappings/mappings.jsx @@ -1,7 +1,17 @@ +import { h, Fragment } from "preact"; +import { useState, useEffect } from "preact/hooks"; import "./mappings.css"; import { api } from "../base/api.jsx"; -import { el, empty, mount } from "../base/dom.jsx"; -import { fieldsTable, mappingRow, payloadTree } from "./mapping-editor.jsx"; +import { FieldsTable, MappingRow, PayloadTree } from "./mapping-editor.jsx"; + +export function Empty({ title, detail }) { + return ( +
+
{title}
+ {detail &&
{detail}
} +
+ ); +} /** * Payload field mapping (t2db.3): bind named fields to JSON paths inside a @@ -10,36 +20,37 @@ import { fieldsTable, mappingRow, payloadTree } from "./mapping-editor.jsx"; * a mapping + matcher to a workflow) is a separate, not-yet-built page -- * this one only produces the mapping entity and its preview. */ -export function mappingsPage() { - const root = el("div"); +export function mappingsPage(query) { + return ; +} - let mappings = []; - let captures = []; - let loadError = null; - let editor = null; +function MappingsApp({ query }) { + const [mappings, setMappings] = useState([]); + const [captures, setCaptures] = useState([]); + const [loadError, setLoadError] = useState(null); + const [editor, setEditor] = useState(null); - render(); - load(); - - async function load() { + const load = async () => { try { const [mRes, cRes] = await Promise.all([api.mappings(), api.captures(100)]); - mappings = mRes.mappings || []; - captures = cRes.captures || []; - loadError = null; + setMappings(mRes.mappings || []); + setCaptures(cRes.captures || []); + setLoadError(null); } catch (err) { - loadError = String(err.message || err); + setLoadError(String(err.message || err)); } - render(); - } + }; - function startCreate() { - editor = { id: null, name: "", sourceHint: "", fields: [], captureId: null, payload: null, payloadError: null, preview: null, actionError: null }; - render(); - } + useEffect(() => { + load(); + }, []); - function startEdit(m) { - editor = { + const startCreate = () => { + setEditor({ id: null, name: "", sourceHint: "", fields: [], captureId: null, payload: null, payloadError: null, preview: null, actionError: null }); + }; + + const startEdit = (m) => { + setEditor({ id: m.id, name: m.name, sourceHint: m.source_hint || "", @@ -49,86 +60,84 @@ export function mappingsPage() { payloadError: null, preview: null, actionError: null, - }; - render(); - } + }); + }; - async function remove(m) { + const remove = async (m) => { if (!window.confirm(`Delete mapping "${m.name}"?`)) return; try { await api.mappingDelete(m.id); await load(); } catch (err) { - loadError = String(err.message || err); - render(); + setLoadError(String(err.message || err)); } - } + }; - function selectCapture(captureId) { + const selectCapture = (captureId) => { const c = captures.find((c) => String(c.id) === String(captureId)); - editor.captureId = c ? c.id : null; - editor.preview = null; - if (!c) { - editor.payload = null; - editor.payloadError = null; - } else { - try { - editor.payload = JSON.parse(c.body); - editor.payloadError = null; - } catch { - editor.payload = null; - editor.payloadError = "This capture's body is not valid JSON, so its fields cannot be mapped by path."; + setEditor(prev => { + const next = { ...prev, captureId: c ? c.id : null, preview: null }; + if (!c) { + next.payload = null; + next.payloadError = null; + } else { + try { + next.payload = JSON.parse(c.body); + next.payloadError = null; + } catch { + next.payload = null; + next.payloadError = "This capture's body is not valid JSON, so its fields cannot be mapped by path."; + } } - } - render(); - } + return next; + }); + }; - function addField({ path, type, name }) { - const existing = new Set(editor.fields.map((f) => f.name)); - let candidate = name || "field"; - let n = 1; - while (existing.has(candidate)) candidate = `${name || "field"}_${++n}`; - editor.fields.push({ name: candidate, path, type, required: true }); - editor.preview = null; - render(); - } + const addField = ({ path, type, name }) => { + setEditor(prev => { + const existing = new Set(prev.fields.map((f) => f.name)); + let candidate = name || "field"; + let n = 1; + while (existing.has(candidate)) candidate = `${name || "field"}_${++n}`; + const newFields = [...prev.fields, { name: candidate, path, type, required: true }]; + return { ...prev, fields: newFields, preview: null }; + }); + }; - function removeField(i) { - editor.fields.splice(i, 1); - editor.preview = null; - render(); - } + const removeField = (i) => { + setEditor(prev => { + const newFields = prev.fields.slice(); + newFields.splice(i, 1); + return { ...prev, fields: newFields, preview: null }; + }); + }; - // Every field mutation goes through here so a stale preview can never be - // shown against fields it wasn't actually resolved against -- see - // docs/prds/payload-field-mapping.md's "never show a mapping the operator - // has not seen resolve against real data." - function mutateField(i, patch) { - Object.assign(editor.fields[i], patch); - editor.preview = null; - render(); - } + const mutateField = (i, patch) => { + setEditor(prev => { + const newFields = prev.fields.slice(); + newFields[i] = { ...newFields[i], ...patch }; + return { ...prev, fields: newFields, preview: null }; + }); + }; const renameField = (i, name) => mutateField(i, { name }); const retypeField = (i, type) => mutateField(i, { type }); const requireField = (i, required) => mutateField(i, { required }); - async function preview() { + const preview = async () => { if (!editor.captureId) { - editor.actionError = "Pick a captured event to preview against."; - render(); + setEditor(prev => ({ ...prev, actionError: "Pick a captured event to preview against." })); return; } try { - editor.preview = await api.mappingPreview(editor.captureId, editor.fields); - editor.actionError = null; + const previewRes = await api.mappingPreview(editor.captureId, editor.fields); + setEditor(prev => ({ ...prev, preview: previewRes, actionError: null })); } catch (err) { - editor.actionError = String(err.message || err); + setEditor(prev => ({ ...prev, actionError: String(err.message || err) })); } - render(); - } + }; - async function save() { + const save = async () => { const body = { name: editor.name, source_hint: editor.sourceHint, fields: editor.fields }; try { if (editor.id) { @@ -136,121 +145,128 @@ export function mappingsPage() { } else { await api.mappingCreate(body); } - editor = null; + setEditor(null); await load(); } catch (err) { - editor.actionError = String(err.message || err); - render(); + setEditor(prev => ({ ...prev, actionError: String(err.message || err) })); } - } + }; - function cancel() { - editor = null; - render(); - } + const cancel = () => { + setEditor(null); + }; - function render() { - mount(root, editor ? renderEditor() : renderList()); - } - - function renderList() { - return el( - "div", - el( - "div.page-head", - el( - "div", - el("h1.page-title", "Field mappings"), - el("p.page-sub", "Bind named fields to JSON paths from a real captured event, ready for a playbook binding."), - ), - el("div.page-actions", el("button.btn.btn-primary", { type: "button", onclick: startCreate }, "New mapping")), - ), - loadError - ? empty("Cannot reach archied", loadError) - : mappings.length - ? el( - "div.card", - el( - "div.table-scroll", - el( - "table.table", - el("thead", el("tr", ...["Name", "Source hint", "Fields", ""].map((h) => el("th", h)))), - el("tbody", ...mappings.map((m) => mappingRow(m, { onEdit: startEdit, onDelete: remove }))), - ), - ), - ) - : empty("No mappings yet", "Create one from a captured event to reuse fields in a future playbook binding."), + const renderList = () => { + return ( +
+
+
+

Field mappings

+

Bind named fields to JSON paths from a real captured event, ready for a playbook binding.

+
+
+ +
+
+ {loadError ? ( + + ) : mappings.length ? ( +
+
+ + + + {["Name", "Source hint", "Fields", ""].map((h, i) => ( + + ))} + + + + {mappings.map((m) => ( + startEdit(m)} onDelete={() => remove(m)} /> + ))} + +
{h}
+
+
+ ) : ( + + )} +
); - } + }; - function renderEditor() { - return el( - "div", - el( - "div.page-head", - el("div", el("h1.page-title", editor.id ? "Edit mapping" : "New mapping")), - el( - "div.page-actions", - el("button.btn", { type: "button", onclick: cancel }, "Cancel"), - el("button.btn.btn-primary", { type: "button", onclick: save }, "Save"), - ), - ), - editor.actionError ? el("div.mapping-error", editor.actionError) : null, - el( - "div.card.mapping-form", - el( - "label.mapping-form-row", - "Name", - el("input.mapping-input", { - value: editor.name, - oninput: (e) => { editor.name = e.target.value; }, - }), - ), - el( - "label.mapping-form-row", - "Source hint (organisational only)", - el("input.mapping-input", { - value: editor.sourceHint, - oninput: (e) => { editor.sourceHint = e.target.value; }, - }), - ), - el( - "label.mapping-form-row", - "Preview against captured event", - el( - "select.mapping-select", - { onchange: (e) => selectCapture(e.target.value) }, - el("option", { value: "" }, "— pick a captured event —"), - ...captures.map((c) => - el("option", { value: c.id, selected: String(editor.captureId) === String(c.id) }, - `${c.source || "(unknown)"} — ${c.received_at || ""}`), - ), - ), - ), - ), - el( - "div.card.mapping-fields", - el("div.mapping-section-title", "Bound fields"), - fieldsTable(editor.fields, { - preview: editor.preview, - onRemove: removeField, - onNameChange: renameField, - onTypeChange: retypeField, - onRequiredChange: requireField, - }), - el("button.btn", { type: "button", onclick: preview }, "Preview"), - ), - el( - "div.card.mapping-payload", - el("div.mapping-section-title", "Payload — click a value to bind it"), - editor.payloadError - ? el("div.mapping-error", editor.payloadError) - : editor.payload !== null - ? payloadTree(editor.payload, { onPick: addField }) - : el("div.mapping-empty-fields", "Pick a captured event above to see its payload."), - ), + const renderEditor = () => { + return ( +
+
+
+

{editor.id ? "Edit mapping" : "New mapping"}

+
+
+ + +
+
+ {editor.actionError &&
{editor.actionError}
} +
+ + + +
+
+
Bound fields
+ + +
+
+
Payload — click a value to bind it
+ {editor.payloadError ? ( +
{editor.payloadError}
+ ) : editor.payload !== null ? ( + + ) : ( +
Pick a captured event above to see its payload.
+ )} +
+
); - } + }; - return root; + return editor ? renderEditor() : renderList(); }