Skip to content

H-6281, FE-501: Add undo/redo support to Petrinaut demo app#8505

Merged
kube merged 24 commits intomainfrom
cf/h-6281-basic-undoredo-in-petrinaut-demo-app
Mar 9, 2026
Merged

H-6281, FE-501: Add undo/redo support to Petrinaut demo app#8505
kube merged 24 commits intomainfrom
cf/h-6281-basic-undoredo-in-petrinaut-demo-app

Conversation

@kube
Copy link
Collaborator

@kube kube commented Mar 4, 2026

🌟 What is the purpose of this PR?

Adds undo/redo support to the Petrinaut demo app. Having history tracking is useful both for day-to-day model editing and as groundwork for upcoming versioning/diffing features.

🔗 Related links

🔍 What does this change?

  • Adds a useUndoRedo hook in the demo app that manages a stack of full SDCPN snapshots (max 50), with 500ms debounce for drag coalescing and no-op detection
  • Adds an optional undoRedo prop to <Petrinaut>, gated behind a React context — UI only renders when provided
  • Adds undo/redo IconButtons and a version history popover to the top bar
  • Adds Cmd/Ctrl+Z and Cmd/Ctrl+Shift+Z keyboard shortcuts (Monaco editors handle their own undo)
  • Fixes a bug where dragging state persisted in EditorContext after drag end, causing stale positions to reappear after undo
  • Removes window.confirm dialogs before deletions — undo makes them unnecessary

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • modifies an npm-publishable library and I have added a changeset file(s)

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

❓ How to test this?

  1. cd libs/@hashintel/petrinaut && yarn dev
  2. Make edits (add place, move it, rename, add transition, connect arcs)
  3. Cmd+Z should undo each edit; Cmd+Shift+Z should redo
  4. Click the version history clock button — should show timestamped entries
  5. Click an older entry — should restore that state
  6. Drag a node — should create only one history entry (not per-pixel)
  7. Edit code in Monaco — Cmd+Z should undo within Monaco, not the SDCPN
  8. Delete a place/transition — should happen immediately without confirmation, and be undoable

@vercel
Copy link

vercel bot commented Mar 4, 2026

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

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment Mar 9, 2026 5:51pm
petrinaut Ready Ready Preview, Comment Mar 9, 2026 5:51pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
hashdotdesign Ignored Ignored Preview Mar 9, 2026 5:51pm
hashdotdesign-tokens Ignored Ignored Preview Mar 9, 2026 5:51pm

@github-actions github-actions bot added area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Mar 4, 2026
@cursor
Copy link

cursor bot commented Mar 4, 2026

PR Summary

Medium Risk
Adds new optional undo/redo wiring, global keyboard shortcuts, and state/history tracking that can affect editor interaction flow (especially around drag events and navigation). Changes are gated behind an undoRedo prop but also adjust core editor behavior (drag state cleanup, deletion confirmations, menu behavior).

Overview
Adds an optional undoRedo prop to <Petrinaut> that provides undo/redo + history navigation via a new UndoRedoContext, enabling Cmd/Ctrl+Z and Cmd/Ctrl+Shift+Z shortcuts (outside inputs/Monaco) and a top-bar version history menu.

Updates the demo app to track SDCPN snapshot history (useUndoRedo, max 50 entries) with no-op detection, 500ms debounced coalescing for drag-heavy edits, and history reset on net switch.

Fixes a drag bug by clearing per-node dragging state on drag end to avoid stale positions reapplying after undo, removes pre-delete window.confirm prompts (relying on undo instead), and extends Menu with maxHeight (scrolling) and closeOnSelect to support the history popover.

Written by Cursor Bugbot for commit b765bb1. This will update automatically on new commits. Configure here.

@kube kube force-pushed the cf/h-5641-add-input-for-probabilistic-transition-kernels branch from ec0176c to 5a2c7fb Compare March 4, 2026 22:18
@kube kube force-pushed the cf/h-6281-basic-undoredo-in-petrinaut-demo-app branch from 4448449 to 0ad0be7 Compare March 4, 2026 22:18
@augmentcode
Copy link

augmentcode bot commented Mar 4, 2026

🤖 Augment PR Summary

Summary: Adds optional undo/redo support to the Petrinaut demo/editor, including UI controls, keyboard shortcuts, and a simple version-history viewer.

Changes:

  • Introduces a useUndoRedo hook that tracks a bounded snapshot history (max 50) with no-op detection and debounced coalescing.
  • Plumbs an optional undoRedo prop into <Petrinaut> via a new React context, so undo UI only renders when provided.
  • Adds top-bar undo/redo buttons plus a “Version History” popover listing timestamped entries and allowing jumps to prior versions.
  • Registers Cmd/Ctrl+Z and Cmd/Ctrl+Shift+Z shortcuts for SDCPN undo/redo (Monaco editors keep their own undo stack).
  • Fixes a drag-state bug by clearing per-node dragging state on drag end to avoid stale positions being re-applied after undo.

Technical Notes: History entries store full SDCPN snapshots with ISO timestamps; the provider exposes canUndo/canRedo, a current index, and a navigation callback for the popover.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@kube kube changed the title H-6281: Add undo/redo support to Petrinaut demo app H-6281, FE-501: Add undo/redo support to Petrinaut demo app Mar 5, 2026
@kube kube force-pushed the cf/h-6281-basic-undoredo-in-petrinaut-demo-app branch from 0ad0be7 to beffe8b Compare March 5, 2026 18:10
@kube kube force-pushed the cf/h-5641-add-input-for-probabilistic-transition-kernels branch from 5a2c7fb to 363cd18 Compare March 5, 2026 18:10
@kube kube force-pushed the cf/h-6281-basic-undoredo-in-petrinaut-demo-app branch from beffe8b to fdf9954 Compare March 5, 2026 18:25
@kube kube force-pushed the cf/h-5641-add-input-for-probabilistic-transition-kernels branch from 363cd18 to a15bf3d Compare March 5, 2026 18:25
@kube kube changed the base branch from graphite-base/8505 to cf/h-5641-add-input-for-probabilistic-transition-kernels March 9, 2026 12:48
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kube kube changed the base branch from cf/h-5641-add-input-for-probabilistic-transition-kernels to graphite-base/8505 March 9, 2026 16:47
kube and others added 12 commits March 9, 2026 18:17
Consumer-side history management via useUndoRedo hook with full SDCPN
snapshots, 500ms debounce for drag coalescing, and no-op detection.
Petrinaut library accepts optional undoRedo props and renders UI
(toolbar buttons, keyboard shortcuts, version history popover) only
when provided.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…store

After undo, ReactFlow could re-apply the old dragged position because
the draggingStateByNodeId entry persisted with the pre-undo coordinates.
Now the entry is removed when drag completes, so subsequent position
changes correctly bail out via the !lastPosition guard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Now that undo/redo is available, confirmation prompts before deleting
places, transitions, types, equations, parameters, and type elements
are unnecessary friction — users can simply undo if needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove standalone undo/redo icon buttons from the TopBar, keeping only the
version history button. Rewrite VersionHistoryButton to use the Menu component
instead of a custom Popover, with a checkmark icon on the current version and
flex layout for menu item suffixes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Skip undo/redo shortcut when focus is in input/textarea/contentEditable
  so native text undo works in form fields
- Clear debounce timer on undo/redo/goToIndex to prevent history corruption
  when editing within a debounce window after undoing
- Compute new SDCPN synchronously via produce instead of reading from a
  ref in queueMicrotask, which could read stale state

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…hecks

Use the setState updater form in mutatePetriNetDefinition so multiple
calls before a re-render each see the latest state, fixing lost position
updates during multi-node drag end. Merge duplicated isTextInput and
isInputFocused checks into a single variable to prevent drift.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Show HH:mm:ss timestamps instead of labels, add scrollable max height,
and keep menu open on item selection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kube kube force-pushed the cf/h-6281-basic-undoredo-in-petrinaut-demo-app branch from 5604e83 to b765bb1 Compare March 9, 2026 17:44
@kube kube changed the base branch from graphite-base/8505 to cf/h-5641-add-input-for-probabilistic-transition-kernels March 9, 2026 17:44
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Base automatically changed from cf/h-5641-add-input-for-probabilistic-transition-kernels to main March 9, 2026 19:27
@kube kube added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit f6971b7 Mar 9, 2026
48 of 67 checks passed
@hashdotai hashdotai mentioned this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

2 participants