-
Notifications
You must be signed in to change notification settings - Fork 491
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(@clayui/core): Add Collection Tree implementation #5045
feat(@clayui/core): Add Collection Tree implementation #5045
Conversation
…e` to be more readable
…sted and pass custom props in children function
7a4bbb8
to
9b5f144
Compare
9b5f144
to
ce76721
Compare
Well, I found out that the test failures were related to a reference issue of the I've made some more advances with tree virtualization, I'm trying the strategy of using the nested |
Well, I tried the nested virtualization strategy using the recent libs but it doesn't work very well because they don't communicate when it's nested, it breaks everything. I think I'm going back to the option to render the tree in list with virtualization for Tree, as it is implemented in other libs, I think we still managed to still maintain accessibility using some properties, like:
The problem with this is that it changes all the TreeView markup and this can break some implementations in the portal but I think it is something very valuable that is worth it because it would just update the corresponding classes and we will have a lot of performance gains regardless of the data size. It is very likely that I will also have to rewrite a good part of the existing mechanisms of the TreeView, for example:
I'll deep dive into that this week and bring you some more information on the progress of this, I also hope I don't make any API changes or break anything other than the markup that we can't avoid here. |
I spent quite a bit of time developing/research this but there are a lot of changes I would have to make so I'm guessing that adding this now would take more time than I thought and many internal changes to the TreeView would be affected but also changes to the API, for example I'll try to dig a little deeper into the things I've done so far and try to explain the things that we would have to change. The main mechanism here is the tree walker which must have the ability to traverse the tree from one point to another, for example virtualization works over a range of indexes The example above tries to illustrate some of the diagramming of how this would work, the virtual scroll changes the range of visible indicies and the tree walker navigates through the tree and adds all items that are within that range to the list, the list data contains some properties like item depth level, parent and child, this helps to define accessibility properties for the list in the future.
The implementation of the cursor is more complicated because it can't be the leaf of the tree because it wouldn't know how to go back, maybe we could keep the cursor with the last item at level zero of the tree and the next iteration starts from that point, a strategy would be maintain a structure as a support of items corresponding to the leaf path, that is, the parent items of the leaf that allows you to go back and continue forward, this can help in moments when there is a large amount of items in depth and only they are visible and we don't need get the parent in the level zero and navigate to the corresponding subtree. In the demo example above, moving the virtual scroll changes the range of items that should be visible, we use the cursor of the last iteration, the arrows used define how this flow would work from traversing the items in the tree until reaching the index limit.
The flow follows the same idea, there are many edge cases in various scenarios here the assumption is that the cursor will always be present when the recomputation is triggered by the virtualizer because it calls with each scroll change, we can also save more information in the cursor like yours index to help you decide when to look for the parent and know which children to add or if the parent's children are not visible. It may be that I'm not covering all the scenarios here. Another scenario is when the user collates an item with visible children, it follows the same rule recomputing the visible items using the cursor as a starting point, the cursor has its index of the last iteration so we know how many items are added before it or after it, so when looking for the cursor's parent and having children but the cursor is not the first in this list of items we can determine where to start. A way also to avoid putting a leaf item from the tree as a cursor and putting its parent to always avoid the first search for the parent when it has no children. The tree walker system is reactive, so even if an expand/collapse, remove an item from the tree, move the items will have no problem what can happen in these situations is the system restarts from zero when the cursor is lost. The problem with this approach is that it can be very complex with many edge cases that can happen but it can also be simple because it is reactive, I haven't implemented all these details yet, I have a very simple system, I plan to organize and commit to push to this PR and keep that on hold for future work. There is another strategy like turning the entire tree into a list and using some optimization strategies like slice time, traversing the tree within a deadline, when you don't have time to traverse wait for the next available frame, this is similar to how react-vtree does. As a final part of this change from tree to list virtualization, some other changes would be needed.
I'm still going to merge the commits I added initially using the base Collection in the TreeView but I'll send it in another PR to keep the history here for the full iteration of the tree virtualization. |
Closes #5030
This PR is a WIP of the Collection Tree implementation, as mentioned in the issue the hardest part here is getting the nested virtualization to have accessibility, I'm still working on it but I'm submitting a piece of work that adds some more features to the Collection implementation that are needed to use in TreeView.
These are necessary resources to use in the TreeView component, see the commit d4f8419 that shows how it is being used.
As mentioned in the RFC, most of these changes are just internal architecture changes to keep all components to the same standard both internally and usage, still no components are supported by the collection, follow issue #5032 for more details.
Over the next week I will be sending more commits that I intend to focus only on the implementation of virtualization for the tree, this will be very important for DropDown and TreeView for much more expressive performance gains in TreeView.
ToDo