-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[TreeView] Support reordering of items in SimpleTreeView
#12369
[TreeView] Support reordering of items in SimpleTreeView
#12369
Conversation
Deploy preview: https://deploy-preview-12369--material-ui-x.netlify.app/ |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
808adc5
to
4856933
Compare
bf4c4d2
to
87afd8a
Compare
87afd8a
to
67db002
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated approach looks great! 🎉 👍
Fix #10235
Problem
The registration is done by the children when some of their props changes.
But if you just swap to items, nothing is called and the indexes in the state becomes outdated, causing multi-selection to break.
New approach
For both
RichTreeView
andSimpleTreeView
state.items.itemOrderedChildrenIds
state.items.nodeMap
Benefis
instance.getItemOrderedChildrenIds
(which replacesinstance.getChildrenIds
) has now a complexity ofO(1)
instead ofO(n)
. It is used for most keyboard navigation and range selection.Costs
O(n)
instead ofO(1)
. We need to explore the optimal data structure for the indexes depending on which access is the most frequent (getting an item index, changing an item index, getting the next item after some item, getting an ordered list of the items, ...). For now the new structure is super simple so at least we can easily modify it.For
SimpleTreeView
querySelector
, if the list has changed it updatesstate.items.itemOrderedChildrenIds
Benefis
SimpleTreeView
Costs
SimpleTreeView
is not meant for big dataset, IMHO the data structure optimization forstate.items.itemOrderedChildrenIds
are a lot more important to help theRichTreeView
scale on big datasets).Follow up
state.items.itemOrderedChildrenIds
could be a ref since it's only used in even callbacks. We need to check if this can avoid a re-render (not sure since it's always updated when children changes, which should cause a re-render of its own unless it's an index swap. So the optimization might be pointless).