Make workflow editing open in the shared floating window shell. - Replace the workflow editor modal overlay with FloatingWindow drag, resize, and geometry persistence. - Let graph and header workflow switcher callbacks forward the selected workflow id into the editor. - Update workflow editor sizing styles and mobile full-screen behavior for the floating shell. - Add regression coverage for floating-window behavior, resize ownership, and workflow id forwarding. Files changed: .../app/components/GraphWorkflowSwitcherSlot.tsx | 6 +- .../app/components/HeaderWorkflowSwitcherSlot.tsx | 6 +- .../app/components/WorkflowNodeEditor.css | 51 +++++++-- .../app/components/WorkflowNodeEditor.tsx | 33 +++--- .../__tests__/GraphWorkflowSwitcherSlot.test.tsx | 11 ++ .../__tests__/HeaderWorkflowSwitcherSlot.test.tsx | 10 ++ .../__tests__/WorkflowNodeEditor.css.test.ts | 21 ++-- .../__tests__/WorkflowNodeEditor.test.tsx | 126 +++++++++++++++++---- 8 files changed, 208 insertions(+), 56 deletions(-) Fusion-Task-Id: FN-6989 Fusion-Task-Lineage: cf762608-37d5-43be-8cbe-20fd1ae56296
115 lines
4.1 KiB
TypeScript
115 lines
4.1 KiB
TypeScript
import { useEffect, useMemo, useState } from "react";
|
|
import { createPortal } from "react-dom";
|
|
import type { BoardWorkflowDefinition, BoardWorkflowsPayload } from "../api";
|
|
import { useBoardWorkflows } from "../hooks/useBoardWorkflows";
|
|
import { useViewportMode } from "../hooks/useViewportMode";
|
|
import { WorkflowSwitcher } from "./WorkflowSwitcher";
|
|
import type { WorkflowStatusCounts } from "./workflowStatusCounts";
|
|
|
|
export interface GraphWorkflowSelection {
|
|
boardWorkflows: BoardWorkflowsPayload;
|
|
selectedWorkflow: BoardWorkflowDefinition;
|
|
}
|
|
|
|
interface GraphWorkflowSwitcherSlotProps {
|
|
projectId?: string;
|
|
/*
|
|
FNXC:WorkflowEditorFloating 2026-06-24-00:00:
|
|
Graph shares the Board/List workflow dropdown contract, so row edit must forward the workflow id into the floating editor. Keeping the parameter prevents Graph edits from falling back to the default workflow.
|
|
*/
|
|
onOpenWorkflowEditor?: (workflowId?: string) => void;
|
|
onCreateWorkflow?: () => void;
|
|
onWorkflowSelectionChange?: (selection: GraphWorkflowSelection | null) => void;
|
|
}
|
|
|
|
const EMPTY_COUNTS: Map<string, WorkflowStatusCounts> = new Map();
|
|
|
|
export function filterTasksByGraphWorkflowSelection<T extends { id: string }>(
|
|
tasks: T[],
|
|
projectId: string | undefined,
|
|
selection: GraphWorkflowSelection | null,
|
|
): T[] {
|
|
if (!projectId || !selection) return tasks;
|
|
return tasks.filter((task) => {
|
|
const assignedWorkflowId = selection.boardWorkflows.taskWorkflowIds[task.id]
|
|
?? selection.boardWorkflows.defaultWorkflowId;
|
|
return assignedWorkflowId === selection.selectedWorkflow.id;
|
|
});
|
|
}
|
|
|
|
export function GraphWorkflowSwitcherSlot({
|
|
projectId,
|
|
onOpenWorkflowEditor,
|
|
onCreateWorkflow,
|
|
onWorkflowSelectionChange,
|
|
}: GraphWorkflowSwitcherSlotProps) {
|
|
const {
|
|
boardWorkflows,
|
|
workflowMode,
|
|
workflowOptions,
|
|
selectedWorkflow,
|
|
setSelectedWorkflowId,
|
|
refreshBoardWorkflows,
|
|
} = useBoardWorkflows({ projectId });
|
|
const viewportMode = useViewportMode();
|
|
|
|
const [headerWorkflowSlot, setHeaderWorkflowSlot] = useState<HTMLElement | null>(() => {
|
|
if (typeof document === "undefined") return null;
|
|
return document.getElementById("header-workflow-slot");
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (typeof document === "undefined") return;
|
|
const resolve = () => {
|
|
const slot = document.getElementById("header-workflow-slot");
|
|
setHeaderWorkflowSlot((previous) => (previous === slot ? previous : slot));
|
|
return slot;
|
|
};
|
|
if (resolve()) return;
|
|
/*
|
|
FNXC:GraphWorkflowSwitcher 2026-06-23-21:45:
|
|
Graph shares the Board/List header workflow affordance, but mobile and inactive left-sidebar layouts can omit `#header-workflow-slot`. Poll only briefly and re-resolve on viewport changes so Graph never spins forever or leaves an empty dropdown shell when the header slot is absent.
|
|
*/
|
|
let attempts = 0;
|
|
const interval = window.setInterval(() => {
|
|
attempts += 1;
|
|
if (resolve() || attempts >= 20) window.clearInterval(interval);
|
|
}, 250);
|
|
return () => window.clearInterval(interval);
|
|
}, [viewportMode]);
|
|
|
|
const selection = useMemo<GraphWorkflowSelection | null>(() => {
|
|
if (!workflowMode || !boardWorkflows || !selectedWorkflow) return null;
|
|
return { boardWorkflows, selectedWorkflow };
|
|
}, [boardWorkflows, selectedWorkflow, workflowMode]);
|
|
|
|
useEffect(() => {
|
|
onWorkflowSelectionChange?.(selection);
|
|
}, [onWorkflowSelectionChange, selection]);
|
|
|
|
useEffect(() => {
|
|
return () => onWorkflowSelectionChange?.(null);
|
|
}, [onWorkflowSelectionChange]);
|
|
|
|
if (!workflowMode || !selectedWorkflow || workflowOptions.length < 2 || !headerWorkflowSlot) {
|
|
return null;
|
|
}
|
|
|
|
return createPortal(
|
|
<div className="board-workflow-toolbar">
|
|
<div className="board-workflow-selector">
|
|
<WorkflowSwitcher
|
|
workflows={workflowOptions}
|
|
value={selectedWorkflow.id}
|
|
onChange={setSelectedWorkflowId}
|
|
counts={EMPTY_COUNTS}
|
|
onOpen={refreshBoardWorkflows}
|
|
onEditWorkflow={onOpenWorkflowEditor}
|
|
onCreateWorkflow={onCreateWorkflow}
|
|
/>
|
|
</div>
|
|
</div>,
|
|
headerWorkflowSlot,
|
|
);
|
|
}
|