-
Notifications
You must be signed in to change notification settings - Fork 269
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
Fix #240 - cannot delete nodes with multiple graphs. #246
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,10 +188,7 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
const { initialBBox, zoomDelay, minZoom, maxZoom } = this.props; | ||
|
||
if (this.viewWrapper.current) { | ||
this.viewWrapper.current.addEventListener( | ||
'keydown', | ||
this.handleWrapperKeydown | ||
); | ||
document.addEventListener('keydown', this.handleWrapperKeydown); | ||
this.viewWrapper.current.addEventListener( | ||
'click', | ||
this.handleDocumentClick | ||
|
@@ -239,10 +236,7 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
} | ||
|
||
componentWillUnmount() { | ||
this.viewWrapper.current.removeEventListener( | ||
'keydown', | ||
this.handleWrapperKeydown | ||
); | ||
document.removeEventListener('keydown', this.handleWrapperKeydown); | ||
this.viewWrapper.current.removeEventListener( | ||
'click', | ||
this.handleDocumentClick | ||
|
@@ -400,10 +394,15 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
}); | ||
|
||
// remove node | ||
// The timeout avoids a race condition | ||
setTimeout(() => { | ||
GraphUtils.removeElementFromDom(`node-${nodeId}-container`); | ||
}); | ||
const timeoutId = `nodes-${nodeId}`; | ||
|
||
// cancel an asyncRenderNode animation | ||
cancelAnimationFrame(this.nodeTimeouts[timeoutId]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the race condition bug by cancelling the asyncRenderNode method. Now nodes are deleted and stay deleted. |
||
|
||
GraphUtils.removeElementFromDom( | ||
`node-${nodeId}-container`, | ||
this.viewWrapper.current | ||
); | ||
} | ||
} | ||
|
||
|
@@ -463,7 +462,10 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
removeEdgeElement(source: string, target: string) { | ||
const id = `${source}-${target}`; | ||
|
||
GraphUtils.removeElementFromDom(`edge-${id}-container`); | ||
GraphUtils.removeElementFromDom( | ||
`edge-${id}-container`, | ||
this.viewWrapper.current | ||
); | ||
} | ||
|
||
canSwap(sourceNode: INode, hoveredNode: INode | null, swapEdge: any) { | ||
|
@@ -492,7 +494,10 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
}); | ||
|
||
// remove from UI | ||
GraphUtils.removeElementFromDom(`node-${nodeId}-container`); | ||
GraphUtils.removeElementFromDom( | ||
`node-${nodeId}-container`, | ||
this.viewWrapper.current | ||
); | ||
|
||
// inform consumer | ||
this.props.onSelectNode(null); | ||
|
@@ -526,10 +531,12 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
if (selectedEdge.source != null && selectedEdge.target != null) { | ||
// remove extra custom containers just in case. | ||
GraphUtils.removeElementFromDom( | ||
`edge-${selectedEdge.source}-${selectedEdge.target}-custom-container` | ||
`edge-${selectedEdge.source}-${selectedEdge.target}-custom-container`, | ||
this.viewWrapper.current | ||
); | ||
GraphUtils.removeElementFromDom( | ||
`edge-${selectedEdge.source}-${selectedEdge.target}-container` | ||
`edge-${selectedEdge.source}-${selectedEdge.target}-container`, | ||
this.viewWrapper.current | ||
); | ||
} | ||
|
||
|
@@ -605,7 +612,7 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
} | ||
}; | ||
|
||
handleEdgeSelected = e => { | ||
handleEdgeSelected = (e: any) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor flowtype redline fix. |
||
const { source, target } = e.target.dataset; | ||
let newState = { | ||
svgClicked: true, | ||
|
@@ -777,7 +784,10 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
return; | ||
} | ||
|
||
GraphUtils.removeElementFromDom('edge-custom-container'); | ||
GraphUtils.removeElementFromDom( | ||
'edge-custom-container', | ||
this.viewWrapper.current | ||
); | ||
|
||
if (edgeEndNode) { | ||
const mapId1 = `${hoveredNodeData[nodeKey]}_${edgeEndNode[nodeKey]}`; | ||
|
@@ -1085,7 +1095,10 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
const draggedEdgeCopy = { ...this.state.draggedEdge }; | ||
|
||
// remove custom edge | ||
GraphUtils.removeElementFromDom('edge-custom-container'); | ||
GraphUtils.removeElementFromDom( | ||
'edge-custom-container', | ||
this.viewWrapper.current | ||
); | ||
this.setState( | ||
{ | ||
draggedEdge: null, | ||
|
@@ -1320,6 +1333,7 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> { | |
} | ||
|
||
const containerId = `${id}-container`; | ||
|
||
let nodeContainer: | ||
| HTMLElement | ||
| Element | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ export type IEdgeType = IEdge; | |
export { default as GraphUtils } from './utilities/graph-util'; | ||
export { default as Node } from './components/node'; | ||
export type INodeType = INode; | ||
// eslint-disable-next-line prettier/prettier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes an annoying problem with prettier trying to fix the line breaks when it doesn't need to. |
||
export { default as BwdlTransformer } from './utilities/transformers/bwdl-transformer'; | ||
export { GV as GraphView }; | ||
export type LayoutEngineType = LayoutEngineConfigTypes; | ||
|
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.
Fixes a minor console error that shows up when a node is deleted and the connected edges try to calculate their positions.