feat(dashboard): render task actions, statuses and filters from the server catalog
Three surfaces stopped keeping hand-synced copies of the lifecycle vocabulary, so a status or action added on the backend shows up without a frontend change: - task actions render label/variant/confirm from taskstate.ActionCatalog via actionFor(); unknown actions no longer vanish behind a hardcoded switch and a new action needs no frontend case - status labels and pill severities come from taskstate.Statuses via statusLabel()/statusKind(); the local copy and the dom.js switch are gone - the status filter vocabulary and the "needs you" grouping derive from statusIds()/attentionStatusIds(); a new status appears in the filter and in the settings page's Work lifecycle card, driven by /api/task-meta Regenerated ui/dist so the embedded binary ships the new dashboard.
This commit is contained in:
1 parent
23e0895ea2
commit
cf06cd6a08
8 files changed
+332
-120
No files matched your search
+4
-21
@@ -52,27 +52,10 @@ export function pill(text, kind = "idle") {
|
||||
return el(`span.pill.pill-${kind}`, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map an archie task status onto a pill kind. Centralised so "merged" is the
|
||||
* same green everywhere it appears.
|
||||
*/
|
||||
export function statusKind(status) {
|
||||
switch (status) {
|
||||
case "running":
|
||||
return "info";
|
||||
case "merged":
|
||||
case "pr_open":
|
||||
return "ok";
|
||||
case "parked":
|
||||
case "waiting_human":
|
||||
return "warn";
|
||||
case "dead":
|
||||
case "rejected":
|
||||
return "danger";
|
||||
default:
|
||||
return "idle";
|
||||
}
|
||||
}
|
||||
// Re-exported from task-meta.js so the pill severity vocabulary has a single
|
||||
// source (the server catalog). Importers that pull statusKind from dom.js --
|
||||
// e.g. dashboard.js -- keep working, and the hardcoded switch is gone.
|
||||
export { statusKind } from "./task-meta.js";
|
||||
|
||||
/** Humanised relative time: "2 min ago". Raw timestamps make people do maths. */
|
||||
export function ago(value) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import "./settings.css";
|
||||
import { api } from "../base/api.js";
|
||||
import { el, empty, mount, pill } from "../base/dom.js";
|
||||
import { statusKind, statusLabel } from "../base/task-meta.js";
|
||||
import { row } from "./config-row.js";
|
||||
import { updateStatusCard } from "./update-status.js";
|
||||
|
||||
@@ -25,10 +26,12 @@ export function settingsPage() {
|
||||
const root = el("div.cfg-page");
|
||||
const body = el("div");
|
||||
const versionSlot = el("div");
|
||||
const lifecycleSlot = el("div");
|
||||
|
||||
render();
|
||||
load();
|
||||
loadVersionStatus();
|
||||
loadLifecycle();
|
||||
|
||||
function render() {
|
||||
mount(
|
||||
@@ -40,9 +43,10 @@ export function settingsPage() {
|
||||
el("h1.page-title", "Configuration"),
|
||||
el("p.page-sub", "What archied is actually running with right now."),
|
||||
),
|
||||
el("div.page-actions", el("button.btn", { onclick: () => { load(); loadVersionStatus(); } }, "Refresh")),
|
||||
el("div.page-actions", el("button.btn", { onclick: () => { load(); loadVersionStatus(); loadLifecycle(); } }, "Refresh")),
|
||||
),
|
||||
versionSlot,
|
||||
lifecycleSlot,
|
||||
body,
|
||||
);
|
||||
}
|
||||
@@ -72,6 +76,24 @@ export function settingsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLifecycle() {
|
||||
try {
|
||||
const data = await api.taskMeta();
|
||||
mount(lifecycleSlot, lifecycleCard(data));
|
||||
} catch (err) {
|
||||
// The lifecycle vocabulary is optional metadata; if archied does not
|
||||
// answer, show a quiet placeholder rather than a loud failure.
|
||||
mount(
|
||||
lifecycleSlot,
|
||||
section(
|
||||
"Work lifecycle",
|
||||
"The task statuses and operator actions archied ships.",
|
||||
empty("Lifecycle unavailable", String(err.message || err)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function renderBody(cfg, reload) {
|
||||
if (!cfg || Object.keys(cfg).length === 0) {
|
||||
mount(
|
||||
@@ -127,6 +149,54 @@ function section(title, sub, ...children) {
|
||||
);
|
||||
}
|
||||
|
||||
// Work lifecycle: the vocabulary archied ships as a server catalog. Both the
|
||||
// statuses (label + pill severity) and the operator actions (label + button
|
||||
// variant) are rendered from the /api/task-meta payload, so a status or action
|
||||
// added on the backend appears here on the next load with no frontend change.
|
||||
// statusLabel/statusKind are used as fallbacks for an entry that arrives
|
||||
// without its own label/kind so the card degrades gracefully.
|
||||
function lifecycleCard(data) {
|
||||
const statuses = data?.statuses || [];
|
||||
const actions = data?.actions || [];
|
||||
|
||||
const statusList = statuses.length
|
||||
? el("div.kv-list", ...statuses.map((s) => statusLifecycleRow(s)))
|
||||
: empty("No statuses reported", "The server did not return any lifecycle statuses.");
|
||||
|
||||
const actionList = actions.length
|
||||
? el("div.kv-list", ...actions.map((a) => actionLifecycleRow(a)))
|
||||
: empty("No actions reported", "The server did not return any operator actions.");
|
||||
|
||||
return section(
|
||||
"Work lifecycle",
|
||||
"The task statuses and operator actions archied ships. Add one on the backend and it appears here without a frontend change.",
|
||||
el("h3.cfg-subhead", "Statuses"),
|
||||
statusList,
|
||||
el("h3.cfg-subhead", "Actions"),
|
||||
actionList,
|
||||
);
|
||||
}
|
||||
|
||||
function statusLifecycleRow(s) {
|
||||
const label = s.label ?? statusLabel(s.id);
|
||||
const kind = s.kind ?? statusKind(s.id);
|
||||
return el("div.kv", el("span.kv-label", s.id), el("span.kv-value", pill(label, kind)));
|
||||
}
|
||||
|
||||
function actionLifecycleRow(a) {
|
||||
const label = a.label ?? a.id;
|
||||
const cls = roleButtonClass(a.kind);
|
||||
const spec = cls ? `button.btn.btn-small.${cls}` : "button.btn.btn-small";
|
||||
return el("div.kv", el("span.kv-label", a.id), el("span.kv-value", el(spec, { type: "button", disabled: true }, label)));
|
||||
}
|
||||
|
||||
// The button variant token for an action kind, matching the tasks board's
|
||||
// mapping: quiet/danger get their own tokens, everything else (primary, link)
|
||||
// falls back to the default .btn styling. A new kind never needs a new case.
|
||||
function roleButtonClass(kind) {
|
||||
return kind === "quiet" ? "btn-quiet" : kind === "danger" ? "btn-danger" : "";
|
||||
}
|
||||
|
||||
function identityCard(identity, ctx) {
|
||||
if (!identity) return section("Identity", "Who Archie is on the forge.", empty("Not available"));
|
||||
return section(
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
const ATTENTION_STATUSES = new Set(["waiting_human", "parked"]);
|
||||
const TASK_STATUSES = new Set([
|
||||
"needs_you",
|
||||
"queued",
|
||||
"running",
|
||||
"waiting_human",
|
||||
"pr_open",
|
||||
"merged",
|
||||
"parked",
|
||||
"dead",
|
||||
"rejected",
|
||||
"closed_wont_do",
|
||||
]);
|
||||
import { attentionStatusIds, statusIds } from "../base/task-meta.js";
|
||||
|
||||
// The vocabulary is the server catalog, not a hand-synced copy: the "needs
|
||||
// you" grouping and the set of known statuses come straight from task-meta so
|
||||
// a status added on the backend shows up here without a frontend change.
|
||||
// "needs_you" is a UI pseudo-status (work waiting on a human), so it is
|
||||
// prepended rather than stored in the catalog.
|
||||
const ATTENTION_STATUSES = attentionStatusIds();
|
||||
const TASK_STATUSES = new Set(["needs_you", ...statusIds()]);
|
||||
|
||||
export function initialTaskFilter(params) {
|
||||
const requested = params?.get?.("status") || "";
|
||||
|
||||
+27
-72
@@ -1,30 +1,11 @@
|
||||
import "./tasks.css";
|
||||
import { api } from "../base/api.js";
|
||||
import { ago, el, empty, mount, pill, statusKind } from "../base/dom.js";
|
||||
import { ago, el, empty, mount, pill } from "../base/dom.js";
|
||||
import { statTile } from "../base/statTile.js";
|
||||
import { taskRowA11y } from "./task-row.js";
|
||||
import { initialTaskFilter, taskMatchesStatus } from "./task-filters.js";
|
||||
import { describeTimelineEvent } from "./timeline-event.js";
|
||||
|
||||
/**
|
||||
* Plain-language status labels. One place, so "waiting_human" only ever
|
||||
* reads as "Waiting for you" wherever a task list is shown.
|
||||
*/
|
||||
const STATUS_LABELS = {
|
||||
queued: "Queued",
|
||||
running: "Working",
|
||||
waiting_human: "Waiting for you",
|
||||
pr_open: "In review",
|
||||
merged: "Merged",
|
||||
parked: "Parked",
|
||||
dead: "Stopped (too many retries)",
|
||||
rejected: "Rejected",
|
||||
closed_wont_do: "Won't do",
|
||||
};
|
||||
|
||||
function statusLabel(status) {
|
||||
return STATUS_LABELS[status] || status || "Unknown";
|
||||
}
|
||||
import { actionFor, statusIds, statusKind, statusLabel } from "../base/task-meta.js";
|
||||
|
||||
/**
|
||||
* The work board: every task archied knows about, filterable by status and
|
||||
@@ -67,8 +48,8 @@ export function tasksPage(params = new URLSearchParams()) {
|
||||
},
|
||||
el("option", { value: "" }, "All statuses"),
|
||||
el("option", { value: "needs_you", selected: filterStatus === "needs_you" }, "Needs you"),
|
||||
...Object.entries(STATUS_LABELS).map(([value, label]) =>
|
||||
el("option", { value, selected: filterStatus === value }, label)),
|
||||
...statusIds().map((value) =>
|
||||
el("option", { value, selected: filterStatus === value }, statusLabel(value))),
|
||||
);
|
||||
|
||||
render();
|
||||
@@ -288,55 +269,29 @@ export function tasksPage(params = new URLSearchParams()) {
|
||||
label,
|
||||
);
|
||||
|
||||
const controls = (t.actions || []).map((action) => {
|
||||
switch (action) {
|
||||
case "cancel":
|
||||
return button(
|
||||
"button.btn.btn-small.btn-quiet",
|
||||
action,
|
||||
"Cancel",
|
||||
`Cancel "${t.title || "this task"}"? This closes the forge issue.`,
|
||||
);
|
||||
case "stop":
|
||||
return button(
|
||||
"button.btn.btn-small",
|
||||
action,
|
||||
"Stop",
|
||||
`Stop "${t.title || "this task"}"? Recoverable work will remain parked.`,
|
||||
);
|
||||
case "approve":
|
||||
return button("button.btn.btn-small", action, "Approve");
|
||||
case "reject":
|
||||
return button(
|
||||
"button.btn.btn-small.btn-quiet",
|
||||
action,
|
||||
"Reject",
|
||||
`Reject "${t.title || "this task"}"? This closes the forge issue.`,
|
||||
);
|
||||
case "retry":
|
||||
return button("button.btn.btn-small", action, "Retry");
|
||||
case "abandon":
|
||||
return button(
|
||||
"button.btn.btn-small.btn-quiet",
|
||||
action,
|
||||
"Abandon",
|
||||
`Abandon "${t.title || "this task"}"? This closes the forge issue.`,
|
||||
);
|
||||
case "archive":
|
||||
return button(
|
||||
"button.btn.btn-small.btn-quiet",
|
||||
action,
|
||||
"Archive",
|
||||
`Archive the local record for "${t.title || "this task"}"?`,
|
||||
);
|
||||
case "open_pr":
|
||||
return taskLink(t, "pull_request", t.pr_number, "Open PR");
|
||||
case "open_issue":
|
||||
return taskLink(t, "issue", t.issue_number, "Open issue");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
});
|
||||
// Everything is derived from the server catalog: an action added on the
|
||||
// backend renders here the moment task-meta ships it, no frontend redeploy
|
||||
// needed. label, variant and confirm text all come from actionFor(action);
|
||||
// a new variant kind just needs a token below, not a new case.
|
||||
const variantToken = (kind) =>
|
||||
kind === "quiet" ? "btn-quiet" : kind === "danger" ? "btn-danger" : "";
|
||||
|
||||
const controls = (t.actions || [])
|
||||
.map((action) => {
|
||||
const meta = actionFor(action);
|
||||
if (!meta) return null; // unknown id -> render nothing for this entry
|
||||
const title = t.title || "this task";
|
||||
const confirmText = meta.confirm ? meta.confirm.replaceAll("{title}", title) : undefined;
|
||||
const cls = ["button", "btn", "btn-small", variantToken(meta.kind)].filter(Boolean).join(".");
|
||||
if (meta.kind === "link") {
|
||||
// Only the forge links have a destination to navigate to; the label
|
||||
// comes from the catalog rather than a hardcoded "Open PR".
|
||||
if (action === "open_pr") return taskLink(t, "pull_request", t.pr_number, meta.label);
|
||||
if (action === "open_issue") return taskLink(t, "issue", t.issue_number, meta.label);
|
||||
}
|
||||
return button(cls, action, meta.label, confirmText);
|
||||
})
|
||||
.filter(Boolean);
|
||||
if (!controls.length && !error) return "—";
|
||||
return el("div.task-actions", error, controls);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user