web: tabbed run detail with summary, IO fields and timeline (R3/R6/R7)
The browser run detail becomes a tab strip — Summary, Input, Output,
Timeline — over the selected tab's body, with the Graph tab key reserved
for the R5 item.
- Summary: run label, status chip + outcome, the run identity line, the
key/value rows (Pipeline, Stage, waiting-for-resource line, Workspace,
content hash, Started, Finished, live Duration, Retry of, Diagnostic)
and the collapsed run artifacts gallery.
- Input / Output: one collapsed section per recorded map entry, the value
as a monospace block; empty states match the app.
- Timeline: one row per visit with the stage-outcome glyph, `{stage} ·
visit {n}`, an outcome chip, a paperclip when artifacts were recorded,
the duration and the description; a row opens the per-visit stage pane.
- Stage pane: headline rows, the Verdict block with inline artifact links
and the Artifacts / Session / Output / Input / This run / Stage
definition sections, all closable with Escape.
All new logic is the pure, DOM-free src/runDetail.js ported from the
Android sources; app.js keeps only the wiring and every server string is
set with textContent.
PARITY.md: R3, R6 and R7 marked done with their captures.
This commit is contained in:
+479
-97
@@ -71,6 +71,28 @@ import {
|
||||
templateStageSummary,
|
||||
TEMPLATE_UNPARSED_SOURCE_NOTE,
|
||||
} from "./templates.js";
|
||||
import {
|
||||
RENDERED_RUN_TABS,
|
||||
EMPTY_INPUT_MESSAGE,
|
||||
EMPTY_OUTPUT_MESSAGE,
|
||||
EMPTY_TIMELINE_MESSAGE,
|
||||
NO_STAGE_DETAILS_MESSAGE,
|
||||
fieldSections,
|
||||
summaryRows,
|
||||
runIdentityLine,
|
||||
runLabelFor,
|
||||
runDurationText,
|
||||
runTimeline,
|
||||
nodeLabel,
|
||||
headlineFields,
|
||||
runStepFields,
|
||||
stageSectionSpecs,
|
||||
clampVisitIndex,
|
||||
referencedVerdictArtifacts,
|
||||
verdictReasonSegments,
|
||||
outcomeColorToken,
|
||||
stateGlyph,
|
||||
} from "./runDetail.js";
|
||||
|
||||
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
|
||||
|
||||
@@ -127,6 +149,14 @@ const state = {
|
||||
runFilters: defaultRunFilters(),
|
||||
runSort: DEFAULT_RUN_SORT,
|
||||
openMenu: null,
|
||||
// Run detail: the selected tab (Summary by default) and the per-run
|
||||
// expand/collapse choices for the input/output field sections and the summary
|
||||
// artifacts section. The stage pane is the timeline's per-visit panel; its
|
||||
// section expansion is reseeded each time a pane is opened.
|
||||
runTab: "summary",
|
||||
runSections: new Set(),
|
||||
runStagePane: null,
|
||||
runStageSections: new Set(),
|
||||
};
|
||||
|
||||
let runPoll = null;
|
||||
@@ -138,6 +168,12 @@ let runPoll = null;
|
||||
let listClock = null;
|
||||
let listNow = Date.now();
|
||||
|
||||
// The run detail's own live clock: it ticks only while the shown run is
|
||||
// executing, updating just the Duration row in place (never a full re-render, so
|
||||
// an open stage pane is not torn down), exactly as the runs list does.
|
||||
let detailClock = null;
|
||||
let detailNow = Date.now();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DOM helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -159,36 +195,6 @@ function h(tag, props = {}, ...children) {
|
||||
return node;
|
||||
}
|
||||
|
||||
function fmtSeconds(total) {
|
||||
const s = Math.max(0, Math.round(total));
|
||||
const hh = Math.floor(s / 3600);
|
||||
const mm = Math.floor((s % 3600) / 60);
|
||||
const ss = s % 60;
|
||||
if (hh > 0) return `${hh}h ${mm}m ${ss}s`;
|
||||
if (mm > 0) return `${mm}m ${ss}s`;
|
||||
return `${ss}s`;
|
||||
}
|
||||
|
||||
function fmtTime(iso) {
|
||||
if (!iso) return "—";
|
||||
const ms = Date.parse(iso);
|
||||
return Number.isNaN(ms) ? iso : new Date(ms).toLocaleString();
|
||||
}
|
||||
|
||||
function fmtDuration(startIso, finishIso) {
|
||||
if (!startIso) return "—";
|
||||
const start = Date.parse(startIso);
|
||||
if (Number.isNaN(start)) return "—";
|
||||
const end = finishIso ? Date.parse(finishIso) : Date.now();
|
||||
if (Number.isNaN(end)) return "—";
|
||||
// A future start (clock skew) reads as 0s, matching the Android client.
|
||||
return fmtSeconds(Math.max(0, (end - start) / 1000));
|
||||
}
|
||||
|
||||
function statusClass(status) {
|
||||
return `chip chip-${String(status || "unknown").toLowerCase()}`;
|
||||
}
|
||||
|
||||
function isExecuting(run) {
|
||||
return Boolean(run && run.executing);
|
||||
}
|
||||
@@ -273,8 +279,13 @@ function renderContent() {
|
||||
}
|
||||
nodes.push(split);
|
||||
content.replaceChildren(...nodes);
|
||||
if (state.view === "runs") refreshListClock();
|
||||
else stopListClock();
|
||||
if (state.view === "runs") {
|
||||
refreshListClock();
|
||||
refreshDetailClock();
|
||||
} else {
|
||||
stopListClock();
|
||||
stopDetailClock();
|
||||
}
|
||||
}
|
||||
|
||||
function tabButton(view, label) {
|
||||
@@ -1041,77 +1052,415 @@ function closeMenu() {
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* The run detail: a tab strip (Summary / Input / Output / Timeline) over the
|
||||
* selected tab's body, wired from the pure helpers in runDetail.js. Summary is
|
||||
* the default and carries the run's identity, key/value rows and diagnostic;
|
||||
* Input/Output are one collapsed section per recorded field; the Timeline is one
|
||||
* compact row per visit that opens the stage pane. Every server string is set
|
||||
* with textContent, never innerHTML.
|
||||
*/
|
||||
function renderRunDetail() {
|
||||
const d = state.runDetail;
|
||||
const pane = h("div", { class: "detail" });
|
||||
const pane = h("div", { class: "detail run-detail" });
|
||||
if (!d) {
|
||||
pane.append(h("div", { class: "muted pad", text: "Select a run." }));
|
||||
return pane;
|
||||
}
|
||||
pane.append(
|
||||
h(
|
||||
"h2",
|
||||
{},
|
||||
d.title || d.name || `run ${d.id}`,
|
||||
h("span", { class: statusClass(d.status), text: d.status || "unknown" }),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "kv" },
|
||||
kv("Run ID", `#${d.id}`),
|
||||
kv("Pipeline", `#${d.pipeline_id} @ v${d.version}`),
|
||||
kv("Outcome", d.outcome || "—"),
|
||||
kv("Current stage", d.current_stage || "—"),
|
||||
kv("Started", fmtTime(d.created_at)),
|
||||
kv("Duration", isExecuting(d) ? `${fmtDuration(d.created_at, "")} (running)` : fmtDuration(d.created_at, d.finished_at)),
|
||||
kv("Completed steps", String(d.completed_steps ?? 0)),
|
||||
d.diagnostic ? kv("Diagnostic", d.diagnostic) : null,
|
||||
{ class: "detail-tabs" },
|
||||
...RENDERED_RUN_TABS.map((tab) =>
|
||||
h("button", {
|
||||
class: `detail-tab${state.runTab === tab.key ? " active" : ""}`,
|
||||
text: tab.label,
|
||||
onclick: () => {
|
||||
state.runTab = tab.key;
|
||||
renderContent();
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const steps = d.steps ?? [];
|
||||
const executing = isExecuting(d);
|
||||
|
||||
// Run-level artifacts gallery (parity R8). The header is the run summary line
|
||||
// and the gallery below it draws one group per (stage, visit); all derivation
|
||||
// lives in artifacts.js so the count can never disagree with the tiles.
|
||||
pane.append(h("h3", { class: "artifacts-header", text: artifactsHeader(steps, executing) }));
|
||||
pane.append(renderArtifactGallery(steps));
|
||||
|
||||
pane.append(h("h3", { text: `Steps (${steps.length})` }));
|
||||
if (!steps.length) {
|
||||
pane.append(h("div", { class: "muted pad", text: "No steps recorded yet." }));
|
||||
return pane;
|
||||
if (state.runTab === "input") {
|
||||
pane.append(renderRunFieldTab(d.input, "input", EMPTY_INPUT_MESSAGE));
|
||||
} else if (state.runTab === "output") {
|
||||
pane.append(renderRunFieldTab(d.output, "output", EMPTY_OUTPUT_MESSAGE));
|
||||
} else if (state.runTab === "steps") {
|
||||
pane.append(renderRunTimelineTab(d));
|
||||
} else {
|
||||
pane.append(renderRunSummaryTab(d));
|
||||
}
|
||||
const list = h("div", { class: "steps" });
|
||||
for (const s of steps) {
|
||||
list.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "step" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "step-head" },
|
||||
h("code", { text: `${s.sequence}. ${s.stage}` }),
|
||||
h("span", { class: statusClass(s.status), text: s.status || "unknown" }),
|
||||
s.outcome ? h("span", { class: "chip", text: s.outcome }) : null,
|
||||
h("span", { class: "muted", text: fmtDuration(s.started_at, s.finished_at) }),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "kv tight" },
|
||||
kv("Target", s.target || "—"),
|
||||
kv("Visit", s.control ? `${s.control.visit}/${s.control.max_visits}` : "—"),
|
||||
kv("Session", s.session_id || "—"),
|
||||
s.diagnostic ? kv("Diagnostic", s.diagnostic) : null,
|
||||
),
|
||||
renderVisitArtifacts(s),
|
||||
renderSessionExport(s),
|
||||
if (state.runStagePane) pane.append(renderStagePane(d));
|
||||
return pane;
|
||||
}
|
||||
|
||||
/** The Summary tab: identity, chip row, key/value rows, diagnostic and gallery. */
|
||||
function renderRunSummaryTab(d) {
|
||||
const wrap = h("div", { class: "run-tab-body" });
|
||||
wrap.append(h("h2", { class: "run-detail-title", text: runLabelFor(d) }));
|
||||
const status = runStateOf(d.status);
|
||||
const chips = h("div", { class: "run-chip-row" });
|
||||
chips.append(h("span", { class: `chip chip-${status}`, text: d.status || status }));
|
||||
if (String(d.outcome ?? "").trim()) chips.append(h("span", { class: "muted", text: `outcome ${d.outcome}` }));
|
||||
if (d.executing) chips.append(h("span", { class: "muted", text: "executing" }));
|
||||
wrap.append(chips);
|
||||
wrap.append(h("div", { class: "run-identity muted", text: runIdentityLine(d) }));
|
||||
|
||||
const rows = h("div", { class: "kv" });
|
||||
for (const row of summaryRows(d, detailNow)) {
|
||||
if (row.kind === "wait") rows.append(h("div", { class: "run-wait", text: row.value }));
|
||||
else if (row.kind === "duration") rows.append(renderDurationRow(d, row));
|
||||
else if (row.kind === "block") rows.append(renderCodeBlock(row.key, row.value));
|
||||
else rows.append(renderKvRow(row));
|
||||
}
|
||||
wrap.append(rows);
|
||||
|
||||
// The run-level artifacts gallery (parity R8), collapsed by default like the
|
||||
// Android summary. Its header alone says what was captured until expanded.
|
||||
wrap.append(
|
||||
renderCollapsible("summary-artifacts", artifactsHeader(d.steps ?? [], isExecuting(d)), () =>
|
||||
renderArtifactGallery(d.steps ?? []),
|
||||
),
|
||||
);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** The Duration row, tagged so the detail clock can update it in place. */
|
||||
function renderDurationRow(d, row) {
|
||||
return h(
|
||||
"div",
|
||||
{ class: "kv-row" },
|
||||
h("span", { class: "kv-key", text: row.key }),
|
||||
h("span", { class: "kv-val run-duration", "data-run-id": String(d.id), text: row.value }),
|
||||
);
|
||||
}
|
||||
|
||||
/** One key/value row from a summary row model. */
|
||||
function renderKvRow(row) {
|
||||
return h(
|
||||
"div",
|
||||
{ class: "kv-row" },
|
||||
h("span", { class: "kv-key", text: row.key }),
|
||||
h("span", { class: `kv-val${row.monospace ? " monospace" : ""}`, text: row.value }),
|
||||
);
|
||||
}
|
||||
|
||||
/** A themed monospace block with a label header. */
|
||||
function renderCodeBlock(label, text) {
|
||||
return h(
|
||||
"div",
|
||||
{ class: "codeblock" },
|
||||
h("div", { class: "codeblock-label", text: label }),
|
||||
h("pre", { class: "codeblock-body", text }),
|
||||
);
|
||||
}
|
||||
|
||||
/** One stage-pane field as either the code card (blocks) or a key/value row. */
|
||||
function renderStageField(field) {
|
||||
if (field.block) return renderCodeBlock(field.label, field.value);
|
||||
return h(
|
||||
"div",
|
||||
{ class: "kv-row" },
|
||||
h("span", { class: "kv-key", text: field.label }),
|
||||
h("span", { class: `kv-val${field.mono ? " monospace" : ""}`, text: field.value }),
|
||||
);
|
||||
}
|
||||
|
||||
/** One collapsible input/output field section (expanded body is a code block). */
|
||||
function renderRunFieldTab(map, keyPrefix, emptyMessage) {
|
||||
const wrap = h("div", { class: "run-tab-body" });
|
||||
const sections = fieldSections(map, keyPrefix);
|
||||
if (!sections.length) {
|
||||
wrap.append(h("div", { class: "run-empty muted", text: emptyMessage }));
|
||||
return wrap;
|
||||
}
|
||||
for (const section of sections) {
|
||||
const key = `${keyPrefix}-${section.key}`;
|
||||
wrap.append(
|
||||
renderCollapsible(key, section.title, () =>
|
||||
h("pre", { class: "field-block" }, h("code", { text: section.value })),
|
||||
),
|
||||
);
|
||||
}
|
||||
pane.append(list);
|
||||
return pane;
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* One collapsible section of the run detail's field/summary body. Expanded state
|
||||
* is keyed in `state.runSections`, so the operator's choices survive a re-render.
|
||||
*/
|
||||
function renderCollapsible(key, title, bodyFn) {
|
||||
const expanded = state.runSections.has(key);
|
||||
const wrap = h("div", { class: "collapsible" });
|
||||
wrap.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "section-toggle",
|
||||
type: "button",
|
||||
"aria-expanded": expanded ? "true" : "false",
|
||||
onclick: () => {
|
||||
state.runSections = new Set(state.runSections);
|
||||
if (state.runSections.has(key)) state.runSections.delete(key);
|
||||
else state.runSections.add(key);
|
||||
renderContent();
|
||||
},
|
||||
},
|
||||
h("span", { class: "chevron", text: expanded ? "\u25be" : "\u25b8" }),
|
||||
h("span", { class: "section-title", text: title }),
|
||||
),
|
||||
);
|
||||
if (expanded) wrap.append(h("div", { class: "section-body" }, bodyFn()));
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** The Timeline tab: one compact row per visit, in step order. */
|
||||
function renderRunTimelineTab(d) {
|
||||
const wrap = h("div", { class: "run-tab-body" });
|
||||
const timeline = runTimeline(d.steps ?? []);
|
||||
if (!timeline.entries.length) {
|
||||
wrap.append(h("div", { class: "run-empty muted", text: EMPTY_TIMELINE_MESSAGE }));
|
||||
return wrap;
|
||||
}
|
||||
const list = h("div", { class: "timeline" });
|
||||
for (const entry of timeline.entries) list.append(renderTimelineRow(entry));
|
||||
wrap.append(list);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* One timeline row: a stage-outcome glyph, the `{stage} · visit {n}` line with
|
||||
* the outcome chip, a paperclip when the visit recorded artifacts, the duration,
|
||||
* and the one-line description. Clicking (or Enter/Space) opens the stage pane.
|
||||
*/
|
||||
function renderTimelineRow(entry) {
|
||||
const state_ = runStateOf(entry.outcomeLabel);
|
||||
const chipLabel = entry.outcomeLabel || state_.label;
|
||||
const tone = outcomeClass(entry.step.outcome, entry.step.status);
|
||||
const open = () => openStagePane(entry.stageKey, entry.visitIndex);
|
||||
const row = h("div", {
|
||||
class: "timeline-row",
|
||||
role: "button",
|
||||
tabindex: "0",
|
||||
"data-stage-key": entry.stageKey,
|
||||
"data-visit-index": String(entry.visitIndex),
|
||||
});
|
||||
row.addEventListener("click", open);
|
||||
row.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
open();
|
||||
}
|
||||
});
|
||||
row.append(h("span", { class: `timeline-glyph ${tone}`, text: stateGlyph(state_) }));
|
||||
const head = h("div", { class: "timeline-head" });
|
||||
head.append(h("span", { class: "timeline-title", text: `${entry.stageKey} · visit ${entry.visit}` }));
|
||||
head.append(h("span", { class: `outcome-chip ${tone}`, text: chipLabel }));
|
||||
if (entry.hasArtifacts) {
|
||||
head.append(
|
||||
h("span", { class: "timeline-paperclip", title: "Recorded artifacts", "aria-label": "has recorded artifacts", text: "\u{1F4CE}" }),
|
||||
);
|
||||
}
|
||||
if (entry.duration) head.append(h("span", { class: "timeline-duration muted", text: entry.duration }));
|
||||
const body = h("div", { class: "timeline-main" }, head);
|
||||
if (entry.description) body.append(h("span", { class: "timeline-desc muted", text: entry.description }));
|
||||
row.append(body);
|
||||
return row;
|
||||
}
|
||||
|
||||
/** A CSS class naming a stage-outcome colour (status palette, else flow). */
|
||||
function outcomeClass(outcome, status) {
|
||||
const [kind, value] = outcomeColorToken(outcome, status).split(" ");
|
||||
return `outcome-${kind}-${value}`;
|
||||
}
|
||||
|
||||
// --- Stage pane ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The stage pane: a closable dialog for one visit, opened from a timeline row.
|
||||
* It leads with the verdict block (when the server recorded one), then the
|
||||
* always-visible headline rows, then the visit's collapsible sections in the
|
||||
* Android order (Artifacts, Session, Output, Input, This run, Stage definition).
|
||||
* Escape, the Back button and a backdrop click close it.
|
||||
*/
|
||||
function renderStagePane(d) {
|
||||
const stageKey = state.runStagePane.stageKey;
|
||||
const timeline = runTimeline(d.steps ?? []);
|
||||
const runSteps = timeline.visitsByStage.get(stageKey) ?? [];
|
||||
const visitIndex = clampVisitIndex(state.runStagePane.visitIndex, runSteps.length);
|
||||
const step = runSteps[visitIndex] ?? null;
|
||||
const graph = d.graph ?? { stages: [] };
|
||||
const specs = stageSectionSpecs(stageKey, graph, runSteps, visitIndex, true);
|
||||
const fields = step ? runStepFields(step) : [];
|
||||
const headline = headlineFields(fields);
|
||||
|
||||
const overlay = h("div", {
|
||||
class: "stage-pane",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": nodeLabel(stageKey),
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) closeStagePane();
|
||||
});
|
||||
const bar = h(
|
||||
"div",
|
||||
{ class: "stage-pane-bar" },
|
||||
h("button", {
|
||||
class: "stage-pane-back",
|
||||
type: "button",
|
||||
"aria-label": "Back",
|
||||
text: "\u2190 Back",
|
||||
onclick: closeStagePane,
|
||||
}),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stage-pane-titles" },
|
||||
h("span", { class: "stage-pane-title", text: nodeLabel(stageKey) }),
|
||||
h("span", { class: "stage-pane-run muted", text: runLabelFor(d) }),
|
||||
),
|
||||
);
|
||||
|
||||
const body = h("div", { class: "stage-pane-body" });
|
||||
if (step) {
|
||||
const verdict = renderVerdictBlock(step);
|
||||
if (verdict) body.append(verdict);
|
||||
}
|
||||
for (const field of headline) body.append(renderStageField(field));
|
||||
if (headline.length === 0 && specs.length === 0) {
|
||||
body.append(h("div", { class: "run-empty muted", text: NO_STAGE_DETAILS_MESSAGE }));
|
||||
}
|
||||
for (const spec of specs) body.append(renderStageSection(spec, step));
|
||||
overlay.append(h("div", { class: "stage-pane-sheet" }, bar, body));
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** One stage-pane section, using the pane's own expansion state. */
|
||||
function renderStageSection(spec, step) {
|
||||
const expanded = state.runStageSections.has(spec.key);
|
||||
const wrap = h("div", { class: "collapsible stage-section" });
|
||||
wrap.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "section-toggle",
|
||||
type: "button",
|
||||
"aria-expanded": expanded ? "true" : "false",
|
||||
onclick: () => {
|
||||
state.runStageSections = new Set(state.runStageSections);
|
||||
if (state.runStageSections.has(spec.key)) state.runStageSections.delete(spec.key);
|
||||
else state.runStageSections.add(spec.key);
|
||||
renderContent();
|
||||
},
|
||||
},
|
||||
h("span", { class: "chevron", text: expanded ? "\u25be" : "\u25b8" }),
|
||||
h("span", { class: "section-title", text: spec.title }),
|
||||
),
|
||||
);
|
||||
if (!expanded) return wrap;
|
||||
const body = h("div", { class: "section-body" });
|
||||
if (spec.artifacts && step) body.append(renderVisitArtifacts(step));
|
||||
else if (spec.session && step) body.append(renderSessionExport(step));
|
||||
else for (const field of spec.fields) body.append(renderStageField(field));
|
||||
wrap.append(body);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The verdict block: heading "Verdict", the option as an outcome-coloured chip,
|
||||
* the reason as body text with inline artifact links, and the referenced
|
||||
* artifacts as compact chips. Nothing renders when the server recorded no
|
||||
* option and no reason.
|
||||
*/
|
||||
function renderVerdictBlock(step) {
|
||||
const verdict = step.verdict;
|
||||
if (!verdict) return null;
|
||||
const option = String(verdict.option ?? "");
|
||||
const reason = String(verdict.reason ?? "");
|
||||
if (option.trim() === "" && reason.trim() === "") return null;
|
||||
|
||||
const wrap = h("div", { class: "verdict" });
|
||||
const head = h("div", { class: "verdict-head" }, h("span", { class: "verdict-title", text: "Verdict" }));
|
||||
if (option.trim() !== "") {
|
||||
head.append(h("span", { class: `outcome-chip ${outcomeClass(step.outcome, step.status)}`, text: option }));
|
||||
}
|
||||
wrap.append(head);
|
||||
|
||||
const references = referencedVerdictArtifacts(verdict, presentedArtifacts(step));
|
||||
if (reason.trim() !== "") {
|
||||
const body = h("p", { class: "verdict-reason" });
|
||||
for (const segment of verdictReasonSegments(reason, references)) {
|
||||
if (!segment.artifact) body.append(document.createTextNode(segment.text));
|
||||
else body.append(renderVerdictLink(segment.text, segment.artifact, step));
|
||||
}
|
||||
wrap.append(body);
|
||||
}
|
||||
if (references.length) {
|
||||
const refs = h("div", { class: "verdict-refs" });
|
||||
for (const artifact of references) refs.append(renderVerdictRef(artifact, step));
|
||||
wrap.append(refs);
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** One inline artifact reference in a verdict reason (media opens the viewer). */
|
||||
function renderVerdictLink(text, artifact, step) {
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
if (!resolved) return h("span", { class: "verdict-link disabled", text });
|
||||
const link = h("a", { class: "verdict-link", href: resolved, target: "_blank", rel: "noreferrer", text });
|
||||
link.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
openArtifactFromVerdict(artifact, step, resolved);
|
||||
});
|
||||
return link;
|
||||
}
|
||||
|
||||
/** One compact chip naming a referenced artifact. */
|
||||
function renderVerdictRef(artifact, step) {
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
const chip = h("button", {
|
||||
class: "verdict-ref",
|
||||
type: "button",
|
||||
text: artifact.name || "(unnamed artifact)",
|
||||
});
|
||||
chip.addEventListener("click", () => openArtifactFromVerdict(artifact, step, resolved));
|
||||
return chip;
|
||||
}
|
||||
|
||||
/** Open a referenced artifact: media in the viewer, everything else externally. */
|
||||
function openArtifactFromVerdict(artifact, step, resolved) {
|
||||
if (!resolved) return;
|
||||
const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts: presentedArtifacts(step) };
|
||||
const viewable = pagedArtifacts([group]);
|
||||
const viewerIndexOf = viewerIndexByUrl([group]);
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
const kind = artifactKind(artifact.content_type, artifact.name);
|
||||
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
|
||||
if (media && at != null) openArtifactViewer(viewable, at);
|
||||
else window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
|
||||
/** Open the stage pane for one visit of a stage and move focus into it. */
|
||||
function openStagePane(stageKey, visitIndex) {
|
||||
state.runStagePane = { stageKey, visitIndex };
|
||||
state.runStageSections = new Set();
|
||||
renderContent();
|
||||
document.querySelector(".stage-pane-back")?.focus();
|
||||
}
|
||||
|
||||
/** Close the stage pane, returning focus to the timeline row that opened it. */
|
||||
function closeStagePane() {
|
||||
const closing = state.runStagePane;
|
||||
if (!closing) return;
|
||||
state.runStagePane = null;
|
||||
state.runStageSections = new Set();
|
||||
renderContent();
|
||||
const row = [...document.querySelectorAll(".timeline-row")].find(
|
||||
(node) => node.dataset.stageKey === closing.stageKey && node.dataset.visitIndex === String(closing.visitIndex),
|
||||
);
|
||||
row?.focus();
|
||||
}
|
||||
|
||||
/** Whether the configured server URL can resolve a server-relative artifact. */
|
||||
@@ -1441,15 +1790,6 @@ function openArtifactViewer(viewable, startIndex) {
|
||||
document.addEventListener("keydown", viewerKeydown);
|
||||
}
|
||||
|
||||
function kv(key, value) {
|
||||
return h(
|
||||
"div",
|
||||
{ class: "kv-row" },
|
||||
h("span", { class: "kv-key", text: key }),
|
||||
h("span", { class: "kv-val", text: value }),
|
||||
);
|
||||
}
|
||||
|
||||
/** A key/value row whose value is monospace (a key, an id) rather than prose. */
|
||||
function kvMono(key, value) {
|
||||
return h(
|
||||
@@ -1596,6 +1936,12 @@ async function selectRun(id, { silent = false } = {}) {
|
||||
state.selectedRunId = id;
|
||||
if (!silent) {
|
||||
state.runDetail = null;
|
||||
// A different run reseeds the detail: Summary tab, every section closed and
|
||||
// no stage pane left over from the run the operator navigated away from.
|
||||
state.runTab = "summary";
|
||||
state.runSections = new Set();
|
||||
state.runStagePane = null;
|
||||
state.runStageSections = new Set();
|
||||
renderContent();
|
||||
}
|
||||
try {
|
||||
@@ -1651,6 +1997,31 @@ function stopListClock() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* (Re)start the run detail's own clock: it ticks once a second only while the
|
||||
* shown run is executing, updating just the Duration row in place (never a full
|
||||
* re-render, so an open stage pane and its scroll are not torn down). The value
|
||||
* is derived from the server's start timestamp, so it survives a reconnect.
|
||||
*/
|
||||
function refreshDetailClock() {
|
||||
stopDetailClock();
|
||||
detailNow = Date.now();
|
||||
if (state.view === "runs" && isExecuting(state.runDetail)) {
|
||||
detailClock = setInterval(() => {
|
||||
detailNow = Date.now();
|
||||
const node = document.querySelector(".run-duration[data-run-id]");
|
||||
if (node && state.runDetail) node.textContent = runDurationText(state.runDetail, detailNow) ?? "";
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function stopDetailClock() {
|
||||
if (detailClock) {
|
||||
clearInterval(detailClock);
|
||||
detailClock = null;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Boot
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1666,9 +2037,20 @@ client.addEventListener("state", (event) => {
|
||||
if (next.kind !== "connected" && previousKind === "connected") {
|
||||
stopRunPoll();
|
||||
stopListClock();
|
||||
stopDetailClock();
|
||||
}
|
||||
render();
|
||||
});
|
||||
|
||||
// The stage pane is a modal dialog: Escape closes it (the artifact viewer, when
|
||||
// it is stacked above, owns Escape first). Registered once; it is a no-op when
|
||||
// no pane is open.
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape" && state.runStagePane && !document.querySelector(".artifact-viewer")) {
|
||||
event.preventDefault();
|
||||
closeStagePane();
|
||||
}
|
||||
});
|
||||
|
||||
// Prefill from a previous session only; the user still confirms with Connect.
|
||||
render();
|
||||
|
||||
Reference in New Issue
Block a user