b00b434c5d
- Gaps between stages are sized from the widest straight-route label, so a chip never reaches into either box; a source's forward routes fan across its side instead of sharing a 20px band. - A label prefers the widest horizontal run that can hold it; when only a stub exists the chip moves onto the edge's longest run and sits beside a vertical one, keeping clear of both the box and the neighbouring label. - Hovering a wire or its chip highlights the route and dims the rest. - System-added routes (the parser's implicit error fallback) draw dotted with a legend entry, distinct from declared routes and executed state. - Lanes are 34px apart, so a dense definition no longer doubles the canvas height. - The graph opens expanded by default and remembers a collapse (graphPrefs.js).
393 lines
12 KiB
JavaScript
393 lines
12 KiB
JavaScript
// The Pipelines destination: the filterable/sortable list, the pipeline detail
|
|
// (Summary / Graph / Source) and the list refresh used after a template create.
|
|
// The pure models live in pipelines.js and graph.js; this module owns the DOM.
|
|
|
|
import { h } from "../dom.js";
|
|
import { describeError } from "../format.js";
|
|
import {
|
|
PIPELINE_SORTS,
|
|
PIPELINE_DETAIL_TABS,
|
|
RUN_PRESENCES,
|
|
RUN_STATUS_FILTERS,
|
|
EMPTY_PIPELINE_FILTERS,
|
|
filterPipelines,
|
|
graphNote,
|
|
latestRunByPipeline,
|
|
pipelineFilterCount,
|
|
pipelineListEmptyState,
|
|
pipelineSubtitle,
|
|
pipelineUpdatedLine,
|
|
runBadge,
|
|
runBadgeMetaLine,
|
|
sortPipelines,
|
|
summaryFields,
|
|
versionRow,
|
|
} from "../pipelines.js";
|
|
import { PIPELINE_GRAPH_EMPTY, mount as mountGraph } from "../graph.js";
|
|
import { writeGraphExpanded } from "../graphPrefs.js";
|
|
|
|
export function createPipelinesView(rt) {
|
|
const { state, repo } = rt;
|
|
const renderContent = (...args) => rt.renderContent(...args);
|
|
const selectPipeline = (...args) => rt.selectPipeline(...args);
|
|
const pushRoute = (...args) => rt.pushRoute(...args);
|
|
|
|
|
|
function renderPipelineList() {
|
|
const list = h("div", { class: "list" });
|
|
list.append(renderPipelineControls());
|
|
const rows = h("div", { id: "pipelineRows", class: "list-scroll" });
|
|
fillPipelineRows(rows);
|
|
list.append(rows);
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* The list's filter + sort toolbar and (when open) the matching menu panel. The
|
|
* rows themselves live in the separate `#pipelineRows` container so a keystroke
|
|
* in the name filter can refresh just the rows without rebuilding (and so
|
|
* blurring) the input the operator is typing in.
|
|
*/
|
|
function renderPipelineControls() {
|
|
const filters = state.pipelineFilters;
|
|
const count = pipelineFilterCount(filters);
|
|
const panel = state.pipelineMenu;
|
|
const controls = h(
|
|
"div",
|
|
{ class: "list-controls" },
|
|
h(
|
|
"div",
|
|
{ class: "list-toolbar" },
|
|
h(
|
|
"button",
|
|
{
|
|
id: "filterToggle",
|
|
class: `control${panel === "filter" ? " active" : ""}`,
|
|
onclick: () => {
|
|
state.pipelineMenu = panel === "filter" ? null : "filter";
|
|
renderContent();
|
|
},
|
|
},
|
|
h("span", { text: "Filter" }),
|
|
h("span", { id: "filterCount", class: "count", text: count ? ` (${count})` : "" }),
|
|
),
|
|
h("button", {
|
|
id: "sortToggle",
|
|
class: `control${panel === "sort" ? " active" : ""}`,
|
|
text: `Sort: ${pipelineSortLabel(state.pipelineSort)}`,
|
|
onclick: () => {
|
|
state.pipelineMenu = panel === "sort" ? null : "sort";
|
|
renderContent();
|
|
},
|
|
}),
|
|
h("button", {
|
|
id: "clearFilters",
|
|
class: "ghost clear",
|
|
text: "Clear filters",
|
|
hidden: count === 0,
|
|
onclick: clearPipelineFilters,
|
|
}),
|
|
),
|
|
);
|
|
if (panel === "filter") controls.append(renderFilterPanel());
|
|
if (panel === "sort") controls.append(renderSortPanel());
|
|
return controls;
|
|
}
|
|
|
|
function renderFilterPanel() {
|
|
const filters = state.pipelineFilters;
|
|
const panel = h("div", { class: "menu-panel filter-panel" });
|
|
panel.append(h("div", { class: "filter-section", text: "Name" }));
|
|
panel.append(
|
|
h(
|
|
"label",
|
|
{ class: "filter-field" },
|
|
h("span", { class: "filter-field-label", text: "Pipeline name contains" }),
|
|
h("input", {
|
|
id: "pipelineNameFilter",
|
|
type: "text",
|
|
value: filters.name,
|
|
spellcheck: "false",
|
|
oninput: (e) => {
|
|
state.pipelineFilters = { ...state.pipelineFilters, name: e.target.value };
|
|
// Targeted refresh: the input keeps focus and its value while the
|
|
// list narrows behind it.
|
|
refreshPipelineRows();
|
|
},
|
|
}),
|
|
),
|
|
);
|
|
panel.append(h("div", { class: "filter-section", text: "Runs" }));
|
|
for (const presence of RUN_PRESENCES) {
|
|
panel.append(
|
|
h(
|
|
"label",
|
|
{ class: "filter-item" },
|
|
h("input", {
|
|
type: "radio",
|
|
name: "runPresence",
|
|
checked: filters.presence === presence.key,
|
|
onchange: () => {
|
|
state.pipelineFilters = { ...state.pipelineFilters, presence: presence.key };
|
|
renderContent();
|
|
},
|
|
}),
|
|
h("span", { text: presence.label }),
|
|
),
|
|
);
|
|
}
|
|
panel.append(h("div", { class: "filter-section", text: "Last run status" }));
|
|
for (const status of RUN_STATUS_FILTERS) {
|
|
panel.append(
|
|
h(
|
|
"label",
|
|
{ class: "filter-item" },
|
|
h("input", {
|
|
id: `status-${status}`,
|
|
type: "checkbox",
|
|
checked: filters.lastRunStatuses.includes(status),
|
|
onchange: (e) => {
|
|
const next = e.target.checked
|
|
? [...state.pipelineFilters.lastRunStatuses, status]
|
|
: state.pipelineFilters.lastRunStatuses.filter((s) => s !== status);
|
|
state.pipelineFilters = { ...state.pipelineFilters, lastRunStatuses: next };
|
|
renderContent();
|
|
},
|
|
}),
|
|
h("span", { text: status }),
|
|
),
|
|
);
|
|
}
|
|
panel.append(
|
|
h("div", { class: "filter-actions" }, h("button", { class: "ghost", text: "Clear filters", onclick: clearPipelineFilters })),
|
|
);
|
|
return panel;
|
|
}
|
|
|
|
function renderSortPanel() {
|
|
const panel = h("div", { class: "menu-panel sort-panel" });
|
|
for (const option of PIPELINE_SORTS) {
|
|
panel.append(
|
|
h("button", {
|
|
class: `sort-option${state.pipelineSort === option.key ? " active" : ""}`,
|
|
text: option.label,
|
|
onclick: () => {
|
|
state.pipelineSort = option.key;
|
|
state.pipelineMenu = null;
|
|
renderContent();
|
|
},
|
|
}),
|
|
);
|
|
}
|
|
panel.append(
|
|
h(
|
|
"div",
|
|
{ class: "filter-actions" },
|
|
h("button", {
|
|
class: "ghost",
|
|
text: "Reset",
|
|
onclick: () => {
|
|
state.pipelineSort = "server_order";
|
|
state.pipelineMenu = null;
|
|
renderContent();
|
|
},
|
|
}),
|
|
),
|
|
);
|
|
return panel;
|
|
}
|
|
|
|
/** Re-renders the rows and the toolbar's active-filter badge after a filter change. */
|
|
function refreshPipelineRows() {
|
|
const rows = document.getElementById("pipelineRows");
|
|
if (rows) fillPipelineRows(rows);
|
|
const count = pipelineFilterCount(state.pipelineFilters);
|
|
const badge = document.getElementById("filterCount");
|
|
if (badge) badge.textContent = count ? ` (${count})` : "";
|
|
const clear = document.getElementById("clearFilters");
|
|
if (clear) clear.hidden = count === 0;
|
|
}
|
|
|
|
/** Sorts, filters and renders the pipeline rows (or the matching empty state) into `rowsEl`. */
|
|
function fillPipelineRows(rowsEl) {
|
|
const latestRuns = latestRunByPipeline(state.runs);
|
|
const runsKnown = state.runsLoaded;
|
|
const now = Date.now();
|
|
const nodes = [];
|
|
if (state.loading && !state.pipelines.length) {
|
|
nodes.push(h("div", { class: "muted pad", text: "Loading pipelines…" }));
|
|
} else if (!state.pipelinesLoaded) {
|
|
nodes.push(h("div", { class: "muted pad", text: "Connect to the server to load pipelines." }));
|
|
} else {
|
|
const sorted = sortPipelines(state.pipelines, state.pipelineSort, latestRuns);
|
|
const items = filterPipelines(sorted, state.pipelineFilters, latestRuns, runsKnown);
|
|
if (items.length) {
|
|
for (const pipeline of items) nodes.push(renderPipelineRow(pipeline, latestRuns, runsKnown, now));
|
|
} else {
|
|
const empty = pipelineListEmptyState(state.pipelines, items, state.pipelineFilters);
|
|
const box = h("div", { class: "empty pad" }, h("div", { class: "muted", text: empty.message }));
|
|
if (empty.clearAction) {
|
|
box.append(h("button", { class: "ghost", text: empty.clearAction, onclick: clearPipelineFilters }));
|
|
}
|
|
nodes.push(box);
|
|
}
|
|
}
|
|
rowsEl.replaceChildren(...nodes);
|
|
}
|
|
|
|
function renderPipelineRow(pipeline, latestRuns, runsKnown, now) {
|
|
const children = [
|
|
h("span", { class: "row-title", text: pipeline.name || `pipeline ${pipeline.id}` }),
|
|
h("span", { class: "row-meta", text: pipelineSubtitle(pipeline) }),
|
|
];
|
|
const updated = pipelineUpdatedLine(pipeline);
|
|
if (updated) children.push(h("span", { class: "row-meta", text: updated }));
|
|
if (runsKnown) {
|
|
const run = latestRuns.get(pipeline.id);
|
|
if (!run) {
|
|
children.push(h("span", { class: "row-meta muted", text: "no runs recorded" }));
|
|
} else {
|
|
const badge = runBadge(run, now);
|
|
children.push(
|
|
h(
|
|
"span",
|
|
{ class: "row-run" },
|
|
h("span", { class: `chip chip-${badge.state}`, text: badge.state }),
|
|
h("span", { class: "row-meta", text: runBadgeMetaLine(badge) }),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
return h(
|
|
"button",
|
|
{
|
|
class: `row${state.selectedPipelineId === pipeline.id ? " selected" : ""}`,
|
|
"data-pipeline-id": String(pipeline.id),
|
|
onclick: () => selectPipeline(pipeline),
|
|
},
|
|
...children,
|
|
);
|
|
}
|
|
|
|
function renderPipelineDetail() {
|
|
const d = state.pipelineDetail;
|
|
const pane = h("div", { class: "detail" });
|
|
if (!d) {
|
|
pane.append(h("div", { class: "muted pad", text: "Select a pipeline." }));
|
|
return pane;
|
|
}
|
|
pane.append(h("h1", { class: "detail-title", id: "detailTitle", tabindex: "-1", text: d.name || `pipeline ${d.id}` }));
|
|
if (state.pipelineTab === "graph") {
|
|
pane.append(h("p", { class: "graph-note muted", text: graphNote() }));
|
|
const stages = d.graph?.stages ?? [];
|
|
if (!stages.length) {
|
|
pane.append(h("div", { class: "muted pad", text: PIPELINE_GRAPH_EMPTY }));
|
|
return pane;
|
|
}
|
|
const host = h("div", { class: "graph-host" });
|
|
pane.append(host);
|
|
state.pipelineGraph = mountGraph(host, d.graph, {
|
|
expanded: state.pipelineGraphExpanded,
|
|
selectedKey: state.pipelineGraphSelection,
|
|
onSelectionChange: (key) => {
|
|
// The graph has already opened or closed its own definition pane; record
|
|
// the destination in the URL without rebuilding the graph.
|
|
state.pipelineGraphSelection = key;
|
|
const id = state.selectedPipelineId;
|
|
if (!id) return;
|
|
const version = state.pipelineRequestedVersion ?? 0;
|
|
pushRoute(
|
|
key
|
|
? { kind: "pipelineStage", id, version, stageKey: key }
|
|
: { kind: "pipeline", id, version },
|
|
);
|
|
},
|
|
onExpandedChange: (value) => {
|
|
state.pipelineGraphExpanded = value;
|
|
writeGraphExpanded(value);
|
|
},
|
|
});
|
|
return pane;
|
|
}
|
|
if (state.pipelineTab === "source") {
|
|
pane.append(h("pre", { class: "source-code" }, h("code", { text: d.source || "" })));
|
|
return pane;
|
|
}
|
|
pane.append(h("div", { class: "detail-subtitle muted", text: pipelineSubtitle({ ...d, stages: d.graph?.stages?.length ?? d.stages }) }));
|
|
const rows = h("div", { class: "kv" });
|
|
for (const field of summaryFields(d)) {
|
|
rows.append(
|
|
h(
|
|
"div",
|
|
{ class: "kv-row" },
|
|
h("span", { class: "kv-key", text: field.key }),
|
|
h("span", { class: `kv-val${field.monospace ? " monospace" : ""}`, text: field.value }),
|
|
),
|
|
);
|
|
}
|
|
pane.append(rows);
|
|
pane.append(
|
|
h(
|
|
"button",
|
|
{
|
|
class: "section-toggle",
|
|
onclick: () => {
|
|
state.versionsExpanded = !state.versionsExpanded;
|
|
renderContent();
|
|
},
|
|
},
|
|
h("span", { class: "chevron", text: state.versionsExpanded ? "\u25be" : "\u25b8" }),
|
|
h("span", { text: "Versions" }),
|
|
),
|
|
);
|
|
if (state.versionsExpanded) {
|
|
const versions = d.versions ?? [];
|
|
const body = h("div", { class: "section-body versions-list" });
|
|
if (!versions.length) {
|
|
body.append(h("div", { class: "muted", text: "No versions recorded." }));
|
|
} else {
|
|
for (const version of versions) {
|
|
const row = versionRow(version);
|
|
body.append(
|
|
h(
|
|
"div",
|
|
{ class: "version-row" },
|
|
h("span", { class: "version-title", text: row.versionLabel }),
|
|
h("span", { class: "muted", text: row.stagesText }),
|
|
row.createdText ? h("span", { class: "muted", text: row.createdText }) : null,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
pane.append(body);
|
|
}
|
|
return pane;
|
|
}
|
|
|
|
async function refreshPipelines() {
|
|
try {
|
|
state.pipelines = await repo.listPipelines();
|
|
state.pipelinesLoaded = true;
|
|
} catch (error) {
|
|
state.error = describeError(error);
|
|
}
|
|
}
|
|
|
|
function pipelineSortLabel(key) {
|
|
return (PIPELINE_SORTS.find((option) => option.key === key) ?? PIPELINE_SORTS[0]).label;
|
|
}
|
|
|
|
function clearPipelineFilters() {
|
|
state.pipelineFilters = { ...EMPTY_PIPELINE_FILTERS };
|
|
renderContent();
|
|
}
|
|
|
|
return {
|
|
renderPipelineList,
|
|
renderPipelineDetail,
|
|
fillPipelineRows,
|
|
clearPipelineFilters,
|
|
refreshPipelines,
|
|
};
|
|
}
|