fix: node connect self (#3194)
This commit is contained in:
parent
3c3fb3cd3f
commit
86707928d4
3 changed files with 85 additions and 5 deletions
|
|
@ -301,6 +301,8 @@ export const useNodesInteractions = () => {
|
|||
target,
|
||||
targetHandle,
|
||||
}) => {
|
||||
if (source === target)
|
||||
return
|
||||
if (getNodesReadOnly())
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -160,8 +160,10 @@ export const useWorkflow = () => {
|
|||
|
||||
if (incomers.length) {
|
||||
incomers.forEach((node) => {
|
||||
callback(node)
|
||||
traverse(node, callback)
|
||||
if (!list.find(n => node.id === n.id)) {
|
||||
callback(node)
|
||||
traverse(node, callback)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -272,7 +274,10 @@ export const useWorkflow = () => {
|
|||
}, [isVarUsedInNodes])
|
||||
|
||||
const isValidConnection = useCallback(({ source, target }: Connection) => {
|
||||
const { getNodes } = store.getState()
|
||||
const {
|
||||
edges,
|
||||
getNodes,
|
||||
} = store.getState()
|
||||
const nodes = getNodes()
|
||||
const sourceNode: Node = nodes.find(node => node.id === source)!
|
||||
const targetNode: Node = nodes.find(node => node.id === target)!
|
||||
|
|
@ -287,7 +292,21 @@ export const useWorkflow = () => {
|
|||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
const hasCycle = (node: Node, visited = new Set()) => {
|
||||
if (visited.has(node.id))
|
||||
return false
|
||||
|
||||
visited.add(node.id)
|
||||
|
||||
for (const outgoer of getOutgoers(node, nodes, edges)) {
|
||||
if (outgoer.id === source)
|
||||
return true
|
||||
if (hasCycle(outgoer, visited))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return !hasCycle(targetNode)
|
||||
}, [store, nodesExtraData])
|
||||
|
||||
const formatTimeFromNow = useCallback((time: number) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue