Files
archie/ui/src/bindings/binding-editor.jsx
T
sam a64d72ddbe refactor(ui): extract Pill to ui/src/base/, closing archie-core-mlro
Pill was independently duplicated byte-for-byte across 11 files
(tasks, logs, mapping-editor, capture-row, settings, update-status,
skills, dashboard, memory, channels, curators) plus the bindings page
built earlier this session -- a violation of organisation.md's
"extract on the second distinct consumer" rule, predating this
session entirely. Found while building the bindings UI.

Mechanical extraction only, no behavior change: ui/src/base/pill.jsx
is now the single definition; every call site imports from there.
skills.jsx's copy used `class=` instead of `className=` (functionally
identical in Preact) -- normalized to the shared version's className.
captures.jsx's import of Pill (previously re-exported through
capture-row.jsx) now points at the shared module directly.

Verified via task test:ui (120/120 unchanged) and, since this touches
the exact rendering path that had a real app-wide regression earlier
tonight (commit 8f9f2d6), re-verified in a real browser across all 12
pages: zero "[object Object]" occurrences, and every page's .pill
elements render with real content (settings: 9, bindings: 2, etc.),
not just "the build succeeded."
2026-09-03 06:25:21 +10:00

47 lines
1.5 KiB
React

import { h } from "preact";
import { Pill } from "../base/pill.jsx";
/**
* Pure rendering logic for the bindings editor, split out from
* bindings.jsx so it is unit-testable without the page's fetch wiring,
* mirroring mappings/mapping-editor.jsx.
*/
const STATUS_LABELS = {
draft: "draft",
pending_approval: "pending approval",
armed: "armed",
};
const STATUS_KINDS = {
draft: "idle",
pending_approval: "warn",
armed: "ok",
};
/** Renders a binding's Status as a labeled pill -- draft/pending_approval/armed. */
export function StatusPill({ status }) {
return <Pill text={STATUS_LABELS[status] || status} kind={STATUS_KINDS[status] || "idle"} />;
}
/** One saved binding's summary row for the bindings list. */
export function BindingRow({ binding: b, onEdit, onApprove, onDelete }) {
const repoPin = b.owner && b.repo ? `${b.owner}/${b.repo}` : "—";
return (
<tr>
<td>{b.name}</td>
<td className="mono">{b.matcher?.source || "—"}</td>
<td>{b.workflow}</td>
<td className="mono">{repoPin}</td>
<td><StatusPill status={b.status} /></td>
<td>
<button className="btn btn-small" type="button" onClick={() => onEdit?.(b)}>Edit</button>
{b.status === "pending_approval" && (
<button className="btn btn-small btn-primary" type="button" onClick={() => onApprove?.(b)}>Approve</button>
)}
<button className="btn btn-small" type="button" onClick={() => onDelete?.(b)}>Delete</button>
</td>
</tr>
);
}