Merge branch 'main' into web-chat-live

This commit is contained in:
2026-10-19 07:01:39 +01:00
9 changed files with 583 additions and 3 deletions
+213
View File
@@ -78,6 +78,15 @@ import {
runFiltersActiveCount,
} from "./runs.js";
import {
CREATE_ACTION_LABEL,
CREATE_NAME_LABEL,
CREATE_NOTE,
createConfirmLabel,
createDismissLabel,
createFormTitle,
createFormValid,
createSuccessMessage,
createdPipelineName,
effectiveStageType,
templateCard,
templateDetailName,
@@ -334,6 +343,16 @@ const state = {
templateGraphs: new Map(),
selectedTemplateKey: null,
templateTab: "summary",
// The create-from-template dialog (P5): whether it is open, the name being
// typed, whether a validate+submit is in flight, the server's refusal text and
// the created pipeline's name (null until a success, which is also what makes
// Cancel read Close and the field lock). The dialog validates the template's
// source first, then submits it create-only; nothing runs.
templateCreateOpen: false,
templateCreateName: "",
templateCreateSending: false,
templateCreateError: "",
templateCreateCreated: null,
loading: false,
error: "",
runFilters: defaultRunFilters(),
@@ -1318,6 +1337,7 @@ function renderTemplateDetail() {
return pane;
}
const graph = templateGraphFor(entry.key);
pane.append(renderTemplateDetailActions());
pane.append(
h(
"div",
@@ -1330,9 +1350,190 @@ function renderTemplateDetail() {
if (state.templateTab === "graph") pane.append(renderTemplateGraphTab(graph));
else if (state.templateTab === "source") pane.append(renderTemplateSourceTab(entry, graph));
else pane.append(renderTemplateSummaryTab(entry, graph));
if (state.templateCreateOpen) pane.append(renderTemplateCreateDialog(entry));
return pane;
}
/**
* The template detail's action row: the one "Create pipeline from this
* template" action (P5), matching the app's top-bar add action. It opens the
* dialog; it never submits on its own.
*/
function renderTemplateDetailActions() {
return h(
"div",
{ class: "detail-actions" },
h("button", {
class: "ghost template-create-open",
type: "button",
text: CREATE_ACTION_LABEL,
onclick: () => openTemplateCreateDialog(),
}),
);
}
/** Open the create dialog with a fresh, empty name; nothing is sent until Create. */
function openTemplateCreateDialog() {
state.templateCreateOpen = true;
state.templateCreateName = "";
state.templateCreateSending = false;
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
document.querySelector(".template-create-name")?.focus();
}
/** Dismiss the create dialog (never while a validate+submit is in flight). */
function closeTemplateCreateDialog() {
if (state.templateCreateSending) return;
state.templateCreateOpen = false;
state.templateCreateName = "";
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
}
/**
* The create dialog (P5): the title, the one required name field, the note, the
* server's refusal text or the success line, and Create/Cancel (Cancel reads
* Close after a success). Create is disabled while the name is blank or while
* sending; the field locks while sending and after a success. Every server
* string is set with textContent.
*/
function renderTemplateCreateDialog(entry) {
const title = createFormTitle(entry);
const overlay = h("div", {
class: "template-create-dialog",
role: "dialog",
"aria-modal": "true",
"aria-label": title,
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) closeTemplateCreateDialog();
});
const panel = h("div", { class: "template-create-panel" });
panel.append(h("h2", { class: "template-create-title", text: title }));
const field = h("label", { class: "template-create-field" });
field.append(h("span", { class: "template-create-label", text: CREATE_NAME_LABEL }));
field.append(
h("input", {
class: "template-create-name",
type: "text",
value: state.templateCreateName,
spellcheck: "false",
autocomplete: "off",
disabled: state.templateCreateSending || state.templateCreateCreated != null,
oninput: (event) => {
// Update in place (no re-render) so the field keeps focus and its caret;
// only the confirm button's enabled state depends on the name.
state.templateCreateName = event.target.value;
const confirm = overlay.querySelector(".template-create-confirm");
if (confirm) {
confirm.disabled = !createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
});
}
},
}),
);
panel.append(field);
panel.append(h("p", { class: "template-create-note muted", text: CREATE_NOTE }));
if (state.templateCreateError) {
panel.append(h("div", { class: "template-create-error bad", text: state.templateCreateError }));
}
if (state.templateCreateCreated != null) {
panel.append(
h("div", {
class: "template-create-success",
text: createSuccessMessage(state.templateCreateCreated),
}),
);
}
const actions = h("div", { class: "template-create-actions" });
actions.append(
h("button", {
class: "ghost template-create-cancel",
type: "button",
text: createDismissLabel(state.templateCreateCreated),
disabled: state.templateCreateSending,
onclick: closeTemplateCreateDialog,
}),
);
actions.append(
h("button", {
class: "template-create-confirm",
type: "button",
text: createConfirmLabel(state.templateCreateSending),
disabled: !createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
}),
onclick: () => createFromTemplate(entry),
}),
);
panel.append(actions);
overlay.append(panel);
return overlay;
}
/**
* The P5 submit flow, exactly the app's: validate the template's source first
* and, when the server refuses to parse it, show its own error in the dialog and
* send nothing; otherwise submit the source create-only with the chosen name. On
* success remember the created name, refresh the pipeline list so the new row is
* visible and leave the dialog open (Cancel now reads Close); on failure show
* the server's error without closing.
*/
async function createFromTemplate(entry) {
if (
!createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
})
) {
return;
}
const name = state.templateCreateName;
state.templateCreateSending = true;
state.templateCreateError = "";
renderContent();
try {
await repo.validate(entry.source);
} catch (error) {
state.templateCreateSending = false;
state.templateCreateError = describeError(error);
renderContent();
return;
}
try {
const detail = await repo.submit(name, entry.source);
state.templateCreateSending = false;
state.templateCreateCreated = createdPipelineName(detail, name);
await refreshPipelines();
} catch (error) {
state.templateCreateSending = false;
state.templateCreateError = describeError(error);
}
renderContent();
}
/**
* Refresh just the pipeline summaries after a create so the new row appears when
* the operator returns to the Pipelines list. A failed refresh keeps the created
* name and is surfaced through the banner rather than discarded.
*/
async function refreshPipelines() {
try {
state.pipelines = await repo.listPipelines();
state.pipelinesLoaded = true;
} catch (error) {
state.error = describeError(error);
}
}
function templateTabButton(tab, label) {
return h("button", {
class: `minitab${state.templateTab === tab ? " active" : ""}`,
@@ -4932,6 +5133,13 @@ async function validateTemplate(entry) {
function selectTemplate(key) {
state.selectedTemplateKey = key;
state.templateTab = "summary";
// A different template reseeds the create dialog, so a name typed for one
// template can never be submitted against another.
state.templateCreateOpen = false;
state.templateCreateName = "";
state.templateCreateSending = false;
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
}
@@ -5155,6 +5363,11 @@ document.addEventListener("keydown", (event) => {
return;
}
if (document.querySelector(".artifact-viewer") || document.querySelector(".change-viewer")) return;
if (state.templateCreateOpen) {
event.preventDefault();
closeTemplateCreateDialog();
return;
}
if (state.actionError) {
event.preventDefault();
dismissActionError();