fix(ui/workflows): a deleted workflow is not written back and a started run is followed (#2061)

This commit is contained in:
sam committed 2026-11-22 13:54:09 +11:00
1 parent 456c08751a
commit 53719c6859
2 files changed
+16 -4

No files matched your search

+11 -3
View File
@@ -193,7 +193,10 @@ const seenDraft = ref<string | undefined>();
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<void> {
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<void> {
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(() => [
/>
</div>
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1 max-sm:flex-1">
<OptionSelect :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-32 max-w-56 max-sm:w-full *:data-[slot=select-value]:block *:data-[slot=select-value]:truncate" @update:model-value="pick" />
<OptionSelect :key="`${watched}/${watchedRun?.status}`" :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-32 max-w-56 max-sm:w-full *:data-[slot=select-value]:block *:data-[slot=select-value]:truncate" @update:model-value="pick" />
<Badge v-if="watchedRun?.source === 'test'" variant="outline" class="shrink-0">Test</Badge>
</div>
</div>
+5 -1
View File
@@ -76,6 +76,8 @@ export function useWorkflowRuns(workflow: Ref<string>) {
const watched = ref("");
const trail = shallowRef<RunTrail>();
let picked = false;
// A run started here is watched before the list has it.
const followed = new Set<string>();
const error = ref("");
const loading = ref(false);
let requestNumber = 0;
@@ -90,7 +92,7 @@ export function useWorkflowRuns(workflow: Ref<string>) {
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<string>) {
picked = false;
listed.value = [];
tested.value = [];
followed.clear();
watched.value = "";
trail.value = undefined;
error.value = "";
@@ -164,6 +167,7 @@ export function useWorkflowRuns(workflow: Ref<string>) {
/** Watches a run that has just started, test run or live. */
async function follow(id: string): Promise<void> {
picked = true;
followed.add(id);
watched.value = id;
await refresh();
}