diogofcunha / react-virtualized-tree

A virtualized tree view component making use of react
https://diogofcunha.github.io/react-virtualized-tree/
MIT License
454 stars 100 forks source link

Re-order nodes with drag and drop #13

Open diogofcunha opened 6 years ago

diogofcunha commented 6 years ago

Add the ability to re-order nodes using drag and drop.

guillaumesayegh commented 6 years ago

Hi !

Could you please tell us why was the PR https://github.com/diogofcunha/react-virtualized-tree/pull/21 deleted ? It would be very interesting to add Draggable behaviour :)

Actually I would be very interested to drag element from the tree to an other drop element in the page.

diogofcunha commented 6 years ago

Hey @guillaumesayegh.

I like to first give it a few tries before committing to definitive solution, specially since this can be a huge compromise. I didn't like the way things were going and want to start all over again.

I have more experience with dnd now, and I will have another fresh look into that in the future.

If you want to drag form the tree to another element in the page I don't see what blocks you atm. you have full control over the node render. as long as you make the node a draggable element it should be ok. I could help you with that if necessary 👍

NicoleRauch commented 5 years ago

Are there any news on this? I need to add reordering by drag-and-drop to my tree and I wanted to check back to see whether there is a "native" solution available before I try to add something myself. Thanks!

guillaumesayegh commented 5 years ago

Hey ! Actually there's no native solution for this. So I have been doing draggable by my own using react-dnd over the render of the node. I consider it would be still very interesting to improve this library by adding "Draggable" behaviour the same way we use "Expandable" for example. Let me know if you want any sample code.

NicoleRauch commented 5 years ago

Thanks for the offer! Meanwhile I've applied draggable together with the corresponding events, and I found it very simple to use for dragging a node onto another node.

I'm also planning to implement dragging between two other nodes (for reordering purposes) and currently I imagine this will be a lot harder because I want to insert a line between the nodes to visualize the drop area. If you have any example code for this, I'd be grateful if I could take a look at it! Cheers :-)

guillaumesayegh commented 5 years ago

Using Droppable react-beautiful-dnd (and Portals depending on your needs) should be very straightforward.

diogofcunha commented 5 years ago

There are several tricky things on dnd that we need to keep in mind:

I can see dragging meaning 3 things:

This makes dnd for the tree behave in both x and y axis and the x part is not trivial. This also means that we probably need to have some slick animations and interactive node measures to make sure the dnd experience looks nice.

I've been busy lately and I'm going on holiday soon, I need to figure out a way to do all this work after my holiday, and making it so that the tree keeps the lack of opinion on implementation details

NicoleRauch commented 5 years ago

@guillaumesayegh Have you implemented this already? I gave react-beautiful-dnd a try, and I wrapped my Tree into a DragDropContext and a Droppable, and I wrapped each tree node into a Draggable, but as soon as I try to drag something, the whole thing explodes with image

I suspect this is because the tree does not have proper children but instead gets this child generator function?

Do you have a working example using react-dnd? Happy to try out that one for a change...

guillaumesayegh commented 5 years ago

Here is working example: sample Basically it's a virtualized tree and each node can drag out of the list. I used a React portal to hack the dragging element.

NicoleRauch commented 5 years ago

Thank you very much for the sample! I stripped it down to make it compile (basically removed the search stuff and the icon), but I still get the same error as soon as I drag the node:

image

So the only other option I see is, maybe you're using a different version? Mine is "react-beautiful-dnd": "10.1.0",

Thanks for any insights :-)

guillaumesayegh commented 5 years ago

Yeah I'm using DND 8.0 and RVT 2.3. Hope this gonna help you out. Otherwise you should ask for support in react-beautiful-dnd project.

NicoleRauch commented 5 years ago

OK. Downgraded react-beautiful-dnd to 9.0.2 and now everything works. Oh well...

NicoleRauch commented 5 years ago

@guillaumesayegh Thanks very much! You helped me get on track with this again. I will submit a bug report with react-beautiful-dnd.

guillaumesayegh commented 5 years ago

Glad you've made it 👍