feat(ui): add select all to workflow editor

This commit is contained in:
psychedelicious 2023-08-18 20:38:09 +10:00
parent 2514af79a0
commit 165c57c001
2 changed files with 21 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import {
edgesDeleted,
nodesChanged,
nodesDeleted,
selectedAll,
selectedEdgesChanged,
selectedNodesChanged,
selectionCopied,
@ -124,11 +125,18 @@ export const Flow = () => {
dispatch(contextMenusClosed());
}, [dispatch]);
useHotkeys(['Ctrl+c', 'Meta+c'], () => {
useHotkeys(['Ctrl+c', 'Meta+c'], (e) => {
e.preventDefault();
dispatch(selectionCopied());
});
useHotkeys(['Ctrl+v', 'Meta+v'], () => {
useHotkeys(['Ctrl+a', 'Meta+a'], (e) => {
e.preventDefault();
dispatch(selectedAll());
});
useHotkeys(['Ctrl+v', 'Meta+v'], (e) => {
e.preventDefault();
dispatch(selectionPasted());
});

View File

@ -612,6 +612,16 @@ const nodesSlice = createSlice({
) => {
state.mouseOverField = action.payload;
},
selectedAll: (state) => {
state.nodes = applyNodeChanges(
state.nodes.map((n) => ({ id: n.id, type: 'select', selected: true })),
state.nodes
);
state.edges = applyEdgeChanges(
state.edges.map((e) => ({ id: e.id, type: 'select', selected: true })),
state.edges
);
},
selectionCopied: (state) => {
state.nodesToCopy = state.nodes.filter((n) => n.selected).map(cloneDeep);
state.edgesToCopy = state.edges.filter((e) => e.selected).map(cloneDeep);
@ -801,6 +811,7 @@ export const {
mouseOverFieldChanged,
selectionCopied,
selectionPasted,
selectedAll,
} = nodesSlice.actions;
export default nodesSlice.reducer;