Repository navigation
Feat: Use G6 to display mind map data. - #16899
Conversation
📝 WalkthroughWalkthroughChangesMind map rendering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant RepresentationRenderer
participant MindMapG6Graph
participant TreeAdapter
participant G6Graph
RepresentationRenderer->>MindMapG6Graph: pass mind-map template
MindMapG6Graph->>TreeAdapter: adapt template to graph data
TreeAdapter-->>MindMapG6Graph: return tree data
MindMapG6Graph->>G6Graph: configure and render graph
G6Graph-->>MindMapG6Graph: emit node click
MindMapG6Graph-->>RepresentationRenderer: forward node payload
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/pages/chunk/representation/utils/adapters.ts`:
- Around line 101-112: Update the cycle detection loop around relation.from,
parentMap, and child.id to check whether the initial/current cursor already
equals child.id before traversing its parent. Mark self-loops and descendant
cycles as wouldCycle and skip them, while preserving the existing ancestor
traversal for non-cyclic relations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cbbb5d9f-53b0-4fa6-9421-b07d8819bf19
📒 Files selected for processing (4)
web/src/pages/chunk/representation/components/mindmap-g6-graph/index.tsxweb/src/pages/chunk/representation/components/mindmap-g6-graph/types.tsweb/src/pages/chunk/representation/components/representation-renderer.tsxweb/src/pages/chunk/representation/utils/adapters.ts
| // Avoid cycles: do not attach a node under one of its descendants. | ||
| let cursor = relation.from; | ||
| let wouldCycle = false; | ||
| while (parentMap.has(cursor)) { | ||
| const ancestor = parentMap.get(cursor)!; | ||
| if (ancestor === child.id) { | ||
| wouldCycle = true; | ||
| break; | ||
| } | ||
| cursor = ancestor; | ||
| } | ||
| if (wouldCycle) continue; |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
Fix cycle detection to handle self-loops and prevent stack overflows.
The current cycle detection logic fails to catch self-loops (where relation.from === relation.to) because it only checks ancestors (parentMap.get(cursor)) and doesn't verify the initial cursor against child.id. A self-loop will bypass this check, adding the node to its own children array, which later causes an infinite recursion (stack overflow) in treeDataItemToG6TreeData.
Check the current node before traversing up the parent map.
🐛 Proposed fix
- let cursor = relation.from;
+ let cursor: string | undefined = relation.from;
let wouldCycle = false;
- while (parentMap.has(cursor)) {
- const ancestor = parentMap.get(cursor)!;
- if (ancestor === child.id) {
+ while (cursor) {
+ if (cursor === child.id) {
wouldCycle = true;
break;
}
- cursor = ancestor;
+ cursor = parentMap.get(cursor);
}
if (wouldCycle) continue;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Avoid cycles: do not attach a node under one of its descendants. | |
| let cursor = relation.from; | |
| let wouldCycle = false; | |
| while (parentMap.has(cursor)) { | |
| const ancestor = parentMap.get(cursor)!; | |
| if (ancestor === child.id) { | |
| wouldCycle = true; | |
| break; | |
| } | |
| cursor = ancestor; | |
| } | |
| if (wouldCycle) continue; | |
| // Avoid cycles: do not attach a node under one of its descendants. | |
| let cursor: string | undefined = relation.from; | |
| let wouldCycle = false; | |
| while (cursor) { | |
| if (cursor === child.id) { | |
| wouldCycle = true; | |
| break; | |
| } | |
| cursor = parentMap.get(cursor); | |
| } | |
| if (wouldCycle) continue; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/pages/chunk/representation/utils/adapters.ts` around lines 101 - 112,
Update the cycle detection loop around relation.from, parentMap, and child.id to
check whether the initial/current cursor already equals child.id before
traversing its parent. Mark self-loops and descendant cycles as wouldCycle and
skip them, while preserving the existing ancestor traversal for non-cyclic
relations.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16899 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Feat: Use G6 to display mind map data.