fix(test): selection
This commit is contained in:
@@ -20,17 +20,21 @@ describe('Basic Flow Rendering', () => {
|
|||||||
cy.get('.react-graph__node:first').should('not.have.class', 'selected');
|
cy.get('.react-graph__node:first').should('not.have.class', 'selected');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('select all nodes', () => {
|
it('selects all nodes', () => {
|
||||||
// @FIX: why is there no selection__pane visible?
|
|
||||||
// https://docs.cypress.io/api/commands/type.html#Do-a-shift-click
|
|
||||||
cy.get('body')
|
cy.get('body')
|
||||||
.type('{shift}', { release: false })
|
.type('{Shift}', { release: false })
|
||||||
.get('.react-graph__selectionpane')
|
.get('.react-graph__selectionpane')
|
||||||
.trigger('mousedown', 'topLeft', { which: 1, force: true })
|
.trigger('mousedown', 'topLeft', { which: 1, force: true })
|
||||||
.trigger('mousemove', 'bottomRight', { which: 1 })
|
.trigger('mousemove', 'bottomRight', { which: 1 })
|
||||||
.trigger('mouseup', 'bottomRight', { force: true });
|
.trigger('mouseup', 'bottomRight', { force: true })
|
||||||
|
.get('.react-graph__node')
|
||||||
|
.should('have.class', 'selected')
|
||||||
|
.get('.react-graph__nodesselection-rect');
|
||||||
|
});
|
||||||
|
|
||||||
cy.get('.react-graph__node').should('have.class', 'selected');
|
it('remove selection', () => {
|
||||||
|
cy.get('.react-graph__renderer').click('bottomRight');
|
||||||
|
cy.get('.react-graph__nodesselection-rect').should('not.exist');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('selects an edge', () => {
|
it('selects an edge', () => {
|
||||||
@@ -55,7 +59,7 @@ describe('Basic Flow Rendering', () => {
|
|||||||
cy.get('.react-graph__edge').should('have.length', 1);
|
cy.get('.react-graph__edge').should('have.length', 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('connect nodes', () => {
|
it('connects nodes', () => {
|
||||||
cy.get('.react-graph__node')
|
cy.get('.react-graph__node')
|
||||||
.contains('Node 3')
|
.contains('Node 3')
|
||||||
.find('.react-graph__handle.source')
|
.find('.react-graph__handle.source')
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import { useStoreState, useStoreActions } from 'easy-peasy';
|
|||||||
import useKeyPress from '../hooks/useKeyPress';
|
import useKeyPress from '../hooks/useKeyPress';
|
||||||
import { isEdge, getConnectedEdges } from '../graph-utils';
|
import { isEdge, getConnectedEdges } from '../graph-utils';
|
||||||
|
|
||||||
export default memo(({ deleteKey, onElementsRemove }) => {
|
export default memo(({ deleteKeyCode, onElementsRemove }) => {
|
||||||
const state = useStoreState(s => ({ selectedElements: s.selectedElements, edges: s.edges }))
|
const state = useStoreState(s => ({ selectedElements: s.selectedElements, edges: s.edges }))
|
||||||
const setNodesSelection = useStoreActions(a => a.setNodesSelection);
|
const setNodesSelection = useStoreActions(a => a.setNodesSelection);
|
||||||
const removePressed = useKeyPress(deleteKey);
|
const deleteKeyPressed = useKeyPress(deleteKeyCode);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (removePressed && state.selectedElements.length) {
|
if (deleteKeyPressed && state.selectedElements.length) {
|
||||||
let elementsToRemove = state.selectedElements;
|
let elementsToRemove = state.selectedElements;
|
||||||
|
|
||||||
// we also want to remove the edges if only one node is selected
|
// we also want to remove the edges if only one node is selected
|
||||||
@@ -22,7 +22,7 @@ export default memo(({ deleteKey, onElementsRemove }) => {
|
|||||||
onElementsRemove(elementsToRemove);
|
onElementsRemove(elementsToRemove);
|
||||||
setNodesSelection({ isActive: false });
|
setNodesSelection({ isActive: false });
|
||||||
}
|
}
|
||||||
}, [removePressed])
|
}, [deleteKeyPressed])
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { fitView, zoomIn, zoomOut } from '../graph-utils';
|
|||||||
const GraphView = memo(({
|
const GraphView = memo(({
|
||||||
nodeTypes, edgeTypes, onMove, onLoad,
|
nodeTypes, edgeTypes, onMove, onLoad,
|
||||||
onElementClick, onNodeDragStop, connectionLineType, connectionLineStyle,
|
onElementClick, onNodeDragStop, connectionLineType, connectionLineStyle,
|
||||||
selectionKey
|
selectionKeyCode
|
||||||
}) => {
|
}) => {
|
||||||
const zoomPane = useRef();
|
const zoomPane = useRef();
|
||||||
const rendererNode = useRef();
|
const rendererNode = useRef();
|
||||||
@@ -28,7 +28,7 @@ const GraphView = memo(({
|
|||||||
const updateSize = useStoreActions(actions => actions.updateSize);
|
const updateSize = useStoreActions(actions => actions.updateSize);
|
||||||
const setNodesSelection = useStoreActions(actions => actions.setNodesSelection);
|
const setNodesSelection = useStoreActions(actions => actions.setNodesSelection);
|
||||||
|
|
||||||
const selectionKeyPressed = useKeyPress(selectionKey);
|
const selectionKeyPressed = useKeyPress(selectionKeyCode);
|
||||||
const updateDimensions = () => {
|
const updateDimensions = () => {
|
||||||
const size = getDimensions(rendererNode.current);
|
const size = getDimensions(rendererNode.current);
|
||||||
updateSize(size);
|
updateSize(size);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const ReactGraph = ({
|
|||||||
style, onElementClick, elements, children,
|
style, onElementClick, elements, children,
|
||||||
nodeTypes, edgeTypes, onLoad, onMove, onElementsRemove,
|
nodeTypes, edgeTypes, onLoad, onMove, onElementsRemove,
|
||||||
onConnect, onNodeDragStop, connectionLineType, connectionLineStyle,
|
onConnect, onNodeDragStop, connectionLineType, connectionLineStyle,
|
||||||
deleteKey, selectionKey
|
deleteKeyCode, selectionKeyCode
|
||||||
}) => {
|
}) => {
|
||||||
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []);
|
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []);
|
||||||
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []);
|
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []);
|
||||||
@@ -45,11 +45,11 @@ const ReactGraph = ({
|
|||||||
edgeTypes={edgeTypesParsed}
|
edgeTypes={edgeTypesParsed}
|
||||||
connectionLineType={connectionLineType}
|
connectionLineType={connectionLineType}
|
||||||
connectionLineStyle={connectionLineStyle}
|
connectionLineStyle={connectionLineStyle}
|
||||||
selectionKey={selectionKey}
|
selectionKeyCode={selectionKeyCode}
|
||||||
/>
|
/>
|
||||||
<GlobalKeyHandler
|
<GlobalKeyHandler
|
||||||
onElementsRemove={onElementsRemove}
|
onElementsRemove={onElementsRemove}
|
||||||
deleteKey={deleteKey}
|
deleteKeyCode={deleteKeyCode}
|
||||||
/>
|
/>
|
||||||
{children}
|
{children}
|
||||||
</StoreProvider>
|
</StoreProvider>
|
||||||
@@ -78,8 +78,8 @@ ReactGraph.defaultProps = {
|
|||||||
},
|
},
|
||||||
connectionLineType: 'bezier',
|
connectionLineType: 'bezier',
|
||||||
connectionLineStyle: {},
|
connectionLineStyle: {},
|
||||||
deleteKey: 'Backspace',
|
deleteKeyCode: 8,
|
||||||
selectionKey: 'Shift'
|
selectionKeyCode: 16
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ReactGraph;
|
export default ReactGraph;
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ import { useState, useEffect } from 'react';
|
|||||||
|
|
||||||
import { isInputNode } from '../utils';
|
import { isInputNode } from '../utils';
|
||||||
|
|
||||||
export default function useKeyPress(targetKey) {
|
export default function useKeyPress(keyCode) {
|
||||||
const [keyPressed, setKeyPressed] = useState(false);
|
const [keyPressed, setKeyPressed] = useState(false);
|
||||||
|
|
||||||
function downHandler({ key, target }) {
|
function downHandler(evt) {
|
||||||
if (key === targetKey && !isInputNode(target)) {
|
console.log(keyCode, evt.keyCode);
|
||||||
|
if (evt.keyCode === keyCode && !isInputNode(evt.target)) {
|
||||||
setKeyPressed(true);
|
setKeyPressed(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const upHandler = ({ key, target }) => {
|
const upHandler = (evt) => {
|
||||||
if (key === targetKey && !isInputNode(target)) {
|
if (evt.keyCode === keyCode && !isInputNode(evt.target)) {
|
||||||
setKeyPressed(false);
|
setKeyPressed(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user