question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add targetNode to canDrag rule

See original GitHub issue

I have a BoxListContainer and BoxListItem

The BoxListContainer is set to only accept BoxListItems

BoxListContainer.craft.rules.canMoveIn = incomingNode => incomingNode.data.type === BoxListItem

Now I need to also set that BoxListItem can be dragged only into BoxListContainer. How do I do that?

canDrag(currentNode: Node, helpers: NodeHelpers) => boolean
canMoveIn(incomingNode: Node, currentNode: Node, helpers: NodeHelpers) => boolean
canMoveout(outgoingNode: Node, currentNode: Node, helpers: NodeHelpers) => boolean

I am missing targetNode in canDrag, the other two have both nodes available.

this:

canDrag(currentNode: Node, targetNode: Node, helpers: NodeHelpers) => boolean

BoxListItem.craft.rules.canMoveIn = (_currentNode, targetNode) => targetNode.data.type === BoxListContainer

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
prevwongcommented, Jan 21, 2020

It seems to me now that you’re interested in implementing a canDrop rule which is not related to the canDrag rule that you created this issue for. Hence, this whole misunderstanding is happening now.

But anyways, with that brief example of yours, a canDrop rule might make sense. I would be glad to review a PR for this.

If I were to import external component, which I don’t even have a control over

If you were to import an external component and you want to use as a <Canvas />, you will have to create a wrapper for it anyway in order for you to specify configuration for it.

p.s. Stop spamming the issues tracker. We can use Discord for more long-winded discussions such as this. It also doesn’t help that you occasionally post your questions/issues on both platforms.

0reactions
prevwongcommented, Jan 30, 2020

Isn’t this use case supported by canDrag already ? For example, let’s say we want our component to only be able to move out depending on the parent it is in:

canDrag: (node, helpers) => {
  const parent = helpers.get(node.parent);
  if ( parent.data.type == BoxListContainer ) return false;
  return true;
}

Currently, Craft depends on both the component’s canDrag and the target parent’s canMoveOut for the component to be successfully moved out, so I think this already does what you want, or am I missing something ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node
rules Object. canDrag (currentNode: Node) => boolean. Specifies if the current Node can be ... canDrop (targetNode: Node, currentNode: Node) => boolean.
Read more >
Drag & Drop from Datatree to Datatree | Infragistics Forums
i can drag a node, but i can only drop them to the second tree element, ... wan't a event that says "this...
Read more >
How can I drag and drop a node in a treeview but that ... - MSDN
In this code I can drag and drop nodes and change the nodes places. ... Insert(draggedindex, targetNode); } // If it is a...
Read more >
Editing the Objects in a Decision - SAS Help Center
On the Decision Flow tab, you can drag rule sets, branches, models, treatment groups, ... but you can move the target node of...
Read more >
Working with Node Type Qualifiers - Cloud - Oracle Help Center
When comparing, locating, and adding or inserting nodes across node types (using ... If the target node type has a default qualifier defined,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found