feat(duplicate): duplicate variables when duplicating a workflow#1254
feat(duplicate): duplicate variables when duplicating a workflow#1254waleedlatif1 merged 2 commits intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR implements variable duplication when duplicating workflows, addressing a UX inconsistency where previously only the workflow structure was copied without its associated variables. The changes span three key layers:
Backend API Enhancement: The workflow duplication endpoint (/api/workflows/[id]/duplicate/route.ts) now properly creates new Variable objects with remapped UUIDs and correct workflow references during the duplication process. This ensures each duplicated workflow gets its own independent set of variables rather than sharing references with the source workflow.
Store Interface Extension: A new loadForWorkflow method is added to the VariablesStore interface (stores/panel/variables/types.ts) to support API-based variable loading for specific workflows.
Store Implementation: The variables store (stores/panel/variables/store.ts) implements the loadForWorkflow method, which fetches variables from the API and hydrates the store while preserving variables from other workflows. The method includes proper error handling and loading states.
Client-side Integration: The workflow registry store (stores/workflows/registry/store.ts) now calls the new loadForWorkflow method after successful workflow duplication to ensure the client-side store is immediately synchronized with the duplicated variables.
This creates a seamless experience where duplicated workflows appear with all their variables intact, maintaining referential integrity and providing immediate access to the copied variable state without requiring page refreshes or navigation.
Confidence score: 4/5
- This PR is safe to merge with low risk as it adds new functionality without modifying existing workflows
- Score reflects well-structured implementation with proper error handling and clear separation of concerns across API, store interface, and client integration
- Pay close attention to the API route duplication logic to ensure variable ID remapping works correctly in all edge cases
4 files reviewed, 2 comments
…studioai#1254) * feat(duplicate): duplicate variables when duplicating a workflow * better typing
Summary
duplicate variables when duplicating a workflow, previously we did not duplicate the variables along with the workflow itself but now we do. makes for a more cohesive and consistent UX, where the entire workflow state is picked up and copied over, including any variable references.
Type of Change
Testing
Tested manually, see below.
Checklist
Screenshots/Videos
Screen.Recording.2025-09-04.at.8.46.18.PM.mov