Skip to content

H-5655: Refactor selection logic and migrate to @xyflow/react v12#8523

Merged
kube merged 25 commits intomainfrom
cf/h-5655-refactor-selection-logic
Mar 12, 2026
Merged

H-5655: Refactor selection logic and migrate to @xyflow/react v12#8523
kube merged 25 commits intomainfrom
cf/h-5655-refactor-selection-logic

Conversation

@kube
Copy link
Collaborator

@kube kube commented Mar 7, 2026

🌟 What is the purpose of this PR?

Refactor the selection logic in Petrinaut and migrate to @xyflow/react v12. This centralizes selection state in EditorContext, adds multi-selection support, and improves keyboard shortcut handling.

🔗 Related links

🔍 What does this change?

  • Migrate to @xyflow/react v12 with updated APIs and types
  • Centralize selection state in EditorContext with isSelected/hasSelection helpers
  • Add multi-selection support — click nodes/arcs with modifier keys, with a new multi-selection panel in Properties
  • Add arc properties panel for viewing/editing selected arcs
  • Make Delete/Backspace work globally for all selected item types (places, transitions, arcs)
  • Batch multi-node drag position commits into single atomic mutations
  • Highlight selected nodes in MiniMap
  • Add partial selection setting in viewport settings dialog
  • Remove browser tests and related dependencies
  • Fix stale selection race conditions and restrict arc selection to click-only
  • Add selection cleanup hook to handle removed items

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

⚠️ Known issues

  • Selection synchronization between EditorContext and ReactFlow's internal state still needs enhancements
  • Selection logic is functional but not perfect — will need reworking later

🐾 Next steps

  • Comprehensive testing pass needed once dependent features are built
  • Further refinement of selection sync between EditorContext and ReactFlow
  • This provides a solid foundation to build on, but the selection system will need another iteration

🛡 What tests cover this?

  • No automated tests — browser tests were removed as part of this PR

❓ How to test this?

  1. Checkout the branch / view the deployment
  2. Open a Petri net in the editor
  3. Select nodes, transitions, and arcs — verify single and multi-selection works
  4. Use Delete/Backspace to remove selected items
  5. Drag multiple selected nodes and verify positions update atomically
  6. Check MiniMap highlights selected nodes

@vercel
Copy link

vercel bot commented Mar 7, 2026

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

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

@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Mar 7, 2026
@kube kube changed the base branch from cf/h-6281-basic-undoredo-in-petrinaut-demo-app to graphite-base/8523 March 9, 2026 10:38
@kube kube force-pushed the graphite-base/8523 branch from 9b3ab34 to 5604e83 Compare March 9, 2026 12:48
@kube kube force-pushed the cf/h-5655-refactor-selection-logic branch from a4cb46c to 4043333 Compare March 9, 2026 12:48
@kube kube changed the base branch from graphite-base/8523 to cf/h-6281-basic-undoredo-in-petrinaut-demo-app March 9, 2026 12:48
@kube kube changed the base branch from cf/h-6281-basic-undoredo-in-petrinaut-demo-app to graphite-base/8523 March 9, 2026 17:44
@kube kube force-pushed the graphite-base/8523 branch from 5604e83 to 9f3aa5b Compare March 9, 2026 22:09
@kube kube force-pushed the cf/h-5655-refactor-selection-logic branch from 4043333 to 47518e4 Compare March 9, 2026 22:09
@kube kube changed the base branch from graphite-base/8523 to main March 9, 2026 22:09
@github-actions github-actions bot added the area/infra Relates to version control, CI, CD or IaC (area) label Mar 9, 2026
@kube kube force-pushed the cf/h-5655-refactor-selection-logic branch from 47518e4 to 4a51729 Compare March 9, 2026 23:47
@github-actions github-actions bot removed the area/infra Relates to version control, CI, CD or IaC (area) label Mar 9, 2026
@kube kube marked this pull request as ready for review March 9, 2026 23:52
@cursor
Copy link

cursor bot commented Mar 9, 2026

PR Summary

Medium Risk
Touches core editor interaction paths (selection, deletion, drag/position commits) while also migrating the underlying graph library to @xyflow/react v12, so regressions in canvas UX and coordinate handling are possible.

Overview
Migrates the SDCPN canvas integration from reactflow to @xyflow/react v12 (imports, instance APIs, store lookups, selection configuration) and updates node/edge typing accordingly.

Refactors editor selection into a typed selection: Map in EditorContext with isSelected/hasSelection helpers, adding multi-select (modifier-click + box select for nodes) and global Delete/Backspace handling via keyboard shortcuts.

Adds new PropertiesPanel flows for arc selection (ArcProperties with weight edit + delete) and multi-selection (MultiSelectionPanel with grouped summary + bulk delete), plus a useSelectionCleanup hook to remove stale selections after model mutations.

Adjusts coordinate semantics to consistently store SDCPN node centers while @xyflow/react uses top-left positions (layout + drag commits), introduces classic/compact node dimensions, and makes node drag-end position commits atomic. Also adds a user setting for SelectionMode.Partial vs full selection and highlights selected nodes in the minimap.

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

@github-actions github-actions bot added the area/infra Relates to version control, CI, CD or IaC (area) label Mar 9, 2026
kube and others added 17 commits March 12, 2026 18:30
Add a `partialSelection` user setting (default true) that controls
whether drag-to-select picks up partially intersected nodes. Refactor
the viewport settings dialog to use a reusable SettingRow grid component.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove FocusNodeRegistrar and all focusNode/registerFocusNode plumbing
from the editor context. Viewport centering on node selection will be
revisited as a dedicated feature.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Selected nodes render with a light blue fill and stroke in the MiniMap.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move deletion keyboard handling from SDCPNView's onKeyDown to the global
keyboard shortcuts hook using useEffectEvent, so Delete/Backspace works
from anywhere in Petrinaut. Extend deleteItemsByIds to also handle types,
differential equations, and parameters.

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

Expose `isSelected(id)` and `hasSelection` from EditorContext so consumers
no longer need direct access to the SelectionMap for simple lookups. Change
`deleteItemsByIds` to accept typed SelectionMap, enabling it to partition
by item type and skip irrelevant collections. Migrate all 12 UI consumers.

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

- Convert ELK top-left positions to center coordinates in calculateGraphLayout,
  matching the convention used by useSdcpnToReactFlow and useApplyNodeChanges
- Accept dims parameter instead of using deprecated nodeDimensions alias, so
  layout uses correct dimensions for compact vs classic mode
- Fix selection guards to check base map instead of prevSelection, preventing
  previously-selected canvas nodes from being dropped during box-select when
  non-canvas items are selected
- Re-add @testing-library/dom and @testing-library/react devDependencies needed
  by unit tests that were incorrectly removed with browser test cleanup

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

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

When a type or differential equation is deleted, clear references to it
from places and equations to avoid unresolvable IDs in the SDCPN JSON.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… fix drag-end cleanup

- Stabilize setSelection with useCallback to prevent useSelectionCleanup
  effect from re-running on every render
- Remove unused addToSelection and removeFromSelection
- Add early return in selection updater when nothing changed to avoid
  unnecessary re-renders
- Always clear per-node dragging state on drag-end even without position

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Fix All in Cursor

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

@kube
Copy link
Collaborator Author

kube commented Mar 12, 2026

Re: cursor bot's "Selection cleanup uses stale state" — valid point. Switched to setSelection((prev) => ...) functional updater form so the cleanup always operates on the latest selection state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deps Relates to third-party dependencies (area) 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