Skip to content

feat(duplicate): added folder duplication, add duplicate to sidebar context menu - #1902

Merged
waleedlatif1 merged 1 commit into
stagingfrom
feat/duplicate
Nov 11, 2025
Merged

feat(duplicate): added folder duplication, add duplicate to sidebar context menu#1902
waleedlatif1 merged 1 commit into
stagingfrom
feat/duplicate

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • added folder duplication
  • add duplicate to sidebar context menu
  • add helper for duplication that is reused by both entiries
  • added hooks for all 4 permutations of workflow/folder and delete/duplicate

Type of Change

  • New feature

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Nov 11, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedNov 11, 2025 9:34pm

@waleedlatif1
waleedlatif1 marked this pull request as ready for review November 11, 2025 21:38
@greptile-apps

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR adds comprehensive folder duplication functionality to match existing workflow duplication capabilities. The implementation includes recursive folder structure duplication and workflow duplication within those folders.

Key Changes:

  • Created reusable duplicateWorkflow helper in lib/workflows/duplicate.ts that handles workflows, blocks, edges, subflows, and variables with proper ID remapping
  • Added /api/folders/[id]/duplicate endpoint that duplicates folder hierarchies recursively and then duplicates all workflows within
  • Added /api/workflows/[id]/duplicate endpoint that uses the shared helper
  • Created useDuplicateFolder and useDuplicateWorkflow hooks following the same pattern as delete hooks
  • Added useDeleteFolder hook to extract deletion logic from component
  • Updated ContextMenu component to support optional duplicate action
  • Integrated duplicate functionality into both folder-item and workflow-item components
  • Added duplicateFolder method to folder store that refreshes state after duplication

Implementation Quality:

  • Follows consistent patterns with existing delete hooks
  • Proper transaction handling for folder structure duplication
  • Comprehensive permission checks
  • Good error handling and logging throughout
  • Supports both single and bulk operations
  • Properly clears selection after operations
  • Navigates to duplicated workflow (single workflow duplication only)

Confidence Score: 5/5

  • This PR is safe to merge - well-structured implementation following established patterns with proper error handling
  • The implementation follows consistent patterns throughout the codebase, includes comprehensive permission checks, proper transaction handling, and thorough error handling. The shared helper function promotes code reuse, and the hooks pattern matches existing delete functionality. All edge cases are handled appropriately including ID remapping, parent relationships, and selection clearing.
  • No files require special attention

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/lib/workflows/duplicate.ts5/5Core helper function for workflow duplication with blocks, edges, subflows, and variables - properly handles ID remapping and permissions
apps/sim/app/api/folders/[id]/duplicate/route.ts5/5API endpoint for folder duplication - recursively duplicates folder structure then workflows, with proper permissions and error handling
apps/sim/app/api/workflows/[id]/duplicate/route.ts5/5API endpoint for workflow duplication - delegates to shared helper function with proper validation and error handling
apps/sim/app/workspace/[workspaceId]/w/hooks/use-duplicate-folder.ts5/5React hook for folder duplication - handles single/bulk operations with loading state and selection clearing
apps/sim/app/workspace/[workspaceId]/w/hooks/use-duplicate-workflow.ts5/5React hook for workflow duplication - handles single/bulk operations with navigation to duplicated workflow
apps/sim/stores/folders/store.ts5/5Added duplicateFolder method to store - calls API and refreshes folders/workflows after duplication

Sequence Diagram

sequenceDiagram
participant User
participant UI as Folder/Workflow Item
participant Hook as useDuplicate Hook
participant Store as Folder/Workflow Store
participant API as Duplicate API
participant Helper as duplicateWorkflow Helper
participant DB as Database
User->>UI: Right-click & select "Duplicate"
UI->>Hook: handleDuplicate()
Hook->>Hook: Check isDuplicating state
Hook->>Store: duplicateFolder/Workflow(id)
alt Folder Duplication
Store->>API: POST /api/folders/{id}/duplicate
API->>DB: Check permissions & get source folder
API->>DB: BEGIN TRANSACTION
API->>DB: Create root folder with new ID
API->>API: duplicateFolderStructure (recursive)
loop For each child folder
API->>DB: Create child folder
API->>API: Recurse for nested children
end
DB-->>API: COMMIT (folder structure complete)
API->>API: duplicateWorkflowsInFolderTree
loop For each folder in mapping
API->>DB: Get workflows in folder
loop For each workflow
API->>Helper: duplicateWorkflow()
Helper->>DB: BEGIN TRANSACTION
Helper->>DB: Create workflow with new ID
Helper->>DB: Copy blocks (remap IDs & parentIds)
Helper->>DB: Copy edges (remap block references)
Helper->>DB: Copy subflows (remap IDs & node refs)
DB-->>Helper: COMMIT
Helper-->>API: Return new workflow ID
end
end
API-->>Store: Return folder stats
else Workflow Duplication
Store->>API: POST /api/workflows/{id}/duplicate
API->>Helper: duplicateWorkflow()
Helper->>DB: Check permissions & get source
Helper->>DB: BEGIN TRANSACTION
Helper->>DB: Create workflow with new ID
Helper->>DB: Copy blocks (remap IDs)
Helper->>DB: Copy edges (remap references)
Helper->>DB: Copy subflows (remap IDs)
DB-->>Helper: COMMIT
Helper-->>API: Return new workflow
API-->>Store: Return workflow metadata
end
Store->>Store: Refresh folders/workflows
Store-->>Hook: Return new ID(s)
Hook->>Store: clearSelection()
alt Single Workflow Duplication
Hook->>UI: Navigate to new workflow
end
Hook-->>UI: Complete
UI-->>User: Show duplicated item
Loading

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
waleedlatif1 merged commit 77d897d into stagingNov 11, 2025
9 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/duplicate branch November 11, 2025 22:05
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@waleedlatif1