fluent_ui icon indicating copy to clipboard operation
fluent_ui copied to clipboard

[Feature Request] Create `TreeViewController`

Open bdlukaa opened this issue 1 year ago • 1 comments

Discussed in https://github.com/bdlukaa/fluent_ui/discussions/1085

Originally posted by pamtbaau July 15, 2024 I've two apps that use a TreeView. In both apps the TreeView needs to be dynamically updated by:

  • Adding/removing TreeViewItems
  • Replacing the value of a TreeViewItem (values are immutable objects)
  • Updating the content of the TreeViewItem depending on the replaced value.

I've tried two approaches:

  • Updating the underlaying tree of values (to-do's, or financial accounts/categories) and then rebuild the entire tree. Issues
    • Requires storing and maintaining which TreeViewItem is selected and/or expanded outside the TreeView.
    • Requires recreating entire tree after each insert/delete/update of underlaying values and apply selected/expanded properties.
  • Adding/removing TreeviewItems to/from the children property of the parent. Issues
    • The content and value of a TreeViewItem are final and cannot be updated. This requires creating a new TreeViewItem and replacing the outdated one.

Both approaches feel awkward...

Questions:

  • Is there something I've overlooked and can help in updating a tree dynamically?
  • Any other approach I could try?

Current Solution

The current only way to dynamically update a TreeView is by making it lazy and providing the items outside of it. When the items are loaded, just update the variable that holds that data and setState.

Expected Solution

To give more finer control to the tree view, a TreeViewController should be created. It would hold information about the attached TreeView. Additionally, it would give much more breath to the tree view widget itself, moving the logic to a contained place.

With the controller, one could:

  • Look for items (controller.getItemFromValue('item_value'));
  • Add items (controller.appendItem( ... ));
  • Remove items (controller.removeItem( ... ));

Additional Context

  • https://bdlukaa.github.io/fluent_ui/#/navigation/tree_view
  • https://learn.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.controls.treeview
  • https://learn.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.controls.treeviewitem

bdlukaa avatar Nov 19 '24 05:11 bdlukaa

I had the same thought. In my case, I want the TreeViewItem to expand when clicked, but I found the implementation to be quite cumbersome. I believe there should be a TreeViewController that could help us manage TreeView updates more efficiently.

Aobanana-chan avatar Jun 03 '25 07:06 Aobanana-chan