Skip to content

Commit 7013b7f

Browse files
committed
fix(action-bar): duplicate subflows with children
1 parent fb8868c commit 7013b7f

File tree

1 file changed

+15
-21
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar

1 file changed

+15
-21
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar.tsx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { isInputDefinitionTrigger } from '@/lib/workflows/triggers/input-definit
66
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
77
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
88
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
9-
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
10-
import { getUniqueBlockName, prepareDuplicateBlockState } from '@/stores/workflows/utils'
119
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1210

1311
const DEFAULT_DUPLICATE_OFFSET = { x: 50, y: 50 }
@@ -48,29 +46,25 @@ export const ActionBar = memo(
4846
collaborativeBatchToggleBlockEnabled,
4947
collaborativeBatchToggleBlockHandles,
5048
} = useCollaborativeWorkflow()
51-
const { activeWorkflowId, setPendingSelection } = useWorkflowRegistry()
49+
const { setPendingSelection } = useWorkflowRegistry()
5250

5351
const handleDuplicateBlock = useCallback(() => {
54-
const blocks = useWorkflowStore.getState().blocks
55-
const sourceBlock = blocks[blockId]
56-
if (!sourceBlock) return
52+
const { copyBlocks, preparePasteData } = useWorkflowRegistry.getState()
53+
copyBlocks([blockId])
5754

58-
const newId = crypto.randomUUID()
59-
const newName = getUniqueBlockName(sourceBlock.name, blocks)
60-
const subBlockValues =
61-
useSubBlockStore.getState().workflowValues[activeWorkflowId || '']?.[blockId] || {}
55+
const pasteData = preparePasteData(DEFAULT_DUPLICATE_OFFSET)
56+
if (!pasteData) return
6257

63-
const { block, subBlockValues: filteredValues } = prepareDuplicateBlockState({
64-
sourceBlock,
65-
newId,
66-
newName,
67-
positionOffset: DEFAULT_DUPLICATE_OFFSET,
68-
subBlockValues,
69-
})
70-
71-
setPendingSelection([newId])
72-
collaborativeBatchAddBlocks([block], [], {}, {}, { [newId]: filteredValues })
73-
}, [blockId, activeWorkflowId, collaborativeBatchAddBlocks, setPendingSelection])
58+
const blocks = Object.values(pasteData.blocks)
59+
setPendingSelection(blocks.map((b) => b.id))
60+
collaborativeBatchAddBlocks(
61+
blocks,
62+
pasteData.edges,
63+
pasteData.loops,
64+
pasteData.parallels,
65+
pasteData.subBlockValues
66+
)
67+
}, [blockId, collaborativeBatchAddBlocks, setPendingSelection])
7468

7569
const { isEnabled, horizontalHandles, parentId, parentType } = useWorkflowStore(
7670
useCallback(

0 commit comments

Comments
 (0)