frontend-collective / react-sortable-tree

Drag-and-drop sortable component for nested data and hierarchies
https://frontend-collective.github.io/react-sortable-tree/
MIT License
4.9k stars 904 forks source link

Can't make sense of Path #383

Open Morgorth opened 6 years ago

Morgorth commented 6 years ago

Hi,

I can't make sense of the path, I wondering if there is an issue. I have a simple tree, no dragging, no change in it:

The path of first child of the first root node is 0:1 and second child 0:2. That could make sense but I would expect 0:0 and 0:1 (index value).

Now, the path of the second root node tells me 0:3, which doesn't make sense to me. And then the child of that node is 0:3 0:4.

Is that an error ? Otherwise can someone explain ?

Thanks

NickEmpetvee commented 6 years ago

Hi,

I believe that the path is built off the inherent tree node key values. Each node inherently has one immutable unique key and numbering starts with 0. The Path simply reflects the node hierarchy in terms of these unique keys. Therefore if node 5 is nested under node 1, the Path will be 1:5. If node 5 moves under node 2, its Path changes to 2:5. If node five moves to the top level its Path is simply 5.

This is what I've surmised from the import/export storybook example: https://frontend-collective.github.io/react-sortable-tree/?selectedKind=Basics&selectedStory=treeData%20import%2Fexport&full=0&addons=0&stories=1&panelRight=0. See the bottom half where the tree data re-renders based on the node arrangement above it. The ID doesn't change although the parent does change when you drag/drop.

I'm a beginner with this library, so I'm answering with limited knowledge but it will hopefully be helpful to you.

Morgorth commented 6 years ago

oh, ok. I was thinking the path represented the position of the node in the array and that I could use it to resync with my database. too bad

NickEmpetvee commented 6 years ago

You may be able to with some creativity. I am trying the same thing right now, and will keep you posted.