react-ui-tree icon indicating copy to clipboard operation
react-ui-tree copied to clipboard

Level three nodes cant have children

Open matiasgarcia opened this issue 9 years ago • 10 comments

Consider the case of the following Tree:

  • Root
    • Level 1
      • Level 2 Node
      • Another Level 2 Node
    • New node

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

I have tried to debug why this is happening but couldn't find any solution. In the github page example, this behaviour happens too.

matiasgarcia avatar Oct 29 '15 14:10 matiasgarcia

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.

tobyndockerill avatar Oct 29 '15 22:10 tobyndockerill

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.

matiasgarcia avatar Oct 29 '15 22:10 matiasgarcia

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?

matiasgarcia avatar Oct 30 '15 13:10 matiasgarcia

The component will not let me drag "New node" into any level 2 node

The level2 node has leaf: true ?

wangzuo avatar Nov 03 '15 05:11 wangzuo

Nope, as I said before, all tree nodes from level 1 to the end had collapse on true

matiasgarcia avatar Nov 10 '15 02:11 matiasgarcia

@matiasgarcia Did you find any solution?

ulshv avatar Apr 11 '16 13:04 ulshv

@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 avatar Apr 11 '16 13:04 matiasgarcia

@matiasgarcia Alright, I get it. Thanks for info! Are you still using it or you find any other DnD-Tree-like solution?

ulshv avatar Apr 11 '16 14:04 ulshv

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 :)

matiasgarcia avatar Apr 11 '16 15:04 matiasgarcia

If you haven't found anything better I think I will use it for my purposes too ;)

ulshv avatar Apr 11 '16 15:04 ulshv