Просмотр исходного кода

fix: the edges between the nodes inside the copied iteration node are… (#12692)

tags/1.0.1
JonSnow 8 месяцев назад
Родитель
Сommit
1eb072fd43
Аккаунт пользователя с таким Email не найден

+ 31
- 1
web/app/components/workflow/hooks/use-nodes-interactions.ts Просмотреть файл

const { const {
getNodes, getNodes,
setNodes, setNodes,
edges,
setEdges,
} = store.getState() } = store.getState()


const nodesToPaste: Node[] = [] const nodesToPaste: Node[] = []
const edgesToPaste: Edge[] = []
const nodes = getNodes() const nodes = getNodes()


if (clipboardElements.length) { if (clipboardElements.length) {
const currentPosition = screenToFlowPosition({ x: mousePosition.pageX, y: mousePosition.pageY }) const currentPosition = screenToFlowPosition({ x: mousePosition.pageX, y: mousePosition.pageY })
const offsetX = currentPosition.x - x const offsetX = currentPosition.x - x
const offsetY = currentPosition.y - y const offsetY = currentPosition.y - y
let idMapping: Record<string, string> = {}
clipboardElements.forEach((nodeToPaste, index) => { clipboardElements.forEach((nodeToPaste, index) => {
const nodeType = nodeToPaste.data.type const nodeType = nodeToPaste.data.type


newIterationStartNode!.parentId = newNode.id; newIterationStartNode!.parentId = newNode.id;
(newNode.data as IterationNodeType).start_node_id = newIterationStartNode!.id (newNode.data as IterationNodeType).start_node_id = newIterationStartNode!.id


newChildren = handleNodeIterationChildrenCopy(nodeToPaste.id, newNode.id)
const oldIterationStartNode = nodes
.find(n => n.parentId === nodeToPaste.id && n.type === CUSTOM_ITERATION_START_NODE)
idMapping[oldIterationStartNode!.id] = newIterationStartNode!.id

const { copyChildren, newIdMapping } = handleNodeIterationChildrenCopy(nodeToPaste.id, newNode.id, idMapping)
newChildren = copyChildren
idMapping = newIdMapping
newChildren.forEach((child) => { newChildren.forEach((child) => {
newNode.data._children?.push(child.id) newNode.data._children?.push(child.id)
}) })
nodesToPaste.push(...newChildren) nodesToPaste.push(...newChildren)
}) })


edges.forEach((edge) => {
const sourceId = idMapping[edge.source]
const targetId = idMapping[edge.target]

if (sourceId && targetId) {
const newEdge: Edge = {
...edge,
id: `${sourceId}-${edge.sourceHandle}-${targetId}-${edge.targetHandle}`,
source: sourceId,
target: targetId,
data: {
...edge.data,
_connectedNodeIsSelected: false,
},
}
edgesToPaste.push(newEdge)
}
})

setNodes([...nodes, ...nodesToPaste]) setNodes([...nodes, ...nodesToPaste])
setEdges([...edges, ...edgesToPaste])
saveStateToHistory(WorkflowHistoryEvent.NodePaste) saveStateToHistory(WorkflowHistoryEvent.NodePaste)
handleSyncWorkflowDraft() handleSyncWorkflowDraft()
} }

+ 9
- 2
web/app/components/workflow/nodes/iteration/use-interactions.ts Просмотреть файл

handleNodeIterationRerender(parentId) handleNodeIterationRerender(parentId)
}, [store, handleNodeIterationRerender]) }, [store, handleNodeIterationRerender])


const handleNodeIterationChildrenCopy = useCallback((nodeId: string, newNodeId: string) => {
const handleNodeIterationChildrenCopy = useCallback((nodeId: string, newNodeId: string, idMapping: Record<string, string>) => {
const { getNodes } = store.getState() const { getNodes } = store.getState()
const nodes = getNodes() const nodes = getNodes()
const childrenNodes = nodes.filter(n => n.parentId === nodeId && n.type !== CUSTOM_ITERATION_START_NODE) const childrenNodes = nodes.filter(n => n.parentId === nodeId && n.type !== CUSTOM_ITERATION_START_NODE)
const newIdMapping = { ...idMapping }


return childrenNodes.map((child, index) => {
const copyChildren = childrenNodes.map((child, index) => {
const childNodeType = child.data.type as BlockEnum const childNodeType = child.data.type as BlockEnum
const nodesWithSameType = nodes.filter(node => node.data.type === childNodeType) const nodesWithSameType = nodes.filter(node => node.data.type === childNodeType)
const { newNode } = generateNewNode({ const { newNode } = generateNewNode({
zIndex: child.zIndex, zIndex: child.zIndex,
}) })
newNode.id = `${newNodeId}${newNode.id + index}` newNode.id = `${newNodeId}${newNode.id + index}`
newIdMapping[child.id] = newNode.id
return newNode return newNode
}) })

return {
copyChildren,
newIdMapping,
}
}, [store, t]) }, [store, t])


return { return {

Загрузка…
Отмена
Сохранить