Browse Source

fix: incorrect duplication when no target node is selected (#7539)

tags/0.7.2
edo1z 1 year ago
parent
commit
0a7ab9a47d
No account linked to committer's email address

+ 20
- 10
web/app/components/workflow/hooks/use-nodes-interactions.ts View File

handleNodeSelect(node.id) handleNodeSelect(node.id)
}, [workflowStore, handleNodeSelect]) }, [workflowStore, handleNodeSelect])


const handleNodesCopy = useCallback(() => {
const handleNodesCopy = useCallback((nodeId?: string) => {
if (getNodesReadOnly()) if (getNodesReadOnly())
return return


} = store.getState() } = store.getState()


const nodes = getNodes() const nodes = getNodes()
const bundledNodes = nodes.filter(node => node.data._isBundled && node.data.type !== BlockEnum.Start && !node.data.isInIteration)


if (bundledNodes.length) {
setClipboardElements(bundledNodes)
return
if (nodeId) {
// If nodeId is provided, copy that specific node
const nodeToCopy = nodes.find(node => node.id === nodeId && node.data.type !== BlockEnum.Start)
if (nodeToCopy)
setClipboardElements([nodeToCopy])
} }
else {
// If no nodeId is provided, fall back to the current behavior
const bundledNodes = nodes.filter(node => node.data._isBundled && node.data.type !== BlockEnum.Start && !node.data.isInIteration)


const selectedNode = nodes.find(node => node.data.selected && node.data.type !== BlockEnum.Start)
if (bundledNodes.length) {
setClipboardElements(bundledNodes)
return
}


if (selectedNode)
setClipboardElements([selectedNode])
const selectedNode = nodes.find(node => node.data.selected && node.data.type !== BlockEnum.Start)

if (selectedNode)
setClipboardElements([selectedNode])
}
}, [getNodesReadOnly, store, workflowStore]) }, [getNodesReadOnly, store, workflowStore])


const handleNodesPaste = useCallback(() => { const handleNodesPaste = useCallback(() => {
} }
}, [getNodesReadOnly, workflowStore, store, reactflow, saveStateToHistory, handleSyncWorkflowDraft, handleNodeIterationChildrenCopy]) }, [getNodesReadOnly, workflowStore, store, reactflow, saveStateToHistory, handleSyncWorkflowDraft, handleNodeIterationChildrenCopy])


const handleNodesDuplicate = useCallback(() => {
const handleNodesDuplicate = useCallback((nodeId?: string) => {
if (getNodesReadOnly()) if (getNodesReadOnly())
return return


handleNodesCopy()
handleNodesCopy(nodeId)
handleNodesPaste() handleNodesPaste()
}, [getNodesReadOnly, handleNodesCopy, handleNodesPaste]) }, [getNodesReadOnly, handleNodesCopy, handleNodesPaste])



+ 1
- 1
web/app/components/workflow/nodes/_base/components/panel-operator/panel-operator-popup.tsx View File

className='flex items-center justify-between px-3 h-8 text-sm text-gray-700 rounded-lg cursor-pointer hover:bg-gray-50' className='flex items-center justify-between px-3 h-8 text-sm text-gray-700 rounded-lg cursor-pointer hover:bg-gray-50'
onClick={() => { onClick={() => {
onClosePopup() onClosePopup()
handleNodesDuplicate()
handleNodesDuplicate(id)
}} }}
> >
{t('workflow.common.duplicate')} {t('workflow.common.duplicate')}

Loading…
Cancel
Save