Merge branch 'main' into web-runs-home
# Conflicts: # web/src/app.js # web/styles.css
This commit is contained in:
+209
-1
@@ -43,6 +43,16 @@ import {
|
||||
defaultRunFilters,
|
||||
runFiltersActiveCount,
|
||||
} from "./runs.js";
|
||||
import {
|
||||
effectiveStageType,
|
||||
templateCard,
|
||||
templateDetailName,
|
||||
templateGalleryName,
|
||||
templateGraphNote,
|
||||
templateStageCountLabel,
|
||||
templateStageSummary,
|
||||
TEMPLATE_UNPARSED_SOURCE_NOTE,
|
||||
} from "./templates.js";
|
||||
|
||||
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
|
||||
|
||||
@@ -92,6 +102,13 @@ const state = {
|
||||
versionsExpanded: false,
|
||||
pipelinesLoaded: false,
|
||||
runsLoaded: false,
|
||||
templates: [],
|
||||
templateLoading: false,
|
||||
// key -> graph|null: the parsed definition, cached once per template key. A
|
||||
// failed/absent validate stores null so the card/detail say "unavailable".
|
||||
templateGraphs: new Map(),
|
||||
selectedTemplateKey: null,
|
||||
templateTab: "summary",
|
||||
loading: false,
|
||||
error: "",
|
||||
runFilters: defaultRunFilters(),
|
||||
@@ -227,6 +244,7 @@ function renderContent() {
|
||||
{ class: "tabs" },
|
||||
tabButton("pipelines", `Pipelines (${state.pipelines.length})`),
|
||||
tabButton("runs", `Runs (${state.runs.length})`),
|
||||
tabButton("templates", "Templates"),
|
||||
h("span", { class: "spacer" }),
|
||||
h("button", { class: "ghost", text: "Refresh", onclick: () => loadCurrentView(true) }),
|
||||
),
|
||||
@@ -235,8 +253,10 @@ function renderContent() {
|
||||
const split = h("div", { class: "split" });
|
||||
if (state.view === "pipelines") {
|
||||
split.append(renderPipelineList(), renderPipelineDetail());
|
||||
} else {
|
||||
} else if (state.view === "runs") {
|
||||
split.append(renderRunList(), renderRunDetail());
|
||||
} else {
|
||||
split.append(renderTemplateGallery(), renderTemplateDetail());
|
||||
}
|
||||
nodes.push(split);
|
||||
content.replaceChildren(...nodes);
|
||||
@@ -254,6 +274,7 @@ function tabButton(view, label) {
|
||||
renderContent();
|
||||
if (view === "runs" && !state.runs.length) loadCurrentView();
|
||||
if (view === "pipelines" && !state.pipelines.length) loadCurrentView();
|
||||
if (view === "templates" && !state.templates.length) loadCurrentView();
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -573,6 +594,140 @@ function renderPipelineDetail() {
|
||||
return pane;
|
||||
}
|
||||
|
||||
// --- Templates -------------------------------------------------------------
|
||||
|
||||
/** The cached parsed graph for a template key, or null when it did not parse. */
|
||||
function templateGraphFor(key) {
|
||||
return state.templateGraphs.has(key) ? state.templateGraphs.get(key) : null;
|
||||
}
|
||||
|
||||
function renderTemplateGallery() {
|
||||
const pane = h("div", { class: "list gallery" });
|
||||
pane.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "pane-head" },
|
||||
h("h2", { text: "Templates" }),
|
||||
h("button", { class: "ghost", text: "Refresh templates", onclick: () => loadTemplates(true) }),
|
||||
),
|
||||
);
|
||||
if (state.templateLoading && !state.templates.length) {
|
||||
pane.append(h("div", { class: "muted pad", text: "Loading templates…" }));
|
||||
return pane;
|
||||
}
|
||||
if (!state.templates.length) {
|
||||
pane.append(h("div", { class: "muted pad", text: "No templates are available on this server." }));
|
||||
return pane;
|
||||
}
|
||||
const cards = h("div", { class: "cards" });
|
||||
for (const entry of state.templates) {
|
||||
const card = templateCard(entry, templateGraphFor(entry.key));
|
||||
cards.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: `card${state.selectedTemplateKey === entry.key ? " selected" : ""}`,
|
||||
onclick: () => selectTemplate(entry.key),
|
||||
},
|
||||
h("span", { class: "card-name", text: templateGalleryName(card.name) }),
|
||||
h("span", { class: "card-desc", text: card.description }),
|
||||
h("span", { class: "card-meta", text: templateStageCountLabel(card.stageCount) }),
|
||||
),
|
||||
);
|
||||
}
|
||||
pane.append(cards);
|
||||
return pane;
|
||||
}
|
||||
|
||||
function renderTemplateDetail() {
|
||||
const pane = h("div", { class: "detail" });
|
||||
const entry = state.templates.find((t) => t.key === state.selectedTemplateKey);
|
||||
if (!entry) {
|
||||
pane.append(h("div", { class: "muted pad", text: "Select a template." }));
|
||||
return pane;
|
||||
}
|
||||
const graph = templateGraphFor(entry.key);
|
||||
pane.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "tabstrip" },
|
||||
templateTabButton("summary", "Summary"),
|
||||
templateTabButton("graph", "Graph"),
|
||||
templateTabButton("source", "Source"),
|
||||
),
|
||||
);
|
||||
if (state.templateTab === "graph") pane.append(renderTemplateGraphTab(graph));
|
||||
else if (state.templateTab === "source") pane.append(renderTemplateSourceTab(entry, graph));
|
||||
else pane.append(renderTemplateSummaryTab(entry, graph));
|
||||
return pane;
|
||||
}
|
||||
|
||||
function templateTabButton(tab, label) {
|
||||
return h("button", {
|
||||
class: `minitab${state.templateTab === tab ? " active" : ""}`,
|
||||
text: label,
|
||||
onclick: () => {
|
||||
state.templateTab = tab;
|
||||
renderContent();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function renderTemplateSummaryTab(entry, graph) {
|
||||
const wrap = h("div", { class: "tabbody" });
|
||||
wrap.append(h("h2", { text: templateDetailName(entry) }));
|
||||
if ((entry.description ?? "").trim()) {
|
||||
wrap.append(h("p", { class: "body", text: entry.description }));
|
||||
}
|
||||
wrap.append(h("div", { class: "kv" }, kvMono("Key", entry.key)));
|
||||
wrap.append(
|
||||
h("div", { class: "meta-line", text: templateStageCountLabel(graph?.stages?.length ?? null) }),
|
||||
);
|
||||
if (entry.scheduled) wrap.append(h("div", { class: "meta-line", text: "Includes a schedule" }));
|
||||
|
||||
const summary = templateStageSummary(graph);
|
||||
if (summary.note) {
|
||||
wrap.append(h("div", { class: "muted pad", text: summary.note }));
|
||||
return wrap;
|
||||
}
|
||||
wrap.append(h("h3", { text: "Stages" }));
|
||||
const ul = h("ul", { class: "stages" });
|
||||
for (const stage of summary.stages) {
|
||||
ul.append(
|
||||
h(
|
||||
"li",
|
||||
{},
|
||||
h("code", { text: stage.key }),
|
||||
h("span", { class: "chip", text: effectiveStageType(stage.type) }),
|
||||
),
|
||||
);
|
||||
}
|
||||
wrap.append(ul);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function renderTemplateGraphTab(graph) {
|
||||
const wrap = h("div", { class: "tabbody" });
|
||||
wrap.append(h("p", { class: "muted", text: templateGraphNote(graph) }));
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function renderTemplateSourceTab(entry, graph) {
|
||||
const wrap = h("div", { class: "tabbody" });
|
||||
if (graph == null) {
|
||||
wrap.append(h("p", { class: "muted", text: TEMPLATE_UNPARSED_SOURCE_NOTE }));
|
||||
}
|
||||
wrap.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "codeblock" },
|
||||
h("div", { class: "codeblock-label", text: "Definition source" }),
|
||||
h("pre", { class: "codeblock-body", text: entry.source ?? "" }),
|
||||
),
|
||||
);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function pipelineSortLabel(key) {
|
||||
return (PIPELINE_SORTS.find((option) => option.key === key) ?? PIPELINE_SORTS[0]).label;
|
||||
}
|
||||
@@ -961,6 +1116,16 @@ function kv(key, value) {
|
||||
);
|
||||
}
|
||||
|
||||
/** A key/value row whose value is monospace (a key, an id) rather than prose. */
|
||||
function kvMono(key, value) {
|
||||
return h(
|
||||
"div",
|
||||
{ class: "kv-row" },
|
||||
h("span", { class: "kv-key", text: key }),
|
||||
h("span", { class: "kv-val" }, h("code", { text: value })),
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Actions
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1005,6 +1170,10 @@ async function loadCurrentView(force = false) {
|
||||
renderContent();
|
||||
return;
|
||||
}
|
||||
if (state.view === "templates") {
|
||||
await loadTemplates(force);
|
||||
return;
|
||||
}
|
||||
state.loading = true;
|
||||
state.error = "";
|
||||
renderContent();
|
||||
@@ -1036,6 +1205,45 @@ async function loadCurrentView(force = false) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the template catalogue, then validates each template's source once and
|
||||
* caches the parsed graph (null when it did not parse) so a card's stage count
|
||||
* and the detail's stage list read the same result and can never disagree.
|
||||
*/
|
||||
async function loadTemplates(force = false) {
|
||||
state.templateLoading = true;
|
||||
state.error = "";
|
||||
renderContent();
|
||||
try {
|
||||
state.templates = await repo.listTemplates();
|
||||
for (const entry of state.templates) {
|
||||
if (force || !state.templateGraphs.has(entry.key)) {
|
||||
state.templateGraphs.set(entry.key, await validateTemplate(entry));
|
||||
}
|
||||
}
|
||||
state.templateLoading = false;
|
||||
renderContent();
|
||||
} catch (err) {
|
||||
state.templateLoading = false;
|
||||
setError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/** The parsed graph for a template, or null when the server cannot parse its source. */
|
||||
async function validateTemplate(entry) {
|
||||
try {
|
||||
return await repo.validate(entry.source);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function selectTemplate(key) {
|
||||
state.selectedTemplateKey = key;
|
||||
state.templateTab = "summary";
|
||||
renderContent();
|
||||
}
|
||||
|
||||
async function selectPipeline(summary) {
|
||||
state.selectedPipelineId = summary.id;
|
||||
state.pipelineDetail = null;
|
||||
|
||||
@@ -11,6 +11,11 @@ export const Protocol = Object.freeze({
|
||||
GET_PIPELINE: "get_pipeline",
|
||||
PIPELINE: "pipeline",
|
||||
|
||||
LIST_TEMPLATES: "list_templates",
|
||||
TEMPLATES: "templates",
|
||||
VALIDATE: "validate",
|
||||
VALIDATED: "validated",
|
||||
|
||||
LIST_RUNS: "list_runs",
|
||||
RUNS: "runs",
|
||||
GET_RUN: "get_run",
|
||||
|
||||
@@ -43,6 +43,20 @@ export class PipelinesRepository {
|
||||
return response.detail;
|
||||
}
|
||||
|
||||
async listTemplates() {
|
||||
return (await this.#client.call({ type: Protocol.LIST_TEMPLATES })).templates ?? [];
|
||||
}
|
||||
|
||||
async validate(source) {
|
||||
const response = await this.#client.call({ type: Protocol.VALIDATE, source });
|
||||
// A server error envelope already rejects inside client.call, so a reply
|
||||
// here is `validated`; a missing graph is still an unusable definition.
|
||||
if (!response.graph) {
|
||||
throw new ProtocolError("The server returned no graph.");
|
||||
}
|
||||
return response.graph;
|
||||
}
|
||||
|
||||
async listRuns() {
|
||||
const response = await this.#client.call({ type: Protocol.LIST_RUNS });
|
||||
return { runs: response.runs ?? [], usage: response.usage ?? null };
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// Pure Templates derivations, mirroring the Android app's ui/Templates.kt,
|
||||
// ui/Format.kt and ui/graph/StageDetailPane.kt. No DOM and no protocol here, so
|
||||
// the gallery/detail wording and the stage-count mapping are unit-tested without
|
||||
// a browser. Every value returned is plain text (or plain data); the caller sets
|
||||
// it with textContent and never with innerHTML.
|
||||
|
||||
/** A gallery card's name: a blank name is the explicit unnamed-template placeholder. */
|
||||
export function templateGalleryName(name) {
|
||||
return (name ?? "").trim() ? name : "(unnamed template)";
|
||||
}
|
||||
|
||||
/** A detail's heading: a blank name falls back to the template's key. */
|
||||
export function templateDetailName(entry) {
|
||||
const name = (entry?.name ?? "").trim();
|
||||
return name ? entry.name : (entry?.key ?? "");
|
||||
}
|
||||
|
||||
/** "1 stage" / "N stages", mirroring ui/Format.kt stageCountText. */
|
||||
export function stageCountText(count) {
|
||||
return `${count} ${count === 1 ? "stage" : "stages"}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The card's stage-count line: the count parsed from the source, or an explicit
|
||||
* "unavailable" when the source could not be parsed (never "0 stages", which
|
||||
* would claim a count the client does not have).
|
||||
*/
|
||||
export function templateStageCountLabel(stageCount) {
|
||||
return stageCount == null ? "stage count unavailable" : stageCountText(stageCount);
|
||||
}
|
||||
|
||||
/** The effective stage type, mirroring internal/stage.EffectiveType: blank is the model stage. */
|
||||
export function effectiveStageType(type) {
|
||||
return (type ?? "").trim() ? type : "model";
|
||||
}
|
||||
|
||||
/**
|
||||
* One gallery card's content: the template's name and description (from the
|
||||
* catalogue) and its stage count (from the graph the server parsed out of the
|
||||
* source; null when the source did not parse, so the card says so rather than
|
||||
* claiming zero stages).
|
||||
*/
|
||||
export function templateCard(entry, graph = null) {
|
||||
return {
|
||||
key: entry?.key ?? "",
|
||||
name: entry?.name ?? "",
|
||||
description: entry?.description ?? "",
|
||||
stageCount: graph?.stages?.length ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
/** The unparsed-source note the Summary tab shows instead of a stage list. */
|
||||
export const TEMPLATE_UNPARSED_SUMMARY_NOTE =
|
||||
"This template's source could not be parsed, so its stages are not listed. See the Source tab for the raw definition.";
|
||||
|
||||
/** The note the Summary tab shows for a parsed template that declares no stages. */
|
||||
export const TEMPLATE_NO_STAGES_NOTE = "This template has no stages.";
|
||||
|
||||
/** The Graph tab's note when the source did not parse. */
|
||||
export const TEMPLATE_UNPARSED_GRAPH_NOTE =
|
||||
"This template's source could not be parsed, so there is no graph. The Source tab shows the raw definition.";
|
||||
|
||||
/** The Graph tab's note when the source parsed; the graph is the parsed definition. */
|
||||
export const TEMPLATE_GRAPH_NOTE =
|
||||
"Pinch to zoom and drag to pan. The graph is the parsed definition; nothing runs.";
|
||||
|
||||
/** The Source tab's note when the source did not parse on the server. */
|
||||
export const TEMPLATE_UNPARSED_SOURCE_NOTE =
|
||||
"This source could not be parsed on the server; showing the raw definition.";
|
||||
|
||||
/**
|
||||
* The Summary tab's stage section: an explicit [note] and no stages when the
|
||||
* source did not parse or parsed to nothing, else the stage rows (key + effective
|
||||
* type). One derivation, so the note and the list can never disagree.
|
||||
*/
|
||||
export function templateStageSummary(graph) {
|
||||
if (graph == null) {
|
||||
return { note: TEMPLATE_UNPARSED_SUMMARY_NOTE, stages: [] };
|
||||
}
|
||||
const stages = graph.stages ?? [];
|
||||
if (!stages.length) {
|
||||
return { note: TEMPLATE_NO_STAGES_NOTE, stages: [] };
|
||||
}
|
||||
return {
|
||||
note: null,
|
||||
stages: stages.map((stage) => ({ key: stage.key, type: effectiveStageType(stage.type) })),
|
||||
};
|
||||
}
|
||||
|
||||
/** The Graph tab's note: the unparsed note when there is no graph, else the parsed-definition note. */
|
||||
export function templateGraphNote(graph) {
|
||||
return graph == null ? TEMPLATE_UNPARSED_GRAPH_NOTE : TEMPLATE_GRAPH_NOTE;
|
||||
}
|
||||
Reference in New Issue
Block a user