Skip to content

Commit df5507c

Browse files
feat(agentFlow): Fix duplicate node and add test cases for delete and duplicate nodes (#5840)
* Test cases added for delete node * Fix incorrect node id being assigned to duplicate node * Test cases added for duplicate node * Fix for bug FLOWISE-257 * lint errors fix * Fix gemini comments * FIx comment * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Fix lint error * Fixed review comments --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 2e3dfde commit df5507c

5 files changed

Lines changed: 1131 additions & 25 deletions

File tree

packages/agentflow/TESTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ These modules carry the highest risk. Test in the same PR when modifying.
3434
| `src/infrastructure/api/client.ts` | `createApiClient` — headers, auth token, 401 interceptor | ✅ Done |
3535
| `src/infrastructure/api/chatflows.ts` | All CRUD + `generateAgentflow` + `getChatModels`, FlowData serialization | ✅ Done |
3636
| `src/infrastructure/api/nodes.ts` | `getAllNodes`, `getNodeByName`, `getNodeIconUrl` | ✅ Done |
37-
| `src/infrastructure/store/AgentflowContext.tsx` | `agentflowReducer` (all actions), `normalizeNodes`. Remaining: `deleteNode()`, `duplicateNode()`, `updateNodeData()`, `getFlowData()` | 🟡 Partial |
37+
| `src/infrastructure/store/AgentflowContext.tsx` | `agentflowReducer` (all actions), `normalizeNodes`, `deleteNode()`, `duplicateNode()`. Remaining: `updateNodeData()`, `getFlowData()` | 🟡 Partial|
3838
| `src/useAgentflow.ts` | `getFlow()`, `toJSON()`, `validate()`, `addNode()`, `clear()` | ⬜ Not yet — thin wrapper |
3939
| `src/features/canvas/hooks/useFlowHandlers.ts` | `handleConnect`, `handleNodesChange`, `handleEdgesChange`, `handleAddNode` — synchronous `onFlowChange` callbacks, dirty tracking, viewport resolution, change filtering | ✅ Done |
4040

@@ -130,6 +130,7 @@ Key features:
130130
- `./src/features/canvas/hooks/useFlowHandlers.ts`
131131
- `./src/features/node-palette/search.ts`
132132
- `./src/infrastructure/api/`
133+
-`./src/infrastructure/store/AgentflowContext.tsx` — will be added when coverage reaches 80%
133134
- **Coverage exclusions**:
134135
- `src/__test_utils__/**` — test utilities
135136
- `src/__mocks__/**` — module mocks

packages/agentflow/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ module.exports = {
4040
'./src/core/': { branches: 80, functions: 80, lines: 80, statements: 80 },
4141
'./src/features/canvas/hooks/useFlowHandlers.ts': { branches: 80, functions: 80, lines: 80, statements: 80 },
4242
'./src/features/node-palette/search.ts': { branches: 80, functions: 80, lines: 80, statements: 80 },
43-
'./src/infrastructure/api/': { branches: 80, functions: 80, lines: 80, statements: 80 }
43+
'./src/infrastructure/api/': { branches: 80, functions: 80, lines: 80, statements: 80 },
44+
'./src/infrastructure/store/AgentflowContext.tsx': { branches: 80, functions: 80, lines: 80, statements: 80 }
4445
},
4546
projects: [
4647
// .test.ts → node (fast, no DOM)

packages/agentflow/src/Agentflow.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ function AgentflowCanvas({
5151
renderHeader?: AgentflowProps['renderHeader']
5252
renderNodePalette?: AgentflowProps['renderNodePalette']
5353
}) {
54-
const { state, setNodes, setEdges, setDirty, setReactFlowInstance, closeEditDialog, registerLocalStateSetters } = useAgentflowContext()
54+
const {
55+
state,
56+
syncNodesFromReactFlow,
57+
syncEdgesFromReactFlow,
58+
setDirty,
59+
setReactFlowInstance,
60+
closeEditDialog,
61+
registerLocalStateSetters
62+
} = useAgentflowContext()
5563
const { isDarkMode } = useConfigContext()
5664
const agentflow = useAgentflow()
5765
const reactFlowWrapper = useRef<HTMLDivElement>(null)
@@ -82,12 +90,12 @@ function AgentflowCanvas({
8290

8391
// Sync local ReactFlow state to context (when user interacts with canvas)
8492
useEffect(() => {
85-
setNodes(nodes as FlowNode[])
86-
}, [nodes, setNodes])
93+
syncNodesFromReactFlow(nodes as FlowNode[])
94+
}, [nodes, syncNodesFromReactFlow])
8795

8896
useEffect(() => {
89-
setEdges(edges as FlowEdge[])
90-
}, [edges, setEdges])
97+
syncEdgesFromReactFlow(edges as FlowEdge[])
98+
}, [edges, syncEdgesFromReactFlow])
9199

92100
// Flow handlers
93101
const { handleConnect, handleNodesChange, handleNodeDragStop, handleEdgesChange, handleAddNode } = useFlowHandlers({

0 commit comments

Comments
 (0)