mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 03:25:57 +08:00
fix: the new node name is generated based on the original node when duplicating (#4675)
This commit is contained in:
parent
eb8dc15ad6
commit
b7f81f0999
@ -33,6 +33,7 @@ import {
|
|||||||
Y_OFFSET,
|
Y_OFFSET,
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
import {
|
import {
|
||||||
|
genNewNodeTitleFromOld,
|
||||||
generateNewNode,
|
generateNewNode,
|
||||||
getNodesConnectedSourceOrTargetHandleIdsMap,
|
getNodesConnectedSourceOrTargetHandleIdsMap,
|
||||||
getTopLeftNodePosition,
|
getTopLeftNodePosition,
|
||||||
@ -1067,7 +1068,6 @@ export const useNodesInteractions = () => {
|
|||||||
const offsetY = currentPosition.y - y
|
const offsetY = currentPosition.y - y
|
||||||
clipboardElements.forEach((nodeToPaste, index) => {
|
clipboardElements.forEach((nodeToPaste, index) => {
|
||||||
const nodeType = nodeToPaste.data.type
|
const nodeType = nodeToPaste.data.type
|
||||||
const nodesWithSameType = nodes.filter(node => node.data.type === nodeType)
|
|
||||||
|
|
||||||
const newNode = generateNewNode({
|
const newNode = generateNewNode({
|
||||||
data: {
|
data: {
|
||||||
@ -1077,7 +1077,7 @@ export const useNodesInteractions = () => {
|
|||||||
_isBundled: false,
|
_isBundled: false,
|
||||||
_connectedSourceHandleIds: [],
|
_connectedSourceHandleIds: [],
|
||||||
_connectedTargetHandleIds: [],
|
_connectedTargetHandleIds: [],
|
||||||
title: nodesWithSameType.length > 0 ? `${t(`workflow.blocks.${nodeType}`)} ${nodesWithSameType.length + 1}` : t(`workflow.blocks.${nodeType}`),
|
title: genNewNodeTitleFromOld(nodeToPaste.data.title),
|
||||||
},
|
},
|
||||||
position: {
|
position: {
|
||||||
x: nodeToPaste.position.x + offsetX,
|
x: nodeToPaste.position.x + offsetX,
|
||||||
|
@ -289,6 +289,20 @@ export const generateNewNode = ({ data, position, id, zIndex, ...rest }: Omit<No
|
|||||||
} as Node
|
} as Node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const genNewNodeTitleFromOld = (oldTitle: string) => {
|
||||||
|
const regex = /^(.+?)\s*\((\d+)\)\s*$/
|
||||||
|
const match = oldTitle.match(regex)
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
const title = match[1]
|
||||||
|
const num = parseInt(match[2], 10)
|
||||||
|
return `${title} (${num + 1})`
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return `${oldTitle} (1)`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const getValidTreeNodes = (nodes: Node[], edges: Edge[]) => {
|
export const getValidTreeNodes = (nodes: Node[], edges: Edge[]) => {
|
||||||
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
|
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user