Support infinite navigation levels with Radix Tree primitive#523
Support infinite navigation levels with Radix Tree primitive#523
Conversation
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
…bility, remove dead code Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
|
i've now made a package of Tree: https://www.npmjs.com/package/@abernier/radix-tree @copilot use it instead |
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Done! Switched to using Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
src/components/Nav/Nav.tsx
Outdated
| } | ||
|
|
||
| // Build a recursive tree structure from flat docs array | ||
| function buildTree(docs: Doc[]): NavNode[] { |
There was a problem hiding this comment.
@copilot Tree.Factory support virtualized prop https://github.com/abernier/radix-primitives/blob/main/packages/radix-tree/src/Tree.tsx#L354 with flatItems: cant we use this instead of rebuilding a nested tree?
There was a problem hiding this comment.
Good catch! Switched to using virtualized mode with flatten() function. This is more efficient since we:
- Use
Tree.Factorywithvirtualized={true}prop - Pass
flatItemscreated byflatten(items, new Set(openKeys)) - Render with
VIteminstead ofItem/Group - Apply depth-based styling directly (indentation via
marginLeft, font sizes)
The flatten function handles the tree traversal and only expands nodes in the openKeys set, which is more performant than rebuilding nested components. (commit 9d129f5)
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Navigation was hardcoded to 2 levels (category/page). Now supports arbitrary nesting depth using a Radix Tree primitive.
Changes
Dependencies:
@abernier/radix-tree@1.0.2- Published npm package for Radix Tree primitive with full functionalityNav component (
src/components/Nav/Nav.tsx)Record<string, Record<string, Doc>>with recursive tree builderdocsarray by slug hierarchyTree.Factoryfrom@abernier/radix-treewith virtualized mode for optimal performanceflatten()function to create flat list from nested structureopenKeysandonOpenKeysChangeExample structure now supported:
Performance:
Test documentation:
/docs/authoring/components/to demonstrate 3-level nestingOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.