Implement clearAllNodes functionality in WorkflowToolbar and workflowStore

- Added clearAllNodes method to the workflow store to reset the workflow state, clearing all nodes and edges.
- Updated WorkflowToolbar to replace the clearExecutionResults function with clearAllNodes, renaming the button to "Reset workflow (clear all nodes)" for clarity.
- Enhanced user experience by ensuring the reset action is clearly communicated through UI changes.
This commit is contained in:
Nikhil-Doye
2025-10-18 21:53:56 -04:00
parent ee87d8ad0d
commit 6e8d85d10b
2 changed files with 28 additions and 3 deletions
+4 -3
View File
@@ -23,6 +23,7 @@ export const WorkflowToolbar: React.FC = () => {
executeWorkflow,
isExecuting,
clearExecutionResults,
clearAllNodes,
} = useWorkflowStore();
const fileInputRef = useRef<HTMLInputElement>(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 = () => {
<button
onClick={handleClear}
className="flex items-center space-x-2 px-3 py-2 bg-gray-100 text-gray-700 rounded-md hover:bg-gray-200 transition-colors"
title="Clear execution results"
title="Reset workflow (clear all nodes)"
>
<RotateCcw className="w-4 h-4" />
<span>Clear</span>
<span>Reset</span>
</button>
</div>
+24
View File
@@ -83,6 +83,7 @@ interface WorkflowStore {
addNode: (type: string, position: { x: number; y: number }) => void;
updateNode: (nodeId: string, data: Partial<NodeData>) => void;
deleteNode: (nodeId: string) => void;
clearAllNodes: () => void;
selectNode: (nodeId: string | null) => void;
// Edge management
@@ -280,6 +281,29 @@ export const useWorkflowStore = create<WorkflowStore>((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 });
},