React-sortable-tree: [Feature] Expose function determine node should not move to marked disable node

Created on 2 Nov 2016  路  5Comments  路  Source: frontend-collective/react-sortable-tree

It's nice to have a function like this

shouldMoveNode = (nextNode, prevNode) => {
    return nextNode.node.is_enable ? true : false;
};
duplicate enhancement

Most helpful comment

  1. What information is inside prevNode?
  2. Does this get called while dragging?
  3. Does this get called right before dropping?

Making some assumptions here, but:
The node itself should remain unchanged, but its parents (and path) will change. I'm pretty confident I could give info on this stuff for a shouldMoveNode API:

draggedNode // The node being moved

prevPath // the previous (current) location in the tree of the node
prevParentNode // the previous (current) parent node

nextPath // The potential next location in the tree of the node
nextParentNode // The potential next parent of the node

All 5 comments

  1. What information is inside prevNode?
  2. Does this get called while dragging?
  3. Does this get called right before dropping?

Making some assumptions here, but:
The node itself should remain unchanged, but its parents (and path) will change. I'm pretty confident I could give info on this stuff for a shouldMoveNode API:

draggedNode // The node being moved

prevPath // the previous (current) location in the tree of the node
prevParentNode // the previous (current) parent node

nextPath // The potential next location in the tree of the node
nextParentNode // The potential next parent of the node

The behaviour of this API is the same as prevent the node being moved into deeper in the tree provide by the maxDepth options. I have found that involved with canDrop inside drag-and-drop-utils.js.

The shouldMoveNode being invoked during the node move should provide helpful information and we could have more flexible option moving nodes around.

Thank you for excellent tree component that hard to be found on the internet.

I like the idea with prevPath聽/ nextPath. May be useful.

This would be critical for my (probably unusual) application, I actually need to make an ajax call to the server to ensure the move doesn't violate a myriad of business rules before it's allowed to proceed.

One basic example of a rule is to make sure no "siblings" will have duplicate titles after the move proceeds. Others would be based on the business data associated with each node, spanning multiple tables in the DB, which explains the need for an ajax call.

So for us this would need to be called right after dropping as the check depends both on what node is being moved and where it's being moved to. Wouldn't want it to be disabled afterwards either as the user often will update their data to allow it to work the next time.

I just released the canDrop API with version 0.1.13. I think this should help you do what you're trying to do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oarashi picture oarashi  路  5Comments

bigjujube picture bigjujube  路  4Comments

brendanmoore picture brendanmoore  路  5Comments

Suremotoo picture Suremotoo  路  4Comments

vladimirsvsv77 picture vladimirsvsv77  路  5Comments