lukasbach / react-complex-tree

Unopinionated Accessible Tree Component with Multi-Select and Drag-And-Drop
https://rct.lukasbach.com
MIT License
944 stars 74 forks source link

Docs on creating data providers #253

Closed lukasbach closed 7 months ago

lukasbach commented 1 year ago

Discussed in https://github.com/lukasbach/react-complex-tree/discussions/252

Originally posted by **PetervdHemel** April 20, 2023 Hi there. I'm quite new to using react, and especially typescript. I've been working (and learning while doing so) on a project that requires the eventual implementation of an interactive and dynamic 'item tree' and this package seemed really promising for that. The biggest issue I have is that the data I'm using (and receiving from my API) does not work with or translate well to the StaticTreeDataProvider that is used for getting started. I've concluded that making a custom data provider would seem to be the best solution, but I have near to no experience creating something like this. The basic structure of the data I receive from my API is something like this: ``` [ { item_id: { uuid: string, name: string, }, item_type: string, children: [], }, ] ``` Where `children` is an optional field that contains full items (either node or leaf which is specified by `item_type`), the array can contain any number of items. Basically I want the generated tree to consist of each item in the array, where the entry name is the `item_id.name`, and when either the `item_type` is `'node'` or the item contains `children` it means it is a 'folder'. The main thing I'm struggling with here is the lack of examples for `TreeDataProvider` which allows me to make something functionally different from `StaticTreeDataProvider` which is required in this case. Big thanks if someone can help or give pointers here. Examples would be hugely appreciated!

Plan: Add concrete examples in docs for implementing custom data providers.

tsingson commented 1 year ago

check https://github.com/lukasbach/react-complex-tree/issues/255

natetewelde commented 1 year ago

@lukasbach Can we also extend this to show better documentation on controlledTreeEnvironments and drag/drop implementation, expand/collapse?

lukasbach commented 7 months ago

I expanded the docs on static data providers and on custom data providers, they now include explicit examples and exemplary implementations for how to react to DND events from outside, and how to manage your own data in regards to that.