FN-6923: default new tasks to the selected workflow lane

New Task now inherits the project's current or last valid workflow lane.

- Persist explicit Board and List workflow switcher selections per project.
- Seed the New Task workflow selector from the cached valid lane without marking the pristine dialog dirty.
- Preserve default-workflow inheritance when no remembered lane exists or the remembered lane was deleted.
- Cover quick-add parity, workflow defaulting, stale-lane fallback, and storage helper behavior in tests.
- Document New Task workflow selector defaulting in the dashboard guide.

Files changed:
 docs/dashboard-guide.md                            |   2 +
 packages/dashboard/app/components/Board.tsx        |  12 +-
 packages/dashboard/app/components/ListView.tsx     |  12 +-
 packages/dashboard/app/components/NewTaskModal.tsx |  21 ++-
 .../app/components/__tests__/NewTaskModal.test.tsx | 142 ++++++++++++++++++++-
 .../utils/__tests__/lastSelectedWorkflow.test.ts   |  67 ++++++++++
 .../dashboard/app/utils/lastSelectedWorkflow.ts    |  31 +++++
 7 files changed, 279 insertions(+), 8 deletions(-)

Fusion-Task-Id: FN-6923
Fusion-Task-Lineage: 6e3c8efd-3865-4975-a754-2f0d5ff89ab0
This commit is contained in:
gsxdsm
2026-06-22 02:07:57 -07:00
parent 322077b804
commit c0ab7f43b8
7 changed files with 279 additions and 8 deletions

View File

@@ -240,6 +240,8 @@ These values are sent with the Planning Mode create-task request as `branchSelec
When inline quick-create, Planning Mode, or Subtask Breakdown is opened from a workflow-filtered board/list lane, the create request also carries that active workflow selection. Quick-created tasks appear on the selected workflow lane immediately while board-workflows metadata refreshes, and planning saves, planning breakdown saves, and subtask-breakdown saves create their tasks directly on the selected workflow lane instead of briefly landing on the default board.
The **New Task** dialog's workflow selector also defaults to the current or last selected Board/List workflow lane for the current project. If no valid lane has been selected, or the remembered lane was deleted, the selector falls back to the project default workflow and task creation omits an explicit `workflowId`.
Completed single-task planning sessions remain in the Planning Mode history after you create the task, and selecting one restores the completed summary instead of restarting the composer. History rows are deduplicated by session id even if the initial load and live session updates arrive out of order, and deleting a history entry now waits for the server delete to persist (failures keep the row visible and surface an error instead of silently disappearing until refresh).
## New Task Modal Branch Strategy

View File

@@ -16,6 +16,7 @@ import { getBoardCanDropTaskRejection } from "./boardCanDropTask";
import { WorkflowSwitcher } from "./WorkflowSwitcher";
import { computeWorkflowStatusCounts } from "./workflowStatusCounts";
import { readBoardWorkflowsCache, writeBoardWorkflowsCache } from "../utils/boardWorkflowsCache";
import { writeLastSelectedWorkflowId } from "../utils/lastSelectedWorkflow";
interface BoardProps {
tasks: Task[];
@@ -483,6 +484,15 @@ export function Board({ tasks, projectId, maxConcurrent, onMoveTask, onPauseTask
}
}, [selectedWorkflow, selectedWorkflowId, workflowMode]);
/**
* FNXC:WorkflowDefaults 2026-06-22-00:00:
* Persist explicit board-lane picks per project so the New Task dialog opens on the same current or last selected workflow lane without changing board filtering semantics.
*/
const handleSelectedWorkflowChange = useCallback((id: string) => {
setSelectedWorkflowId(id);
writeLastSelectedWorkflowId(projectId, id);
}, [projectId]);
const selectedWorkflowTasks = useMemo(() => {
if (!workflowMode || !boardWorkflows || !selectedWorkflow) return [];
return tasks.filter((task) => {
@@ -612,7 +622,7 @@ export function Board({ tasks, projectId, maxConcurrent, onMoveTask, onPauseTask
<WorkflowSwitcher
workflows={workflowOptions}
value={selectedWorkflow.id}
onChange={setSelectedWorkflowId}
onChange={handleSelectedWorkflowChange}
counts={workflowStatusCounts}
onOpen={refreshBoardWorkflows}
onEditWorkflow={onOpenWorkflowEditor}

View File

@@ -25,6 +25,7 @@ import { subscribeSse } from "../sse-bus";
import { WorkflowSwitcher } from "./WorkflowSwitcher";
import { computeWorkflowStatusCounts } from "./workflowStatusCounts";
import { readBoardWorkflowsCache, writeBoardWorkflowsCache } from "../utils/boardWorkflowsCache";
import { writeLastSelectedWorkflowId } from "../utils/lastSelectedWorkflow";
const COLUMN_COLOR_MAP: Record<Column, string> = {
triage: "var(--triage)",
@@ -629,6 +630,15 @@ export function ListView({
}
}, [selectedWorkflow, selectedWorkflowId, workflowMode]);
/**
* FNXC:WorkflowDefaults 2026-06-22-00:00:
* Persist explicit list-view workflow-lane picks per project so New Task inherits the user's current board context without changing list filtering or default resolution.
*/
const handleSelectedWorkflowChange = useCallback((id: string) => {
setSelectedWorkflowId(id);
writeLastSelectedWorkflowId(projectId, id);
}, [projectId]);
useEffect(() => {
setSelectedColumn(null);
}, [selectedWorkflowId]);
@@ -1662,7 +1672,7 @@ export function ListView({
<WorkflowSwitcher
workflows={workflowOptions}
value={selectedWorkflow.id}
onChange={setSelectedWorkflowId}
onChange={handleSelectedWorkflowChange}
counts={workflowStatusCounts}
onOpen={refreshBoardWorkflows}
label={t("listView.workflowLabel", "Workflow")}

View File

@@ -17,6 +17,8 @@ import { useMobileScrollLock } from "../hooks/useMobileScrollLock";
import { useNodes } from "../hooks/useNodes";
import { useViewportMode } from "../hooks/useViewportMode";
import { useAgentsMapCache } from "../hooks/useAgentsMapCache";
import { readBoardWorkflowsCache } from "../utils/boardWorkflowsCache";
import { readLastSelectedWorkflowId } from "../utils/lastSelectedWorkflow";
interface NewTaskModalProps {
isOpen: boolean;
@@ -64,6 +66,7 @@ export function NewTaskModal({ isOpen, onClose, projectId, tasks, onCreateTask,
// `null` = explicit "No workflow", `string` = a specific workflow. Materialized
// atomically at create time via the `workflowId` create parameter.
const [selectedWorkflowId, setSelectedWorkflowId] = useState<string | null | undefined>(undefined);
const initialWorkflowIdRef = useRef<string | null | undefined>(undefined);
// Optional workflow steps the user opted into; TaskForm fetches + seeds these
// from the selected workflow's defaultOn and lifts the enabled set up here.
const [enabledWorkflowSteps, setEnabledWorkflowSteps] = useState<string[]>([]);
@@ -96,13 +99,23 @@ export function NewTaskModal({ isOpen, onClose, projectId, tasks, onCreateTask,
/**
* FNXC:SelectionComment 2026-06-16-23:58:
* Selection comments open the normal New Task dialog with a prefilled description; seed only on the closed→open transition so rerenders do not overwrite user edits.
*
* FNXC:WorkflowDefaults 2026-06-22-00:00:
* Seed New Task's workflow selector from the project's last selected board lane only when that lane still exists in the board-workflows cache. Store the seed as the pristine baseline so opening on a remembered lane does not trigger discard-changes confirmation, and reset returns to that same baseline.
*/
useEffect(() => {
if (isOpen && !wasOpenRef.current) {
setDescription(initialDescription);
const persistedWorkflowId = readLastSelectedWorkflowId(projectId);
const cachedWorkflows = readBoardWorkflowsCache(projectId);
const initialWorkflowId = persistedWorkflowId && cachedWorkflows?.workflows.some((workflow) => workflow.id === persistedWorkflowId)
? persistedWorkflowId
: undefined;
initialWorkflowIdRef.current = initialWorkflowId;
setSelectedWorkflowId(initialWorkflowId);
}
wasOpenRef.current = isOpen;
}, [initialDescription, isOpen]);
}, [initialDescription, isOpen, projectId]);
// Load agents for agent picker
const loadAgents = useCallback(() => {
@@ -171,7 +184,7 @@ export function NewTaskModal({ isOpen, onClose, projectId, tasks, onCreateTask,
description.trim() !== "" ||
dependencies.length > 0 ||
pendingImages.length > 0 ||
selectedWorkflowId !== undefined ||
selectedWorkflowId !== initialWorkflowIdRef.current ||
// Optional workflow steps the user toggled count as unsaved work. (Workflows
// whose steps are defaultOn:false — today's only shipped step — seed an empty
// set, so this stays false until the user actually opts a step in.)
@@ -207,7 +220,7 @@ export function NewTaskModal({ isOpen, onClose, projectId, tasks, onCreateTask,
setThinkingLevel("");
setSelectedPresetId("");
setPresetMode("default");
setSelectedWorkflowId(undefined);
setSelectedWorkflowId(initialWorkflowIdRef.current);
setEnabledWorkflowSteps([]);
setSelectedAgentId(null);
setShowAgentPicker(false);
@@ -335,7 +348,7 @@ export function NewTaskModal({ isOpen, onClose, projectId, tasks, onCreateTask,
setThinkingLevel("");
setSelectedPresetId("");
setPresetMode("default");
setSelectedWorkflowId(undefined);
setSelectedWorkflowId(initialWorkflowIdRef.current);
setEnabledWorkflowSteps([]);
setSelectedAgentId(null);
setShowAgentPicker(false);

View File

@@ -3,6 +3,9 @@ import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import type { ComponentProps } from "react";
import { NewTaskModal } from "../NewTaskModal";
import type { Task, Column } from "@fusion/core";
import type { BoardWorkflowsPayload } from "../../api";
import { writeBoardWorkflowsCache } from "../../utils/boardWorkflowsCache";
import { writeLastSelectedWorkflowId } from "../../utils/lastSelectedWorkflow";
// Mock lucide-react
vi.mock("lucide-react", () => ({
@@ -76,6 +79,43 @@ function makeTask(id: string): Task {
};
}
function workflowDefinition(id: string, name: string) {
return {
id,
name,
description: "",
kind: "workflow" as const,
ir: { version: "v1", name, nodes: [], edges: [] },
layout: {},
createdAt: "",
updatedAt: "",
};
}
function boardWorkflowsPayload(workflows: Array<{ id: string; name: string }>, defaultWorkflowId = workflows[0]?.id ?? "builtin:coding"): BoardWorkflowsPayload {
return {
flagEnabled: true,
defaultWorkflowId,
workflows: workflows.map((workflow) => ({
id: workflow.id,
name: workflow.name,
columns: [{ id: "todo", name: "Todo", flags: {} }],
})),
taskWorkflowIds: {},
};
}
async function mockSelectableWorkflows(workflows: Array<{ id: string; name: string }>, defaultWorkflowId = workflows[0]?.id) {
const { fetchSettings, fetchWorkflows } = await import("../../api");
vi.mocked(fetchSettings).mockResolvedValueOnce({
modelPresets: [],
autoSelectModelPreset: false,
defaultPresetBySize: {},
defaultWorkflowId,
});
vi.mocked(fetchWorkflows).mockResolvedValueOnce(workflows.map((workflow) => workflowDefinition(workflow.id, workflow.name)) as any);
}
function renderNewTaskModal(props: Partial<ComponentProps<typeof NewTaskModal>> = {}) {
const defaultProps: ComponentProps<typeof NewTaskModal> = {
isOpen: true,
@@ -92,6 +132,8 @@ function renderNewTaskModal(props: Partial<ComponentProps<typeof NewTaskModal>>
describe("NewTaskModal", () => {
beforeEach(() => {
vi.clearAllMocks();
window.localStorage.clear();
window.sessionStorage.clear();
mockConfirm.mockReset();
mockConfirm.mockResolvedValue(true);
mockUseMobileKeyboard.mockReturnValue({
@@ -150,7 +192,11 @@ describe("NewTaskModal", () => {
expect(screen.getByRole("button", { name: "Cancel" })).toBeTruthy();
});
it("exposes New Task dialog quick-add affordance parity when AI handoff callbacks are supplied", () => {
it("exposes New Task dialog quick-add affordance parity when AI handoff callbacks are supplied", async () => {
await mockSelectableWorkflows([
{ id: "WF-DEFAULT", name: "Default workflow" },
{ id: "WF-LANE", name: "Selected lane" },
], "WF-DEFAULT");
renderNewTaskModal({
onPlanningMode: vi.fn(),
onSubtaskBreakdown: vi.fn(),
@@ -158,7 +204,7 @@ describe("NewTaskModal", () => {
fireEvent.change(screen.getByRole("textbox"), { target: { value: "Create parity coverage" } });
// Canonical QuickEntryBox action row includes Plan, Subtask, Refine, Deps, Attach, Models, Node, and Agent affordances; the modal maps these to existing TaskForm/quick-field controls instead of duplicating implementations.
// Canonical QuickEntryBox action row includes Save/Create, Fast, GitHub, Priority, Plan, Subtask, Refine, Deps, Attach, Models, Node, Agent, and the inherited workflow lane; the modal maps these to existing TaskForm/quick-field controls instead of duplicating implementations.
expect(screen.getAllByTestId("task-form-plan-button")).toHaveLength(1);
expect(screen.getAllByTestId("task-form-subtask-button")).toHaveLength(1);
expect(screen.getByTestId("refine-button")).toBeInTheDocument();
@@ -171,7 +217,12 @@ describe("NewTaskModal", () => {
expect(screen.getByTestId("task-form-github-tracking")).toBeInTheDocument();
expect(screen.getByTestId("task-priority-select")).toBeInTheDocument();
expect(screen.getByText(/Attachments/i)).toBeInTheDocument();
expect(await screen.findByText(/Executor/i)).toBeInTheDocument();
expect(screen.getByText(/Reviewer/i)).toBeInTheDocument();
expect(screen.getByText(/Planning/i)).toBeInTheDocument();
expect(screen.getByText(/Node Override/i)).toBeInTheDocument();
expect(await screen.findByTestId("task-workflow-select")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Create Task" })).toBeInTheDocument();
});
it("renders the Fast and standard execution-mode affordance inside More options", () => {
@@ -849,6 +900,93 @@ describe("NewTaskModal", () => {
});
}
it("defaults to the persisted valid board lane and submits that workflowId", async () => {
const workflows = [
{ id: "WF-DEFAULT", name: "Default workflow" },
{ id: "WF-LANE", name: "Selected lane" },
];
writeLastSelectedWorkflowId("project-a", "WF-LANE");
writeBoardWorkflowsCache("project-a", boardWorkflowsPayload(workflows, "WF-DEFAULT"));
await mockSelectableWorkflows(workflows, "WF-DEFAULT");
const { props } = renderNewTaskModal({ projectId: "project-a" });
const select = await screen.findByTestId("task-workflow-select") as HTMLSelectElement;
await waitFor(() => expect(select).toHaveValue("WF-LANE"));
fireEvent.change(screen.getByRole("textbox"), { target: { value: "Use selected lane" } });
fireEvent.click(screen.getByRole("button", { name: "Create Task" }));
await waitFor(() => {
expect(props.onCreateTask).toHaveBeenCalledWith(
expect.objectContaining({ workflowId: "WF-LANE" }),
);
});
});
it("inherits the project default and omits workflowId when no lane is persisted", async () => {
const workflows = [
{ id: "WF-DEFAULT", name: "Default workflow" },
{ id: "WF-LANE", name: "Selected lane" },
];
await mockSelectableWorkflows(workflows, "WF-DEFAULT");
const { props } = renderNewTaskModal({ projectId: "project-a" });
const select = await screen.findByTestId("task-workflow-select") as HTMLSelectElement;
await waitFor(() => expect(select).toHaveValue("WF-DEFAULT"));
fireEvent.change(screen.getByRole("textbox"), { target: { value: "Inherit default lane" } });
fireEvent.click(screen.getByRole("button", { name: "Create Task" }));
await waitFor(() => {
expect(props.onCreateTask).toHaveBeenCalledTimes(1);
});
const payload = vi.mocked(props.onCreateTask).mock.calls[0][0] as Record<string, unknown>;
expect(payload).not.toHaveProperty("workflowId");
});
it("ignores a stale persisted lane and falls back to the project default", async () => {
const workflows = [
{ id: "WF-DEFAULT", name: "Default workflow" },
{ id: "WF-LANE", name: "Selected lane" },
];
writeLastSelectedWorkflowId("project-a", "WF-DELETED");
writeBoardWorkflowsCache("project-a", boardWorkflowsPayload(workflows, "WF-DEFAULT"));
await mockSelectableWorkflows(workflows, "WF-DEFAULT");
const { props } = renderNewTaskModal({ projectId: "project-a" });
const select = await screen.findByTestId("task-workflow-select") as HTMLSelectElement;
await waitFor(() => expect(select).toHaveValue("WF-DEFAULT"));
fireEvent.change(screen.getByRole("textbox"), { target: { value: "Ignore deleted lane" } });
fireEvent.click(screen.getByRole("button", { name: "Create Task" }));
await waitFor(() => {
expect(props.onCreateTask).toHaveBeenCalledTimes(1);
});
const payload = vi.mocked(props.onCreateTask).mock.calls[0][0] as Record<string, unknown>;
expect(payload).not.toHaveProperty("workflowId");
});
it("does not treat a seeded persisted lane as dirty on cancel", async () => {
const workflows = [
{ id: "WF-DEFAULT", name: "Default workflow" },
{ id: "WF-LANE", name: "Selected lane" },
];
writeLastSelectedWorkflowId("project-a", "WF-LANE");
writeBoardWorkflowsCache("project-a", boardWorkflowsPayload(workflows, "WF-DEFAULT"));
await mockSelectableWorkflows(workflows, "WF-DEFAULT");
const { props } = renderNewTaskModal({ projectId: "project-a" });
const select = await screen.findByTestId("task-workflow-select") as HTMLSelectElement;
await waitFor(() => expect(select).toHaveValue("WF-LANE"));
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
await waitFor(() => {
expect(props.onClose).toHaveBeenCalledTimes(1);
});
expect(mockConfirm).not.toHaveBeenCalled();
});
it("omits workflowId from the payload when the picker is untouched (inherit default)", async () => {
await mockWorkflows([{ id: "WF-1", name: "QA" }]);
const { props } = renderNewTaskModal();

View File

@@ -0,0 +1,67 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { readLastSelectedWorkflowId, writeLastSelectedWorkflowId } from "../lastSelectedWorkflow";
describe("lastSelectedWorkflow", () => {
afterEach(() => {
if (typeof window !== "undefined") {
window.localStorage.clear();
}
vi.unstubAllGlobals();
vi.restoreAllMocks();
});
it("round-trips the selected workflow id per project", () => {
writeLastSelectedWorkflowId("project-a", "WF-1");
expect(readLastSelectedWorkflowId("project-a")).toBe("WF-1");
});
it("keeps project cache keys isolated", () => {
writeLastSelectedWorkflowId("project-a", "WF-1");
writeLastSelectedWorkflowId("project-b", "WF-2");
expect(readLastSelectedWorkflowId("project-a")).toBe("WF-1");
expect(readLastSelectedWorkflowId("project-b")).toBe("WF-2");
});
it("uses a default key for callers without a project id", () => {
writeLastSelectedWorkflowId(undefined, "WF-default");
writeLastSelectedWorkflowId("project-a", "WF-project");
expect(readLastSelectedWorkflowId()).toBe("WF-default");
expect(readLastSelectedWorkflowId("project-a")).toBe("WF-project");
});
it("returns null for missing, empty, or non-string entries", () => {
expect(readLastSelectedWorkflowId("missing")).toBeNull();
window.localStorage.setItem("fusion:last-selected-workflow:empty", "");
expect(readLastSelectedWorkflowId("empty")).toBeNull();
vi.spyOn(Storage.prototype, "getItem").mockReturnValueOnce({ workflowId: "WF-1" } as unknown as string);
expect(readLastSelectedWorkflowId("non-string")).toBeNull();
});
it("swallows localStorage write failures", () => {
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
throw new Error("quota");
});
expect(() => writeLastSelectedWorkflowId("project-a", "WF-1")).not.toThrow();
});
it("swallows localStorage read failures", () => {
vi.spyOn(Storage.prototype, "getItem").mockImplementation(() => {
throw new Error("private mode");
});
expect(readLastSelectedWorkflowId("project-a")).toBeNull();
});
it("returns null without window for SSR callers", () => {
vi.stubGlobal("window", undefined);
expect(readLastSelectedWorkflowId("project-a")).toBeNull();
expect(() => writeLastSelectedWorkflowId("project-a", "WF-1")).not.toThrow();
});
});

View File

@@ -0,0 +1,31 @@
const LAST_SELECTED_WORKFLOW_PREFIX = "fusion:last-selected-workflow:";
const DEFAULT_PROJECT_CACHE_KEY = "default";
function cacheKey(projectId?: string): string {
return `${LAST_SELECTED_WORKFLOW_PREFIX}${projectId ?? DEFAULT_PROJECT_CACHE_KEY}`;
}
/**
* FNXC:WorkflowDefaults 2026-06-22-00:00:
* Persist the board's current workflow lane per project so New Task can default its existing workflow selector to the current or last selected lane without leaking choices across projects.
*/
export function readLastSelectedWorkflowId(projectId?: string): string | null {
if (typeof window === "undefined") return null;
try {
const value = window.localStorage.getItem(cacheKey(projectId));
return typeof value === "string" && value.trim() !== "" ? value : null;
} catch {
return null;
}
}
export function writeLastSelectedWorkflowId(projectId: string | undefined, workflowId: string): void {
if (typeof window === "undefined") return;
try {
window.localStorage.setItem(cacheKey(projectId), workflowId);
} catch {
// Private-mode/quota failures should never block board workflow selection.
}
}