MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / deleteNode

Function deleteNode

packages/ui/src/store/context/ReactFlowContext.jsx:93–130  ·  view source on GitHub ↗
(nodeid)

Source from the content-addressed store, hash-verified

91 }
92
93 const deleteNode = (nodeid) => {
94 deleteConnectedInput(nodeid, 'node')
95
96 // Gather all nodes to be deleted (parent and all descendants)
97 const nodesToDelete = new Set()
98
99 // Helper function to collect all descendant nodes recursively
100 const collectDescendants = (parentId) => {
101 const childNodes = reactFlowInstance.getNodes().filter((node) => node.parentNode === parentId)
102
103 childNodes.forEach((childNode) => {
104 nodesToDelete.add(childNode.id)
105 collectDescendants(childNode.id)
106 })
107 }
108
109 // Collect all descendants first
110 collectDescendants(nodeid)
111
112 // Add the parent node itself last
113 nodesToDelete.add(nodeid)
114
115 // Clean up inputs for all nodes to be deleted
116 nodesToDelete.forEach((id) => {
117 if (id !== nodeid) {
118 // Skip parent node as it's already processed at the beginning
119 deleteConnectedInput(id, 'node')
120 }
121 })
122
123 // Filter out all nodes and edges in a single operation
124 reactFlowInstance.setNodes((nodes) => nodes.filter((node) => !nodesToDelete.has(node.id)))
125
126 // Remove all edges connected to any of the deleted nodes
127 reactFlowInstance.setEdges((edges) => edges.filter((edge) => !nodesToDelete.has(edge.source) && !nodesToDelete.has(edge.target)))
128
129 dispatch({ type: SET_DIRTY })
130 }
131
132 const deleteEdge = (edgeid) => {
133 deleteConnectedInput(edgeid, 'edge')

Callers 6

CanvasNodeFunction · 0.85
StickyNoteFunction · 0.85
IterationNodeFunction · 0.85
AgentFlowNodeFunction · 0.85
StickyNoteFunction · 0.85

Calls 3

deleteConnectedInputFunction · 0.85
collectDescendantsFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected