Open Duck-98 opened 5 days ago
@Duck-98 Thank you for your comment!
For the search functionality, we prefer to provide a hook or helper rather than extending the functionality of the component. We would like to leave the specific implementation to the users of this library, as there are many possible use cases for how to display the search results. For example
const [filteredTree, openIds] = useTreeSearch(searchText);.
This takes a search string as an argument and returns the filtered tree and the IDs of the nodes that should be opened.
Regarding virtualization of the tree, I think it is difficult to virtualize the tree because all the nodes in the tree are not flat but nested, but I don't have a good idea for this. I would like to know if you have any solutions. Tree virtualization is a feature that has been requested since the beginning of this library, so if it can be implemented without sacrificing functionality, it would be welcome.
@minop1205 Thank you for your thoughtful feedback on the tree virtualization and search functionality. I'd like to propose a detailed implementation approach that addresses both the performance concerns and maintains the library's flexibility:
Regarding virtualization
While I initially attempted to implement virtualization while preserving the nested tree structure, I found that flattening the tree structure provides a more efficient solution. However, I want to emphasize that:
For the technical implementation, I'm proposing to use @tanstack/react-virtual instead of react-window. The reasons for this choice are
The implementation will preserve all existing functionality, including
Performance optimizations will include:
Regarding the search functionality:
useTreeSearch
) that:
Example search hook usage would look like:
const { filteredTree, expandedIds } = useTreeSearch(tree, searchQuery, {
searchFn: (node, query) => // custom implementation,
// ...etc (yet)
});
Would this approach align with the library's goals? I can proceed with a proof-of-concept implementation if you think this direction makes sense.
I'm particularly interested in your thoughts on:
Is your feature request related to a problem? Please describe. When searching and filtering tree data, nodes that match the search criteria are not visible if their parent nodes are collapsed. This creates a poor user experience as users cannot immediately see all search results and must manually expand multiple parent nodes to find the matching items.
For example, if I search for "item-3-2" which is nested under "folder-1/folder-2/folder-3", I cannot see the result unless all parent folders are already expanded.
Describe the solution you'd like I would like to implement two key features:
Enhanced Search Functionality:
Virtualization Support:
Describe alternatives you've considered
Additional context This enhancement would significantly improve the usability of the tree component, especially for large data sets where users need to quickly find specific items in a deep hierarchy. The current implementation requires too many manual interactions to view search results.
For the virtualization feature, I plan to utilize the
react-window
library, which is well-maintained and provides excellent performance for handling large lists and grid layouts. This library would help us implement efficient virtual scrolling while maintaining smooth performance even with expanded trees containing many nodes.I would greatly appreciate your feedback on this feature request. If you think this would be a valuable addition to the library, I would be happy to contribute to its implementation. Please let me know if you would like me to proceed with this enhancement and if you have any specific guidelines or considerations I should keep in mind while implementing these features.