Skip to content

feat(undo-redo): undo/redo for canvas editing#1392

Merged
icecrasher321 merged 11 commits intostagingfrom
feat/undo-redo-stack
Sep 22, 2025
Merged

feat(undo-redo): undo/redo for canvas editing#1392
icecrasher321 merged 11 commits intostagingfrom
feat/undo-redo-stack

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Sep 20, 2025

Summary

Undo/Redo for canvas editing.

Type of Change

  • New feature

Testing

Screen.Recording.2025-09-20.at.11.42.47.AM.mov

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
Copy link

vercel bot commented Sep 20, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 20, 2025 7:41pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 20, 2025 7:41pm

@vercel vercel bot temporarily deployed to Preview – docs September 20, 2025 18:41 Inactive
@icecrasher321 icecrasher321 marked this pull request as ready for review September 20, 2025 18:41
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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 any types, and complex state synchronization logic that could lead to runtime errors
  • Pay close attention to stores/undo-redo/utils.ts and hooks/use-undo-redo.ts for 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

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs September 20, 2025 19:37 Inactive
@icecrasher321 icecrasher321 merged commit 2f97782 into staging Sep 22, 2025
6 checks passed
waleedlatif1 pushed a commit that referenced this pull request Sep 23, 2025
* 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
@waleedlatif1 waleedlatif1 deleted the feat/undo-redo-stack branch September 25, 2025 22:40
Sign up for free to 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