Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reordering node under root #31

Open
Giatomo opened this issue Apr 8, 2024 · 1 comment
Open

Reordering node under root #31

Giatomo opened this issue Apr 8, 2024 · 1 comment

Comments

@Giatomo
Copy link

Giatomo commented Apr 8, 2024

I got some issues while moving nodes right under the root node. Mostly the concat function not working here (on jstreer.js at $el.on("move_node.jstree", function(e, data)) :

var oldPath = oldInstance
              .get_path(data.old_parent)
              .concat(nodeText);

Exemple tree :

# (root node)
- A (child node)
- B
- C

I figured out a solution that would improve the consistancy of the jsTreeMoved event of the "from" and the "to" values while also retrieve the positions of the nodes (which is important in my use case but might also be helpful to other users) :
on $el.on("move_node.jstree", function(e, data) :

Shiny.setInputValue("jsTreeMoved:jsTreeR.copied", {
              from: { instance: oldInstanceId, path: oldPath },
              to: { instance: newInstanceId, path: newPath }
            }, {priority: "event"});

can be replaced by either :

Shiny.setInputValue("jsTreeMoved:jsTreeR.copied",{
              from: {
                instance: oldInstanceId,
                parent: data.old_parent,
                path: oldInstance.get_path(node),
                position: data.old_position},
              to: { 
                instance: newInstanceId,
                parent: data.parent,
                path: newInstance.get_path(node),
                position: data.position}
            }, {priority: "event"});

or :

Shiny.setInputValue("jsTreeMoved:jsTreeR.copied"{
              from: {
                instance: oldInstanceId,
                path: [data.old_parent].concat(oldInstance.get_path(node)),
                position: data.old_position},
              to: { 
                instance: newInstanceId,
                path: [data.parent].concat(newInstance.get_path(node)),
                position: data.position}
            }, {priority: "event"});

Thank for looking into this issue !
Best regards

@stla
Copy link
Owner

stla commented Apr 9, 2024

Hello,

I vaguely remember I already encountered a similar issue. The code with .concat does not work because the path is not an array here, it is null. Right?

Are you sure that [data.parent].concat will work in all situations? Anyway I'll have to check. These Shiny values are used in the "tree navigator" provided by the package, I'll have to check that your proposal does not break it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants