From 4962b2c4605eef65c5ea5ec3236abe2c40ca429d Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Wed, 4 Sep 2024 13:27:01 +0800 Subject: [PATCH] check node edge --- web/app/components/workflow/hooks/use-workflow.ts | 15 +++++++++++++-- web/app/components/workflow/utils.ts | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/web/app/components/workflow/hooks/use-workflow.ts b/web/app/components/workflow/hooks/use-workflow.ts index 3e4e56c4b5..460e36ae60 100644 --- a/web/app/components/workflow/hooks/use-workflow.ts +++ b/web/app/components/workflow/hooks/use-workflow.ts @@ -29,7 +29,9 @@ import { useStore, useWorkflowStore, } from '../store' -import { getParallelInfo } from '../utils' +import { + getParallelInfo, +} from '../utils' import { PARALLEL_DEPTH_LIMIT, PARALLEL_LIMIT, @@ -299,7 +301,13 @@ export const useWorkflow = () => { }, [store, workflowStore, t]) const checkNestedParallelLimit = useCallback((nodes: Node[], edges: Edge[], parentNodeId?: string) => { - const parallelList = getParallelInfo(nodes, edges, parentNodeId) + const { + parallelList, + hasAbnormalEdges, + } = getParallelInfo(nodes, edges, parentNodeId) + + if (hasAbnormalEdges) + return false for (let i = 0; i < parallelList.length; i++) { const parallel = parallelList[i] @@ -329,6 +337,9 @@ export const useWorkflow = () => { if (sourceNode.type === CUSTOM_NOTE_NODE || targetNode.type === CUSTOM_NOTE_NODE) return false + if (sourceNode.parentId !== targetNode.parentId) + return false + if (sourceNode && targetNode) { const sourceNodeAvailableNextNodes = nodesExtraData[sourceNode.data.type].availableNextNodes const targetNodeAvailablePrevNodes = [...nodesExtraData[targetNode.data.type].availablePrevNodes, BlockEnum.Start] diff --git a/web/app/components/workflow/utils.ts b/web/app/components/workflow/utils.ts index e68709fb31..3801da813e 100644 --- a/web/app/components/workflow/utils.ts +++ b/web/app/components/workflow/utils.ts @@ -629,6 +629,7 @@ export const getParallelInfo = (nodes: Node[], edges: Edge[], parentNodeId?: str const parallelList = [] as ParallelInfoItem[] const nextNodeHandles = [{ node: startNode, handle: 'source' }] + let hasAbnormalEdges = false const traverse = (firstNodeHandle: NodeHandle) => { const nodeEdgesSet = {} as Record> @@ -681,6 +682,10 @@ export const getParallelInfo = (nodes: Node[], edges: Edge[], parentNodeId?: str outgoers.forEach((outgoer) => { const outgoerConnectedEdges = getConnectedEdges([outgoer], edges).filter(edge => edge.source === outgoer.id) const sourceEdgesGroup = groupBy(outgoerConnectedEdges, 'sourceHandle') + const incomers = getIncomers(outgoer, nodes, edges) + + if (outgoers.length > 1 && incomers.length > 1) + hasAbnormalEdges = true Object.keys(sourceEdgesGroup).forEach((sourceHandle) => { nextHandles.push({ node: outgoer, handle: sourceHandle }) @@ -746,5 +751,8 @@ export const getParallelInfo = (nodes: Node[], edges: Edge[], parentNodeId?: str traverse(nodeHandle) } - return parallelList + return { + parallelList, + hasAbnormalEdges, + } }