feat(ui): remove selectedAll action

This commit is contained in:
psychedelicious 2024-05-19 14:47:24 +10:00
parent 9a8e0842bb
commit cbe32b647a
2 changed files with 17 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import { useGlobalMenuClose, useToken } from '@invoke-ai/ui-library'; import { useGlobalMenuClose, useToken } from '@invoke-ai/ui-library';
import { useStore } from '@nanostores/react'; import { useStore } from '@nanostores/react';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector, useAppStore } from 'app/store/storeHooks';
import { useConnection } from 'features/nodes/hooks/useConnection'; import { useConnection } from 'features/nodes/hooks/useConnection';
import { useCopyPaste } from 'features/nodes/hooks/useCopyPaste'; import { useCopyPaste } from 'features/nodes/hooks/useCopyPaste';
import { useSyncExecutionState } from 'features/nodes/hooks/useExecutionState'; import { useSyncExecutionState } from 'features/nodes/hooks/useExecutionState';
@ -17,7 +17,6 @@ import {
edgesChanged, edgesChanged,
nodesChanged, nodesChanged,
redo, redo,
selectedAll,
selectionDeleted, selectionDeleted,
undo, undo,
} from 'features/nodes/store/nodesSlice'; } from 'features/nodes/store/nodesSlice';
@ -27,6 +26,8 @@ import type { CSSProperties, MouseEvent } from 'react';
import { memo, useCallback, useMemo, useRef } from 'react'; import { memo, useCallback, useMemo, useRef } from 'react';
import { useHotkeys } from 'react-hotkeys-hook'; import { useHotkeys } from 'react-hotkeys-hook';
import type { import type {
EdgeChange,
NodeChange,
OnEdgesChange, OnEdgesChange,
OnEdgeUpdateFunc, OnEdgeUpdateFunc,
OnInit, OnInit,
@ -77,6 +78,7 @@ export const Flow = memo(() => {
const isValidConnection = useIsValidConnection(); const isValidConnection = useIsValidConnection();
const cancelConnection = useReactFlowStore(selectCancelConnection); const cancelConnection = useReactFlowStore(selectCancelConnection);
const updateNodeInternals = useUpdateNodeInternals(); const updateNodeInternals = useUpdateNodeInternals();
const store = useAppStore();
useWorkflowWatcher(); useWorkflowWatcher();
useSyncExecutionState(); useSyncExecutionState();
const [borderRadius] = useToken('radii', ['base']); const [borderRadius] = useToken('radii', ['base']);
@ -203,9 +205,19 @@ export const Flow = memo(() => {
const onSelectAllHotkey = useCallback( const onSelectAllHotkey = useCallback(
(e: KeyboardEvent) => { (e: KeyboardEvent) => {
e.preventDefault(); e.preventDefault();
dispatch(selectedAll()); const { nodes, edges } = store.getState().nodes.present;
const nodeChanges: NodeChange[] = [];
const edgeChanges: EdgeChange[] = [];
nodes.forEach((n) => {
nodeChanges.push({ id: n.id, type: 'select', selected: true });
});
edges.forEach((e) => {
edgeChanges.push({ id: e.id, type: 'select', selected: true });
});
dispatch(nodesChanged(nodeChanges));
dispatch(edgesChanged(edgeChanges));
}, },
[dispatch] [dispatch, store]
); );
useHotkeys(['Ctrl+a', 'Meta+a'], onSelectAllHotkey); useHotkeys(['Ctrl+a', 'Meta+a'], onSelectAllHotkey);

View File

@ -347,16 +347,6 @@ export const nodesSlice = createSlice({
state.nodes = []; state.nodes = [];
state.edges = []; state.edges = [];
}, },
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
);
},
selectionPasted: (state, action: PayloadAction<{ nodes: AnyNode[]; edges: InvocationNodeEdge[] }>) => { selectionPasted: (state, action: PayloadAction<{ nodes: AnyNode[]; edges: InvocationNodeEdge[] }>) => {
const { nodes, edges } = action.payload; const { nodes, edges } = action.payload;
@ -465,7 +455,6 @@ export const {
nodesChanged, nodesChanged,
nodeUseCacheChanged, nodeUseCacheChanged,
notesNodeValueChanged, notesNodeValueChanged,
selectedAll,
selectionPasted, selectionPasted,
selectionDeleted, selectionDeleted,
undo, undo,
@ -509,7 +498,7 @@ export const nodesPersistConfig: PersistConfig<NodesState> = {
persistDenylist: [], persistDenylist: [],
}; };
const selectionMatcher = isAnyOf(selectedAll, selectionPasted, nodeExclusivelySelected); const selectionMatcher = isAnyOf(selectionPasted, nodeExclusivelySelected);
const isSelectionAction = (action: UnknownAction) => { const isSelectionAction = (action: UnknownAction) => {
if (selectionMatcher(action)) { if (selectionMatcher(action)) {