refactor(nodes): also select edges when only one node is selected
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user