Break out element display and click handlers into hooks#73332
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors Sketchlab React Flow canvas logic by extracting element click/selection handling and display element derivation into dedicated hooks, reducing ReactFlowCanvas size and centralizing related behavior.
Changes:
- Added
useElementClickHandlersto encapsulate node/edge click handling, multi-selection state, and selection clearing. - Added
useDisplayElementsto memoize and computedisplayNodes/displayEdges(selection state, accessibility attributes, reconnectability, and styling). - Updated
ReactFlowCanvasto consume these hooks and removed the inlined logic.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/src/sketchlab/reactFlow/hooks/useElementClickHandlers.ts | New hook for node/edge click behavior and multi-selection state management. |
| apps/src/sketchlab/reactFlow/hooks/useDisplayElements.ts | New hook encapsulating memoized computation of rendered nodes/edges (selection, a11y, styling, reconnectability). |
| apps/src/sketchlab/reactFlow/components/ReactFlowCanvas.tsx | Replaces large inlined blocks with the new hooks to simplify the canvas component. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pulls out a couple of large blocks of code into hooks from
ReactFlowCanvas, which was getting unwieldy. One for click handlers and related pieces (node click, edge click, etc.), and one for memoized calculation of nodes and edges to display.Follow-up to a comment in this PR: #73182 (comment)
Testing story
Tested manually that dragging/grouping/rendering of nodes/edges appeared to continue to function as expected.