refactor(nodes): also select edges when only one node is selected

This commit is contained in:
moklick
2019-07-25 00:00:39 +02:00
parent 81746b2714
commit 9fe6cff644
5 changed files with 222 additions and 99 deletions
+11 -2
View File
@@ -3,6 +3,7 @@ import { useEffect, useContext } from 'react';
import { useKeyPress } from '../hooks';
import { setNodesSelection } from '../state/actions';
import { GraphContext } from '../GraphContext';
import { isEdge, getConnectedEdges } from '../graph-utils';
export default (props) => {
const { state, dispatch } = useContext(GraphContext);
@@ -10,10 +11,18 @@ export default (props) => {
useEffect(() => {
if (removePressed && state.selectedElements.length) {
props.onElementsRemove(state.selectedElements);
let elementsToRemove = state.selectedElements;
// we also want to remove the edges if only one node is selected
if (state.selectedElements.length === 1 && !isEdge(state.selectedElements[0])) {
const connectedEdges = getConnectedEdges(state.selectedElements, state.edges);
elementsToRemove = [...state.selectedElements, ...connectedEdges];
}
props.onElementsRemove(elementsToRemove);
dispatch(setNodesSelection({ isActive: false }));
}
}, [removePressed])
return null;
}
};