web: run detail Graph tab with executed styling and stage panes (R5)
Add the run detail's Graph tab (between Summary and Input), reusing the shared src/graph.js renderer (P6) rather than a second renderer. In run mode a visited stage is executed (solid fill + border), an unvisited one hollow with a dashed muted border; a terminal is executed only when a visit resolved to it; a route is executed only when a recorded visit produced that outcome (solid with an arrowhead, success first, error last, others alphabetical, `error*` for the fallback). The Executed / Not executed legend shows only for a run. While the run executes the current stage carries a pulsing halo (static under prefers-reduced-motion) and a ticking elapsed badge; a finished run shows neither. Clicking a stage opens the existing visit pane at that stage's latest visit, and Back/Escape return focus. The empty state is the exact "This server did not include the run graph." extend src/graph.js with the run-mode inputs (runState-driven executed styling, legend, active halo/elapsed badge); keep app.js to wiring. Extend graph.test.mjs with focused run-mode unit tests and ui-smoke.mjs with the run 438 / run 440 / live-run captures. Mark R5 done in web/PARITY.md. Checks: node --check on every touched file; cd web && node --test test/ (178 pass, 0 fail); cd web && node test/ui-smoke.mjs --out captures (UI SMOKE PASS, captures 28-31).
This commit is contained in:
+112
-9
@@ -26,6 +26,7 @@
|
||||
|
||||
import { Protocol, isTerminal, resolveTarget } from "./protocol.js";
|
||||
import { effectiveStageType } from "./templates.js";
|
||||
import { formatDuration, secondsSince } from "./runs.js";
|
||||
|
||||
// Re-exported so a caller (and the unit tests) can reach the shared "blank is
|
||||
// the model stage" rule from the graph module it belongs to without a second
|
||||
@@ -61,6 +62,19 @@ const DRAG_THRESHOLD = 4;
|
||||
/** The run tab's empty state when the server omitted the run graph (R5). */
|
||||
export const RUN_GRAPH_MISSING = "This server did not include the run graph.";
|
||||
|
||||
/**
|
||||
* The run tab's guidance note: the browser adaptation of RunGraphTab's own
|
||||
* sentence, so the app's pinch/tap become mouse wheel/click while everything
|
||||
* else (the live pulse, the settled finish, the executed/not-executed shapes)
|
||||
* stays verbatim.
|
||||
*/
|
||||
export const RUN_GRAPH_NOTE =
|
||||
"The running stage pulses with its elapsed time and executed routes flow; " +
|
||||
"a finished run settles, and with animations off the running stage stays marked. " +
|
||||
"Solid means executed, dashed and outlined not executed; executed success and " +
|
||||
"failure routes are drawn thickest. Mouse wheel to zoom, drag to pan, " +
|
||||
"click a stage for details.";
|
||||
|
||||
/**
|
||||
* The pipeline detail's empty state when the parsed definition declares no
|
||||
* stages. The template gallery has its own Android-authored analogue
|
||||
@@ -203,6 +217,18 @@ export function edgeIsExecuted(edge, runState) {
|
||||
return inSet(runState.takenRoutes, edge) || inSet(runState.takenRoutes, edge.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The key of the stage a run is executing right now, else null. Only a live run
|
||||
* (still `executing`) has an active stage, so a finished run never carries a
|
||||
* halo or an elapsed badge. Pure: drawing, the elapsed badge and the tests share
|
||||
* one definition of "active".
|
||||
*/
|
||||
export function activeStage(runState) {
|
||||
if (runState == null || !runState.executing) return null;
|
||||
const key = runState.currentStage;
|
||||
return key == null || key === "" ? null : key;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Pure viewport maths (WorkflowGraph.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -895,19 +921,38 @@ function pathFromPoints(points) {
|
||||
* space does nothing.
|
||||
*
|
||||
* Options:
|
||||
* runState — omitted for the definition view (every route executed);
|
||||
* R5 passes `{ visitedStages, takenRoutes }` to dash the
|
||||
* routes a run did not take.
|
||||
* runState — omitted for the definition view (every route executed and
|
||||
* no legend); R5 passes the `runGraphState(run)` shape
|
||||
* ({ visitedStages, takenRoutes, currentStage, executing,
|
||||
* currentStageStartedAt }) to render the run: executed nodes
|
||||
* solid, unvisited ones hollow/dashed, executed routes
|
||||
* arrowed, the live stage's halo + elapsed badge and the
|
||||
* Executed / Not executed legend.
|
||||
* animationsEnabled — honour the caller's animation gate. Defaults to the
|
||||
* page's `prefers-reduced-motion` setting; when false the
|
||||
* active stage keeps a static ring instead of pulsing.
|
||||
* expanded — start with the taller panel.
|
||||
* onStageTap — called with the node key on a node click.
|
||||
* onStageTap — called with the node key on a node click. When supplied
|
||||
* (the run tab), the click opens the caller's own stage
|
||||
* pane and no definition pane is drawn.
|
||||
* onExpandedChange — called with the new expanded flag on toggle.
|
||||
* metrics — layout metrics override (tests).
|
||||
*
|
||||
* Returns `{ unmount }`; call it before discarding the container so the wheel,
|
||||
* pointer and resize listeners never leak.
|
||||
* pointer, resize and elapsed-timer handles never leak.
|
||||
*/
|
||||
export function mount(container, graph, options = {}) {
|
||||
const runState = options.runState ?? null;
|
||||
const activeKey = activeStage(runState);
|
||||
const reducedMotion =
|
||||
typeof window !== "undefined" &&
|
||||
typeof window.matchMedia === "function" &&
|
||||
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
// The caller may force animations off; otherwise the page's motion preference
|
||||
// decides. A finished run never animates regardless (activeKey is null then).
|
||||
const animationsEnabled =
|
||||
options.animationsEnabled === undefined ? !reducedMotion : Boolean(options.animationsEnabled);
|
||||
const pulse = activeKey != null && animationsEnabled;
|
||||
const layout = layoutGraph(graph, options.metrics);
|
||||
const stagesByKey = new Map((graph?.stages ?? []).map((stage) => [stage.key, stage]));
|
||||
|
||||
@@ -983,6 +1028,7 @@ export function mount(container, graph, options = {}) {
|
||||
|
||||
// Node layer: real buttons, positioned in graph space.
|
||||
const nodeLayer = el("div", "graph-node-layer");
|
||||
let elapsedBadge = null;
|
||||
for (const node of layout.nodes) {
|
||||
const kind = graphNodeKind(node.terminal, node.key, stagesByKey.get(node.key)?.type);
|
||||
const button = el("button", `graph-node ${nodeKindClass(kind)}`, node.label);
|
||||
@@ -998,13 +1044,25 @@ export function mount(container, graph, options = {}) {
|
||||
? `${node.label}, open details`
|
||||
: `Stage ${node.key}, ${node.type}, open details`,
|
||||
);
|
||||
if (!stageIsExecuted(node.key, runState)) button.classList.add("not-executed");
|
||||
const executed = stageIsExecuted(node.key, runState);
|
||||
if (runState != null) button.classList.add(executed ? "executed" : "not-executed");
|
||||
if (node.key === activeKey) {
|
||||
button.classList.add("active");
|
||||
if (pulse) button.classList.add("pulsing");
|
||||
const badge = el("span", "graph-elapsed");
|
||||
badge.setAttribute("aria-hidden", "true");
|
||||
button.append(badge);
|
||||
elapsedBadge = badge;
|
||||
}
|
||||
button.addEventListener("click", (event) => {
|
||||
if (dragged) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
selectNode(node.key);
|
||||
// The run tab owns its own stage pane (the shared timeline visit pane), so
|
||||
// a supplied handler replaces the definition pane rather than stacking on it.
|
||||
if (typeof options.onStageTap === "function") options.onStageTap(node.key);
|
||||
else selectNode(node.key);
|
||||
});
|
||||
nodeLayer.append(button);
|
||||
}
|
||||
@@ -1026,7 +1084,27 @@ export function mount(container, graph, options = {}) {
|
||||
controls.append(fitButton, expandButton);
|
||||
viewport.append(controls);
|
||||
|
||||
// The definition pane, hidden until a node is clicked.
|
||||
// The legend, only under a run (never the definition-only view): a solid,
|
||||
// arrowed swatch means "executed", a dashed, arrowless one "not executed",
|
||||
// matching what the graph draws.
|
||||
if (runState != null) {
|
||||
const legend = el("div", "graph-legend");
|
||||
legend.setAttribute("role", "note");
|
||||
legend.setAttribute("aria-label", "Executed and not executed routes");
|
||||
for (const entry of [
|
||||
{ label: "Executed", executed: true },
|
||||
{ label: "Not executed", executed: false },
|
||||
]) {
|
||||
const item = el("span", "graph-legend-entry");
|
||||
item.append(el("span", `graph-legend-swatch ${entry.executed ? "executed" : "not-executed"}`));
|
||||
item.append(el("span", "graph-legend-label", entry.label));
|
||||
legend.append(item);
|
||||
}
|
||||
viewport.append(legend);
|
||||
}
|
||||
|
||||
// The definition pane, hidden until a node is clicked (definition view only;
|
||||
// the run tab opens its own pane through onStageTap instead).
|
||||
const pane = el("div", "graph-pane");
|
||||
pane.hidden = true;
|
||||
root.append(viewport, pane);
|
||||
@@ -1122,7 +1200,28 @@ export function mount(container, graph, options = {}) {
|
||||
|
||||
pane.replaceChildren(...children);
|
||||
pane.hidden = false;
|
||||
if (typeof options.onStageTap === "function") options.onStageTap(key);
|
||||
}
|
||||
|
||||
// --- Elapsed badge (live run only) ---------------------------------------
|
||||
|
||||
function updateElapsed() {
|
||||
if (!elapsedBadge) return;
|
||||
const seconds = secondsSince(runState?.currentStageStartedAt, Date.now());
|
||||
elapsedBadge.textContent = seconds == null ? "" : formatDuration(seconds);
|
||||
}
|
||||
|
||||
let elapsedTimer = null;
|
||||
if (elapsedBadge != null) {
|
||||
updateElapsed();
|
||||
// Tick only while the graph has a live stage with a known start; a still
|
||||
// ring (reduced motion) and a finished run never wake up once a second.
|
||||
if (
|
||||
pulse &&
|
||||
typeof setInterval === "function" &&
|
||||
String(runState?.currentStageStartedAt ?? "").trim() !== ""
|
||||
) {
|
||||
elapsedTimer = setInterval(updateElapsed, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Interactions --------------------------------------------------------
|
||||
@@ -1230,6 +1329,10 @@ export function mount(container, graph, options = {}) {
|
||||
|
||||
return {
|
||||
unmount() {
|
||||
if (elapsedTimer != null) {
|
||||
clearInterval(elapsedTimer);
|
||||
elapsedTimer = null;
|
||||
}
|
||||
resizeObserver?.disconnect();
|
||||
viewport.removeEventListener("pointerdown", onPointerDown);
|
||||
viewport.removeEventListener("pointermove", onPointerMove);
|
||||
|
||||
Reference in New Issue
Block a user