Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(workflows): keep unsaved editor changes when a status is added or archived (#11484)
pseudoyu6af267b11e62
diff --git a/packages/views/workflows/workflow-editor-page.test.tsx b/packages/views/workflows/workflow-editor-page.test.tsxindex c048fd7e98..0065ed153b 100644--- a/packages/views/workflows/workflow-editor-page.test.tsx+++ b/packages/views/workflows/workflow-editor-page.test.tsx@@ -137,6 +137,43 @@ describe("WorkflowEditorPage status creation", () => {});});+// The catalog refetches whenever anyone adds or archives a status.+describe("WorkflowEditorPage when the status catalog changes", () => {+ const status = (key: string, name: string) => ({ key, name, category: "started", description: "", color: "", icon: "", position: 0 });+ const changeDescription = (value: string) =>+ fireEvent.change(screen.getByRole("textbox", { name: "Description" }), { target: { value } });++ it("keeps an unsaved new workflow", async () => {+ renderEditor();+ fireEvent.change(screen.getByRole("textbox", { name: "Name" }), { target: { value: "Release" } });+ await addNewStatus("Deploy");++ statusEntries.current = [status("triage", "Triage")];+ changeDescription("Ships weekly");++ expect((screen.getByRole("textbox", { name: "Name" }) as HTMLInputElement).value).toBe("Release");+ expect((screen.getByRole("textbox", { name: "Description" }) as HTMLTextAreaElement).value).toBe("Ships weekly");+ expect(stepCard("Deploy")).toBeTruthy();+ });++ it("uses a status an admin adds for a template without dropping the member's edits", async () => {+ createWorkflow.mockResolvedValue({ id: "wf-1" });+ renderEditor({ template: "content", canCreateStatus: false });+ fireEvent.change(screen.getByRole("textbox", { name: "Name" }), { target: { value: "Blog" } });+ expect(screen.getByRole("alert")).toBeTruthy();++ statusEntries.current = [status("drafting", "Drafting"), status("editing", "Editing"), status("scheduled", "Scheduled")];+ changeDescription("Posts");++ await waitFor(() => expect(screen.queryByRole("alert")).toBeNull());+ expect((screen.getByRole("textbox", { name: "Name" }) as HTMLInputElement).value).toBe("Blog");+ fireEvent.click(screen.getByRole("button", { name: "Create" }));+ await waitFor(() => expect(createWorkflow).toHaveBeenCalled());+ const steps = createWorkflow.mock.calls[0]![0].steps as { status_key?: string }[];+ expect(steps.map((s) => s.status_key)).toEqual(expect.arrayContaining(["drafting", "editing", "scheduled"]));+ });+});+/** A step in the list (the detail panel's status picker shares its name). */function stepCard(name: string) {const card = screendiff --git a/packages/views/workflows/workflow-editor-page.tsx b/packages/views/workflows/workflow-editor-page.tsxindex a654f2fa30..36e3c5cf8e 100644--- a/packages/views/workflows/workflow-editor-page.tsx+++ b/packages/views/workflows/workflow-editor-page.tsx@@ -50,6 +50,7 @@ import {import { useActorName } from "@multica/core/workspace/hooks";import { projectListOptions } from "@multica/core/projects/queries";import type {+ IssueStatusEntry,IssueWorkflow,IssueWorkflowMappingPlan,IssueWorkflowStep,@@ -151,6 +152,22 @@ function sameDraft(a: Draft, b: Draft): boolean {return JSON.stringify(a) === JSON.stringify(b);}+/** Points columns that would create a status at the one the catalog already has by that name. */+function withExistingStatuses(draft: Draft, statuses: readonly IssueStatusEntry[]): Draft {+ const used = new Set(draft.middle.flatMap((c) => ("status_key" in c ? [c.status_key] : [])));+ let changed = false;+ const middle = draft.middle.map((column): DraftColumn => {+ if ("status_key" in column) return column;+ const name = column.new_name.toLowerCase();+ const existing = statuses.find((e) => e.name.toLowerCase() === name);+ if (!existing || isFixedWorkflowStatus(existing.key) || used.has(existing.key)) return column;+ used.add(existing.key);+ changed = true;+ return { id: column.id, status_key: existing.key };+ });+ return changed ? { ...draft, middle } : draft;+}+function mappingPlanFrom(err: unknown): IssueWorkflowMappingPlan | null {if (!(err instanceof ApiError) || err.status !== 409 || !err.body || typeof err.body !== "object") return null;const body = err.body as { code?: unknown; plan?: IssueWorkflowMappingPlan };@@ -237,7 +254,7 @@ export function WorkflowEditorPage({};// Re-seed only when the target changes or the saved row is refreshed.// eslint-disable-next-line react-hooks/exhaustive-deps- }, [saved?.updated_at, workflowId, seed?.id, template, catalog.activeStatuses.length]);+ }, [saved?.updated_at, workflowId, seed?.id, template]);const [draft, setDraft] = useState<Draft>(baseline);const [mappingPlan, setMappingPlan] = useState<IssueWorkflowMappingPlan | null>(null);@@ -245,6 +262,11 @@ export function WorkflowEditorPage({const [selected, setSelected] = useState<string | null>(null);const [previewOpen, setPreviewOpen] = useState(false);useEffect(() => setDraft(baseline), [baseline]);+ // The catalog can load or change under an open draft; that must not re-seed it.+ useEffect(+ () => setDraft((d) => withExistingStatuses(d, catalog.activeStatuses)),+ [baseline, catalog.activeStatuses],+ );const dirty = !workflowId || !sameDraft(draft, baseline);const pending = createWorkflow.isPending || updateWorkflow.isPending;