-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Improvement(duplicate-subflow): add the ability to duplicate subflow with children #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR adds comprehensive functionality for duplicating subflows (loop and parallel blocks) along with all their child blocks and internal connections in Sim's collaborative workflow editor. The feature enables users to quickly replicate complex workflow structures while preserving all nested content, configurations, and block references.
The implementation spans multiple architectural layers:
Backend Infrastructure: New database operations handle atomic creation of parent subflow blocks, child blocks with proper parent-child relationships, and internal edges. The socket server middleware adds duplicate-with-children permissions for admin and write users, with comprehensive validation schemas for the complex operation payload.
Real-time Collaboration: The collaborative workflow system is extended with collaborativeDuplicateSubflow functionality that performs optimistic local updates followed by server synchronization. This ensures all collaborators immediately see duplicated structures with proper ID mapping and reference updates.
Reference Integrity: A new utility (updateBlockReferences) handles updating block ID references within subblock values during duplication, replacing patterns like <oldId. and %oldId. with new mapped IDs to maintain referential integrity in the duplicated structure.
User Interface: The subflow node component adds a duplicate button in the hover toolbar alongside the existing delete button, providing intuitive access to the duplication feature.
The feature integrates seamlessly with Sim's existing collaborative architecture, following established patterns for real-time synchronization, permission management, and atomic database operations. This enhancement significantly improves workflow productivity by allowing users to duplicate complex subflow structures without manual recreation.
Confidence score: 3/5
- This PR introduces complex functionality with potential edge cases around reference mapping and collaborative synchronization
- Score reflects concerns about pattern specificity in reference updates and the complexity of multi-table database operations
- Pay close attention to
lib/workflows/reference-utils.tsand the collaborative workflow hooks for potential reference mapping issues
7 files reviewed, 1 comment
| if (typeof value === 'string') { | ||
| let result = value | ||
| for (const [oldId, newId] of blockIdMapping.entries()) { | ||
| if (result.includes(oldId)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Using includes() check before replacement is inefficient and could cause false positives. A block ID 'abc' would match strings containing 'abc' even when not in reference format.
f0c20a9 to
010753d
Compare
Summary
Added in the ability to duplicate a subflow with the children and sub block values.
Type of Change
Testing
See video
Checklist
Screenshots/Videos
Screen.Recording.2025-09-14.at.11.55.14.PM.mov