fix(graph): address high-severity findings from PR #88 review#189
fix(graph): address high-severity findings from PR #88 review#189damienriehl wants to merge 3 commits intoentity-graph-prfrom
Conversation
Previously OntologyNode declared `onNavigate` / `onExpandNode` props plus
`role="button" tabIndex={0}` and an `onKeyDown` Enter/Space handler — but
useELKLayout never populated the props, so the node advertised itself as
a focusable button to screen readers and did nothing on Enter/Space. The
inner `onClick` / `onDoubleClick` also competed with ReactFlow's parent
event handling.
Changes:
- useELKLayout exposes `setNodeHandlers({ onNavigate, onExpandNode })`.
Handlers live in a ref so swapping them does NOT re-run layout or bust
React.memo on OntologyNode. Stable lambdas in node data read from the
ref at event time.
- OntologyGraph effect calls setNodeHandlers with `expandNode` (single-
click semantics) and `onNavigateToClass` (double-click semantics).
- OntologyNode drops competing `onClick` / `onDoubleClick` (ReactFlow's
parent handlers own mouse events). `onKeyDown` now provides keyboard
parity:
- Enter / Space → expand (matches single-click)
- Shift + Enter → navigate (matches double-click)
- aria-label now describes the keyboard shortcuts so screen readers
announce the actions.
- Tests updated to verify keyboard-only contract.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The `graphEdgeStyle` Zustand setting (bezier vs smoothstep) was added, persisted to localStorage, defaulted to 'smoothstep', AND exposed via a toolbar — but OntologyEdge always called getBezierPath, so the setting silently lied to the user. OntologyEdge now subscribes to the store and dispatches between getBezierPath / getSmoothStepPath based on the user's choice. OntologyEdge.test.tsx mocks the store (default: 'smoothstep') and the new getSmoothStepPath import to keep the test fast and matchMedia-free. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
These types were leftover from the deleted client-side graph builder (`lib/graph/buildGraphData.ts`). After the server-side BFS port, the canonical graph payload is `EntityGraphResponse` from `lib/api/graph.ts`, and grep confirms no consumers import OntologyGraphNode, OntologyGraphEdge, or GraphData. Keeping them invited future contributors to use the wrong vocabulary. The remaining `GraphNodeType` / `GraphEdgeType` literal unions stay — they are the rendering-side mirrors of the API enum, also referenced in Python (ontokit-api ontokit/schemas/graph.py). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Summary
Follow-up to #88 addressing the 3 high-severity findings from peer review. Targets
entity-graph-prso fixes land before #88 merges todev.Recommended merge order: this PR (#XX) → #88 →
dev.Findings addressed
OntologyNodeadvertised itself as a focusable button (role="button" tabIndex={0}) withonKeyDownEnter/Space handlers, butuseELKLayoutnever populatedonNavigate/onExpandNodeprops — so screen readers announced an interactive element that did nothing.ad95639graphEdgeStyleZustand store field was added, persisted to localStorage, defaulted to 'smoothstep', AND exposed via a toolbar — butOntologyEdgealways calledgetBezierPath. The setting silently lied to the user.df83589OntologyGraphNode/OntologyGraphEdge/GraphDatawere leftover from the deleted client-side graph builder. After the server-side BFS port,EntityGraphResponseis canonical and grep confirms no consumers reference the leftovers.724ea45Detailed rationale per fix
H1 — Wire keyboard handlers through
The challenge: ReactFlow already owns mouse interactions via
onNodeClick/onNodeDoubleClickat theOntologyGraphlevel. IfOntologyNodeadds its ownonClick, mouse events fire BOTH handlers (expand AND navigate). Solution:useELKLayoutso swapping them does not re-run layout or bustReact.memoonOntologyNode. Stable lambdas in node data read from the ref at event time.useELKLayoutexportssetNodeHandlers({ onNavigate, onExpandNode })and the consumer calls it from auseEffect.onClick/onDoubleClickfromOntologyNode— let ReactFlow own all mouse events.onKeyDownfor keyboard parity with the new mapping:Enter/Space→ expand (matches single-click)Shift + Enter→ navigate (matches double-click)aria-labeldescribes the keyboard shortcuts so screen readers announce both actions.H2 — Honor
graphEdgeStylesettingOntologyEdge.test.tsxmocks the store (default 'smoothstep') and the newgetSmoothStepPathimport to keep tests fast and matchMedia-free.H3 — Drop redundant types
OntologyGraphNode/OntologyGraphEdge/GraphDatawere render-side mirrors of the API types but no consumer imported them after the BFS port. Removed; only theGraphNodeType/GraphEdgeTypeliteral unions remain (rendering-side mirrors of the PythonLiteral[...]inontokit-api ontokit/schemas/graph.pyfrom the companion fix in #37 follow-up).Verification
npm run type-checkcleannpm run lint— 21 warnings (all pre-existing in unrelated files; no new ones)Test plan
npm test -- --run __tests__/components/graph/OntologyNode.test.tsx— keyboard contract verified (Enter expands, Shift+Enter navigates, external nodes don't dispatch)npm test -- --run __tests__/components/graph/OntologyEdge.test.tsx— smoothstep path used (per default store mock)Findings deferred to Discussion threads
The original review also flagged 5 medium and 5 low items. They will be filed as a tracked Discussion on this repo for follow-up.
🤖 Generated with Claude Code