-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
base: master
Are you sure you want to change the base?
Conversation
Made empty nodes mergeable
There was a problem hiding this 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:
@@ -254,7 +254,8 @@ export default class App extends Component { | |||
return this.moveInHistory(1) | |||
} | |||
|
|||
handleDataChange = evt => { | |||
handleDataChange = (evt, overwriteLastHistory = false) => { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :/
There was a problem hiding this comment.
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
src/components/Grid.js
Outdated
if (existingNode.value.length > 0 && draggedNode.value.length > 0) | ||
return | ||
if (!arrEquals(newPosition, draggedNode.position)) | ||
nodesToJoin = [draggedNode, existingNode] |
There was a problem hiding this comment.
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}
src/components/Grid.js
Outdated
nodes: this.props.data.nodes | ||
.filter(node => node.id != textNode.id) | ||
.map(node => | ||
node.id == emptyNode.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ===
for id comparisons
src/components/Grid.js
Outdated
if (edge.from == textNode.id) edge.from = emptyNode.id | ||
if (edge.to == textNode.id) edge.to = emptyNode.id | ||
if (edge.to == edge.from) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ===
for id comparisons
src/components/Grid.js
Outdated
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'} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I think I fixed everything |
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! 😄 |
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:
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.