fix: the new node name is generated based on the original node when duplicating (#4675)

This commit is contained in:
非法操作
2024-05-28 13:50:43 +08:00
committed by GitHub
parent eb8dc15ad6
commit b7f81f0999
2 changed files with 16 additions and 2 deletions

View File

@@ -289,6 +289,20 @@ export const generateNewNode = ({ data, position, id, zIndex, ...rest }: Omit<No
} 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[]) => {
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)