diff --git a/src/components/WorkflowToolbar.tsx b/src/components/WorkflowToolbar.tsx index 37df173..b9b535f 100644 --- a/src/components/WorkflowToolbar.tsx +++ b/src/components/WorkflowToolbar.tsx @@ -23,6 +23,7 @@ export const WorkflowToolbar: React.FC = () => { executeWorkflow, isExecuting, clearExecutionResults, + clearAllNodes, } = useWorkflowStore(); const fileInputRef = useRef(null); @@ -70,7 +71,7 @@ export const WorkflowToolbar: React.FC = () => { }; const handleClear = () => { - clearExecutionResults(); + clearAllNodes(); }; if (!currentWorkflow) return null; @@ -156,10 +157,10 @@ export const WorkflowToolbar: React.FC = () => { diff --git a/src/store/workflowStore.ts b/src/store/workflowStore.ts index c0d3d50..f26567d 100644 --- a/src/store/workflowStore.ts +++ b/src/store/workflowStore.ts @@ -83,6 +83,7 @@ interface WorkflowStore { addNode: (type: string, position: { x: number; y: number }) => void; updateNode: (nodeId: string, data: Partial) => void; deleteNode: (nodeId: string) => void; + clearAllNodes: () => void; selectNode: (nodeId: string | null) => void; // Edge management @@ -280,6 +281,29 @@ export const useWorkflowStore = create((set, get) => ({ })); }, + clearAllNodes: () => { + // Clear execution state first + set((state) => ({ + selectedNodeId: null, + executionResults: {}, + isExecuting: false, + })); + + // Use setTimeout to allow React Flow to properly handle node removal + setTimeout(() => { + set((state) => ({ + currentWorkflow: state.currentWorkflow + ? { + ...state.currentWorkflow, + nodes: [], + edges: [], + updatedAt: new Date(), + } + : null, + })); + }, 0); + }, + selectNode: (nodeId: string | null) => { set({ selectedNodeId: nodeId }); },