Skip to content

Commit 38b169c

Browse files
committed
fix(duplicate): add workspace ID to prevent cleanup
1 parent 38efb9a commit 38b169c

File tree

1 file changed

+8
-2
lines changed
  • apps/sim/stores/workflows/registry

1 file changed

+8
-2
lines changed

apps/sim/stores/workflows/registry/store.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
737737
* @returns The ID of the newly created workflow
738738
*/
739739
duplicateWorkflow: (sourceId: string) => {
740-
const { workflows } = get()
740+
const { workflows, activeWorkspaceId } = get()
741741
const sourceWorkflow = workflows[sourceId]
742742

743743
if (!sourceWorkflow) {
@@ -754,13 +754,17 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
754754
return null
755755
}
756756

757+
// Get the workspace ID from the source workflow or fall back to active workspace
758+
const workspaceId = sourceWorkflow.workspaceId || (activeWorkspaceId || undefined)
759+
757760
// Generate new workflow metadata
758761
const newWorkflow: WorkflowMetadata = {
759762
id,
760763
name: `${sourceWorkflow.name} (Copy)`,
761764
lastModified: new Date(),
762765
description: sourceWorkflow.description,
763766
color: getNextWorkflowColor(workflows),
767+
workspaceId, // Include the workspaceId in the new workflow
764768
// Do not copy marketplace data
765769
}
766770

@@ -771,6 +775,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
771775
loops: sourceState.loops || {},
772776
isDeployed: false, // Reset deployment status
773777
deployedAt: undefined, // Reset deployment timestamp
778+
workspaceId, // Include workspaceId in state
774779
history: {
775780
past: [],
776781
present: {
@@ -780,6 +785,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
780785
loops: sourceState.loops || {},
781786
isDeployed: false,
782787
deployedAt: undefined,
788+
workspaceId, // Include workspaceId in history state
783789
},
784790
timestamp: Date.now(),
785791
action: 'Duplicated workflow',
@@ -826,7 +832,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
826832
// Trigger sync
827833
useWorkflowStore.getState().sync.forceSync()
828834

829-
logger.info(`Duplicated workflow ${sourceId} to ${id}`)
835+
logger.info(`Duplicated workflow ${sourceId} to ${id} in workspace ${workspaceId || 'none'}`)
830836

831837
return id
832838
},

0 commit comments

Comments
 (0)