feat(undo-redo): undo/redo for canvas editing#1392
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR implements a comprehensive undo/redo system for workflow canvas editing operations. The implementation introduces a sophisticated command pattern-based architecture that tracks user operations and enables reversible editing actions.
The core changes include:
-
New Undo-Redo Store: A Zustand store (
/stores/undo-redo/) that manages operation stacks per workflow and user, with intelligent features like move operation coalescing (merging consecutive moves of the same block) and capacity management (15 operations by default). The store includes persistence via localStorage and pruning functionality to maintain stack integrity. -
Operation Type System: Comprehensive TypeScript definitions covering 11 operation types including add/remove blocks, add/remove edges, move operations, duplicate operations, and subflow management. Each operation includes both the forward action and its inverse for proper undo functionality.
-
Integration with Collaborative Workflow: The existing collaborative workflow hook now records operations at strategic points throughout the editing lifecycle, with sophisticated logic to handle nested blocks, edge relationships, and prevent recording during undo/redo playback to avoid infinite loops.
-
Floating Controls UI: A new floating control bar component provides users with direct access to zoom controls and undo/redo buttons, complete with keyboard shortcuts (Ctrl/Cmd+Z, Ctrl/Cmd+Shift+Z) and visual feedback through disabled states.
-
User Settings Integration: Added a new "Floating controls" setting in the general settings modal, allowing users to toggle the visibility of the floating control bar while maintaining their preference across sessions.
-
Utility Functions: Extracted block naming utilities (
normalizeBlockName,getUniqueBlockName) to shared modules for consistent naming behavior across operations, particularly important for block duplication during undo/redo scenarios.
The system handles complex scenarios like nested subflows, maintains consistency between multiple stores (workflow, subblock, operation queue), and synchronizes changes with the server while supporting collaborative editing environments where multiple users can maintain separate operation histories.
PR Description Notes:
- The PR description is incomplete with placeholder text and no actual description of the changes
- No issue number is referenced despite the "Fixes #(issue)" placeholder
- All checkboxes in the PR template remain unchecked
- No testing information or screenshots are provided
Confidence score: 2/5
- This PR introduces significant complexity and potential stability issues that require careful review before merging
- Score reflects concerns about incomplete inverse operations, heavy use of
anytypes, and complex state synchronization logic that could lead to runtime errors - Pay close attention to
stores/undo-redo/utils.tsandhooks/use-undo-redo.tsfor critical implementation flaws
Context used:
Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)
13 files reviewed, 11 comments
...pp/workspace/[workspaceId]/w/[workflowId]/components/floating-controls/floating-controls.tsx
Show resolved
Hide resolved
...pp/workspace/[workspaceId]/w/[workflowId]/components/floating-controls/floating-controls.tsx
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx
Outdated
Show resolved
Hide resolved
* feat(undo-redo): support undo-redo on canvas * fix zoom live subscribe * progress * fix subflows * progress * fix subflow logic * pruning stacks * centralize unique naming logic * fix type issues * address greptile comments * remove timeouts
Summary
Undo/Redo for canvas editing.
Type of Change
Testing
Screen.Recording.2025-09-20.at.11.42.47.AM.mov
Checklist