diff --git a/ui/src/workflows/WorkflowEditor.vue b/ui/src/workflows/WorkflowEditor.vue index 19bc9f193..9b4336b41 100644 --- a/ui/src/workflows/WorkflowEditor.vue +++ b/ui/src/workflows/WorkflowEditor.vue @@ -193,7 +193,10 @@ const seenDraft = ref(); const draftConflict = ref(false); // The published version the open document was edited from. const loadedVersion = ref(0); +// Set once the workflow is deleted, so nothing writes its draft back. +let removed = false; function load(value: string): void { + removed = false; const entry = collection.value.definitions.find( (candidate) => candidate.id === value, ); @@ -211,6 +214,7 @@ watch(selected, load, { immediate: true }); // The collection arrives after the first render; a later live update must not // overwrite what is being typed, so it only refreshes an editor with no local edits. watch([collection, () => workflows.drafts], () => { + if (removed) return; const incoming = workflows.drafts.find((draft) => draft.id === selected.value) ?? collection.value.definitions.find((entry) => entry.id === selected.value); @@ -243,7 +247,7 @@ async function writeDraft(target: string, next: string | undefined, force = fals // survives a reload and nothing reaches the running workflow until Publish. // A draft equal to the published definition is removed. async function persistDraft(target: string, value: string, force = false): Promise { - if (!target) return; + if (!target || removed) return; const published = collection.value.definitions.find((entry) => entry.id === target)?.yaml ?? ""; const current = workflows.drafts.find((draft) => draft.id === target)?.yaml; const next = value === published ? undefined : value; @@ -344,8 +348,12 @@ async function remove(): Promise { if (!selected.value) return; clearTimeout(pending); unsaved = undefined; + // The page unmounts the editor as the workflow disappears, and unmounting + // would write the draft back. + removed = true; const done = stored.value === undefined ? await workflows.putDraft(selected.value, undefined) : await workflows.remove(selected.value); - if (done) emit("deleted"); + if (!done) removed = false; + else emit("deleted"); } // What is typed, read against the served step vocabulary (workflow-yaml.ts). @@ -430,7 +438,7 @@ const runOptions = computed(() => [ />
- + Test
diff --git a/ui/src/workflows/workflow-runs.ts b/ui/src/workflows/workflow-runs.ts index fcf8f71f8..df3e11b2c 100644 --- a/ui/src/workflows/workflow-runs.ts +++ b/ui/src/workflows/workflow-runs.ts @@ -76,6 +76,8 @@ export function useWorkflowRuns(workflow: Ref) { const watched = ref(""); const trail = shallowRef(); let picked = false; + // A run started here is watched before the list has it. + const followed = new Set(); const error = ref(""); const loading = ref(false); let requestNumber = 0; @@ -90,7 +92,7 @@ export function useWorkflowRuns(workflow: Ref) { const own = page.map(workflowRun); listed.value = keepRows(listed.value, own); error.value = ""; - if (!picked || (watched.value && !runs.value.some((run) => run.id === watched.value))) watched.value = runs.value[0]?.id ?? ""; + if (!picked || (watched.value && !followed.has(watched.value) && !runs.value.some((run) => run.id === watched.value))) watched.value = runs.value[0]?.id ?? ""; } catch (cause) { if (workflow.value === requested && request === requestNumber) error.value = describeError(cause, errors.common.unknown); } finally { @@ -136,6 +138,7 @@ export function useWorkflowRuns(workflow: Ref) { picked = false; listed.value = []; tested.value = []; + followed.clear(); watched.value = ""; trail.value = undefined; error.value = ""; @@ -164,6 +167,7 @@ export function useWorkflowRuns(workflow: Ref) { /** Watches a run that has just started, test run or live. */ async function follow(id: string): Promise { picked = true; + followed.add(id); watched.value = id; await refresh(); }