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

Allow nodes to be dragged on to empty cells #59

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

F1nnM
Copy link
Contributor

@F1nnM F1nnM commented Oct 19, 2020

Nodes can be merged now. Merging nodes A and B only works, if at least one node doesn't contain text (is empty).
Merging can be done by dragging:

  • an empty node onto another empty node
  • an empty node onto a text node
  • a text node onto an empty node

Dragging the base of an arrow to the target of it, turns the arrow into a loop.

Everything seems to be working fine, but I'm not 100% sure I caught all bugs, so tell me if I introduced any bugs.

Copy link
Owner

@yishn yishn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very fun to play with it! However I found a few issues:

  • Dragging nodes onto loops resets loop properties

  • Node merges break undo/redo for some reason

  • After node merge, trying to create an arrow that starts on the merged node results in an uncaught exception

  • Creating an arrow on a blank canvas results in an uncaught exception

  • While dragging nodes around, it doesn't display label on a mergeable node:

    Wheee

@@ -254,7 +254,8 @@ export default class App extends Component {
return this.moveInHistory(1)
}

handleDataChange = evt => {
handleDataChange = (evt, overwriteLastHistory = false) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need overwriteLastHistory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving a node creates a entry in the history, and merging it would create another one. If I wouldn't overwrite the last history entry (the move) with the move and the merge, one could click undo and would have two not-merged nodes on the same position.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I fixed the undo/redo by doing so, but apparently I broke it again :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the true in the wrong spot. Weird that I didn't catch this before

if (existingNode.value.length > 0 && draggedNode.value.length > 0)
return
if (!arrEquals(newPosition, draggedNode.position))
nodesToJoin = [draggedNode, existingNode]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like nodesToJoin to be an object instead: {draggedNode, existingNode}

nodes: this.props.data.nodes
.filter(node => node.id != textNode.id)
.map(node =>
node.id == emptyNode.id
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use === for id comparisons

Comment on lines 99 to 101
if (edge.from == textNode.id) edge.from = emptyNode.id
if (edge.to == textNode.id) edge.to = emptyNode.id
if (edge.to == edge.from)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use === for id comparisons

if (edge.from == textNode.id) edge.from = emptyNode.id
if (edge.to == textNode.id) edge.to = emptyNode.id
if (edge.to == edge.from)
edge = {...edge, loop: [0, false], labelPosition: 'right'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we resetting the loop properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't meant to reset the loop properties, but rather set them the first time, when the start of an arrow is dragged to its head. I forgot that the properties might already be set.

@yishn yishn linked an issue Oct 21, 2020 that may be closed by this pull request
@yishn yishn changed the title Implemented issue #36 Allow nodes to be dragged on to empty cells Oct 21, 2020
@F1nnM
Copy link
Contributor Author

F1nnM commented Oct 21, 2020

I think I fixed everything

@F1nnM
Copy link
Contributor Author

F1nnM commented Oct 26, 2020

Hi, I really don't want to pressure you, but I also really would like this PR to count towards hacktoberfest, so if you could accept it before the end of the month, that would be great! 😄

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

Successfully merging this pull request may close these issues.

Allow nodes to be dragged on to empty cells
2 participants