-
-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add toHierarchy
utility for TreeView
, RecursiveList
#2072
Merged
Conversation
This file contains 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
metonym
force-pushed
the
pr-2069-changes
branch
6 times, most recently
from
December 8, 2024 19:03
921b10e
to
1754c6e
Compare
metonym
force-pushed
the
pr-2069-changes
branch
from
December 8, 2024 19:12
1754c6e
to
22b379c
Compare
metonym
force-pushed
the
pr-2069-changes
branch
from
December 8, 2024 22:05
22b379c
to
eea00a6
Compare
metonym
force-pushed
the
pr-2069-changes
branch
2 times, most recently
from
December 9, 2024 02:48
2087302
to
7c59620
Compare
Refactor `toHiearchy` to be more generic, performant - Use callback to "pick" generic parent ID property instead of requiring that `pid` be hardcoded` - Account for edge cases of an invalid parent ID - Use Map to store node children for lookups - Use one pass instead of removing empty nodes at the very end - DX: use generics to type `toHierarchy` - Make `toHierarchy` even more generic (reusable with `RecursiveList`) Co-Authored-By: Bram <[email protected]>
metonym
force-pushed
the
pr-2069-changes
branch
from
December 9, 2024 20:20
7c59620
to
5f1e8de
Compare
Released in v0.87.0. If using |
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.
Based on #2069, as I'm unable to push directly to that outside PR. Closes #2069.
This adds a
toHierarchy
utility per @bhavers's suggestion.Both
TreeView
andRecursiveList
components have anodes
prop. The structure is hierarchical, where anode
specifies "child" nodes via thenodes
prop. However, data may often be flat, with a property specifying its parent node ID.This adds a
toHierarchy
utility to easily convert a flat array of nodes into a shape acceptable by the recursive components. This utility is separated from any specific component both for reusability but also for performance. If unused, the utility should be tree-shaken from bundles.The second, required argument is a callback to retrieve the parent ID value. It's generic as to not force using any specific key for the parent ID. However,
id
andnodes
are required, as they match the prop shape forTreeView
andRecursiveList
.Usage
TreeView
Implementation Details
nodes
array where neededtoHierarchy
uses TypeScript generics for type safety and DXAdditional Notes
toHierarchy
. Otherwise, it will need to be directly imported to avoid slower development times (e.g.,from "carbon-components-svelte/src/utility/toHierarchy"
)