Allow adding children to node without refreshing the whole tree #417
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.
Use case:
Dynamically add children (after an API call for example) to nodes without refreshing the whole tree (and expanding all nodes).
Problem:
When displaying a big tree, we'll fetch the children via API to avoid getting all information at once since it might be too big in size. The problem with that approach is that if we add those new nodes to the
data
prop, the whole tree will be refreshed with new ids and will havecollapsed: false
by default, so it will expand even the collapsed nodes, making the navigation confusing as you load more nodes.Proposed solution:
dataKey
prop to theTree
model. If thedataKey
is not present or changes, we should update the whole tree, but if thedata
prop changes but thedataKey
is the same, it means is the same tree, so we shouldn’t update.addChildren
method to theNode
model exposed props, to allow adding children dynamically from each node.Here's a screencast explaining the changes and the use case for this:
https://www.loom.com/share/70e372804b7d4d46a1b7a09564c5d3bf