Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: fix LOOP_CHILDREN_Z_INDEX (#30719)

wangxiaoleid095bd413b1c
diff --git a/web/app/components/workflow/hooks/use-nodes-interactions.ts b/web/app/components/workflow/hooks/use-nodes-interactions.ts
index afb47d5994c..8277e7dac8a 100644
--- a/web/app/components/workflow/hooks/use-nodes-interactions.ts
+++ b/web/app/components/workflow/hooks/use-nodes-interactions.ts
@@ -1602,6 +1602,7 @@ export const useNodesInteractions = () => {
const offsetX = currentPosition.x - x
const offsetY = currentPosition.y - y
let idMapping: Record<string, string> = {}
+ const parentChildrenToAppend: { parentId: string, childId: string, childType: BlockEnum }[] = []
clipboardElements.forEach((nodeToPaste, index) => {
const nodeType = nodeToPaste.data.type
@@ -1615,6 +1616,7 @@ export const useNodesInteractions = () => {
_isBundled: false,
_connectedSourceHandleIds: [],
_connectedTargetHandleIds: [],
+ _dimmed: false,
title: genNewNodeTitleFromOld(nodeToPaste.data.title),
},
position: {
@@ -1682,27 +1684,24 @@ export const useNodesInteractions = () => {
return
// handle paste to nested block
- if (selectedNode.data.type === BlockEnum.Iteration) {
- newNode.data.isInIteration = true
- newNode.data.iteration_id = selectedNode.data.iteration_id
- newNode.parentId = selectedNode.id
- newNode.positionAbsolute = {
- x: newNode.position.x,
- y: newNode.position.y,
- }
- // set position base on parent node
- newNode.position = getNestedNodePosition(newNode, selectedNode)
- }
- else if (selectedNode.data.type === BlockEnum.Loop) {
- newNode.data.isInLoop = true
- newNode.data.loop_id = selectedNode.data.loop_id
+ if (selectedNode.data.type === BlockEnum.Iteration || selectedNode.data.type === BlockEnum.Loop) {
+ const isIteration = selectedNode.data.type === BlockEnum.Iteration
+
+ newNode.data.isInIteration = isIteration
+ newNode.data.iteration_id = isIteration ? selectedNode.id : undefined
+ newNode.data.isInLoop = !isIteration
+ newNode.data.loop_id = !isIteration ? selectedNode.id : undefined
+
newNode.parentId = selectedNode.id
+ newNode.zIndex = isIteration ? ITERATION_CHILDREN_Z_INDEX : LOOP_CHILDREN_Z_INDEX
newNode.positionAbsolute = {
x: newNode.position.x,
y: newNode.position.y,
}
// set position base on parent node
newNode.position = getNestedNodePosition(newNode, selectedNode)
+ // update parent children array like native add
+ parentChildrenToAppend.push({ parentId: selectedNode.id, childId: newNode.id, childType: newNode.data.type })
}
}
}
@@ -1733,7 +1732,17 @@ export const useNodesInteractions = () => {
}
})
- setNodes([...nodes, ...nodesToPaste])
+ const newNodes = produce(nodes, (draft: Node[]) => {
+ parentChildrenToAppend.forEach(({ parentId, childId, childType }) => {
+ const p = draft.find(n => n.id === parentId)
+ if (p) {
+ p.data._children?.push({ nodeId: childId, nodeType: childType })
+ }
+ })
+ draft.push(...nodesToPaste)
+ })
+
+ setNodes(newNodes)
setEdges([...edges, ...edgesToPaste])
saveStateToHistory(WorkflowHistoryEvent.NodePaste, {
nodeId: nodesToPaste?.[0]?.id,
diff --git a/web/app/components/workflow/nodes/loop/use-interactions.ts b/web/app/components/workflow/nodes/loop/use-interactions.ts
index 006d8f963bd..5e8f6ae36c0 100644
--- a/web/app/components/workflow/nodes/loop/use-interactions.ts
+++ b/web/app/components/workflow/nodes/loop/use-interactions.ts
@@ -7,6 +7,7 @@ import { useCallback } from 'react'
import { useStoreApi } from 'reactflow'
import { useNodesMetaData } from '@/app/components/workflow/hooks'
import {
+ LOOP_CHILDREN_Z_INDEX,
LOOP_PADDING,
} from '../../constants'
import {
@@ -114,9 +115,7 @@ export const useNodeLoopInteractions = () => {
return childrenNodes.map((child, index) => {
const childNodeType = child.data.type as BlockEnum
- const {
- defaultValue,
- } = nodesMetaDataMap![childNodeType]
+ const { defaultValue } = nodesMetaDataMap![childNodeType]
const nodesWithSameType = nodes.filter(node => node.data.type === childNodeType)
const { newNode } = generateNewNode({
type: getNodeCustomTypeByNodeDataType(childNodeType),
@@ -127,15 +126,17 @@ export const useNodeLoopInteractions = () => {
_isBundled: false,
_connectedSourceHandleIds: [],
_connectedTargetHandleIds: [],
+ _dimmed: false,
title: nodesWithSameType.length > 0 ? `${defaultValue.title} ${nodesWithSameType.length + 1}` : defaultValue.title,
+ isInLoop: true,
loop_id: newNodeId,
-
+ type: childNodeType,
},
position: child.position,
positionAbsolute: child.positionAbsolute,
parentId: newNodeId,
extent: child.extent,
- zIndex: child.zIndex,
+ zIndex: LOOP_CHILDREN_Z_INDEX,
})
newNode.id = `${newNodeId}${newNode.id + index}`
return newNode