react-ui-tree
react-ui-tree copied to clipboard
Level three nodes cant have children
Consider the case of the following Tree:
- Root
- Level 1
- Level 2 Node
- Another Level 2 Node
- New node
- Level 1
The component will not let me drag "New node" into any level 2 node. To do this, I have to drag out a level 2 node, drag the "New node" into it and then drag it back into level 1.
After doing this, the tree will end up like this:
- Root
- Level 1
- Level 2 Node
- Another Level 2 Node
- New node
- Level 1
I have tried to debug why this is happening but couldn't find any solution. In the github page example, this behaviour happens too.
This is a result of the node having a leaf: true
property.
If you set this to false (or don't give it the property at all) you will be able to drag nodes under it.
No, this bug was found on previous version to the leaf feature. I updated it and it still happens.
You can replicate this on the demo.
I found the problem, but I am not really sure which is the proper way to fix this.
Since I have to render a really big tree, in the initial render I collapsed every single node it had.
In UITree Component, drag():
if(index.prev) {
var prevNode = tree.getIndex(index.prev).node;
if (!prevNode.collapsed && !prevNode.leaf) {
newIndex = tree.move(index.id, index.prev, 'append');
}
}
}
As I said before, this has been happening before the leaf feature was added. So, if you have a collapsed node that doesn't have any children, it won't allow to append nodes to it.
Maybe check its children?
The component will not let me drag "New node" into any level 2 node
The level2 node has leaf: true
?
Nope, as I said before, all tree nodes from level 1 to the end had collapse on true
@matiasgarcia Did you find any solution?
@sergeycooper Since I had a really big tree to render, I collapsed every single node on initialization. The issue was that I also collapsed the leaf nodes on initialization too, and this caused that new nodes couldnt be appended to them (check the code above). TL;DR I just avoided collapsing leaf nodes.
@matiasgarcia Alright, I get it. Thanks for info! Are you still using it or you find any other DnD-Tree-like solution?
Although it has some perfomance issues to be solved when rendering a really big tree, I haven't found anything better. Let me know if you do :)
If you haven't found anything better I think I will use it for my purposes too ;)