web: create a pipeline from a template — validate then submit (P5)

A template detail now offers "Create pipeline from this template". Its
dialog ("Create from {name}", one required field "New pipeline name
(required)", the note that it creates a draft and does not run, Create /
Cancel with Cancel reading Close after a success) validates the
template's source first and, only when it parses, submits it create-only
with the trimmed name. Create is disabled while the name is blank or
while sending; the field locks while sending and after a success. A
refusal shows the server's own error in the still-open dialog; a success
shows `Created "{name}". It is in the Pipelines list.` and refreshes
list_pipelines so the new row is visible.

Pure helpers + both request shapes are unit-tested; the flow is captured
against a scratch server with its own throwaway database. The live
server's pipeline list is never touched: the default ui-smoke run sends
no submit and create runs only under its --scratch flag. Wording matches
android/.../TemplateDetailScreen.kt and PipelinesRepository.kt.
This commit is contained in:
2026-10-19 06:06:05 +01:00
parent f48e53d5c8
commit b55de770fe
9 changed files with 583 additions and 3 deletions
+65
View File
@@ -91,3 +91,68 @@ export function templateStageSummary(graph) {
export function templateGraphNote(graph) {
return graph == null ? TEMPLATE_UNPARSED_GRAPH_NOTE : TEMPLATE_GRAPH_NOTE;
}
// --- Create a pipeline from this template (P5) -----------------------------
// The wording, verbatim from android/.../TemplateDetailScreen.kt's
// CreateFromTemplateDialog. The dialog validates the template's source first,
// then submits it create-only; nothing runs and an existing name is never
// overwritten.
/** The template-detail action that opens the create dialog. */
export const CREATE_ACTION_LABEL = "Create pipeline from this template";
/** The dialog's single required field label. */
export const CREATE_NAME_LABEL = "New pipeline name (required)";
/** The dialog's explanatory note (verbatim; states that nothing runs). */
export const CREATE_NOTE =
"Creates a new draft pipeline on the server from this template's source; it is not run.";
/** The confirm button's idle label. */
export const CREATE_CONFIRM = "Create";
/** The confirm button's in-flight label. */
export const CREATE_SENDING = "Creating…";
/** The dismiss button's label before a success. */
export const CREATE_CANCEL = "Cancel";
/** The dismiss button's label after a success. */
export const CREATE_CLOSE = "Close";
/** The dialog's title: `Create from {name}`, a blank name falling back to the key. */
export function createFormTitle(entry) {
return `Create from ${templateDetailName(entry)}`;
}
/**
* Whether the dialog can submit: not while sending, not once a pipeline has
* been created, and never with a blank (or whitespace-only) name.
*/
export function createFormValid(name, { sending = false, created = null } = {}) {
return !sending && created == null && String(name ?? "").trim() !== "";
}
/** The confirm button's label: "Creating…" while in flight, else "Create". */
export function createConfirmLabel(sending) {
return sending ? CREATE_SENDING : CREATE_CONFIRM;
}
/** The dismiss button's label: "Close" once a pipeline was created, else "Cancel". */
export function createDismissLabel(created) {
return created != null ? CREATE_CLOSE : CREATE_CANCEL;
}
/** The dialog's success line: `Created "{name}". It is in the Pipelines list.` */
export function createSuccessMessage(created) {
return `Created "${created}". It is in the Pipelines list.`;
}
/**
* The name to report after a successful submit: the created pipeline's own name
* when the server returned one, else the name the operator submitted (trimmed),
* mirroring `created = it.name.ifBlank { name.trim() }`.
*/
export function createdPipelineName(detail, submittedName) {
return String(detail?.name ?? "").trim() || String(submittedName ?? "").trim();
}