Skip to content

Commit 179455e

Browse files
Hide legend button Option 2 (#3797)
@psychedelicious This version I added a toggle button to the viewport controls to show/hide the legend ![image](https://github.com/invoke-ai/InvokeAI/assets/115216705/f74ea273-e043-4104-921d-76861bd69841) Option 1 #3790
2 parents 6d688ca + 6eaa7d2 commit 179455e

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

invokeai/frontend/web/src/features/nodes/components/ViewportControls.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ import { ButtonGroup } from '@chakra-ui/react';
22
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
33
import IAIIconButton from 'common/components/IAIIconButton';
44
import { memo, useCallback } from 'react';
5-
import { FaCode, FaExpand, FaMinus, FaPlus } from 'react-icons/fa';
5+
import { FaCode, FaExpand, FaMinus, FaPlus, FaInfo } from 'react-icons/fa';
66
import { useReactFlow } from 'reactflow';
7-
import { shouldShowGraphOverlayChanged } from '../store/nodesSlice';
7+
import {
8+
shouldShowGraphOverlayChanged,
9+
shouldShowFieldTypeLegendChanged,
10+
} from '../store/nodesSlice';
811

912
const ViewportControls = () => {
1013
const { zoomIn, zoomOut, fitView } = useReactFlow();
1114
const dispatch = useAppDispatch();
1215
const shouldShowGraphOverlay = useAppSelector(
1316
(state) => state.nodes.shouldShowGraphOverlay
1417
);
18+
const shouldShowFieldTypeLegend = useAppSelector(
19+
(state) => state.nodes.shouldShowFieldTypeLegend
20+
);
1521

1622
const handleClickedZoomIn = useCallback(() => {
1723
zoomIn();
@@ -29,6 +35,10 @@ const ViewportControls = () => {
2935
dispatch(shouldShowGraphOverlayChanged(!shouldShowGraphOverlay));
3036
}, [shouldShowGraphOverlay, dispatch]);
3137

38+
const handleClickedToggleFieldTypeLegend = useCallback(() => {
39+
dispatch(shouldShowFieldTypeLegendChanged(!shouldShowFieldTypeLegend));
40+
}, [shouldShowFieldTypeLegend, dispatch]);
41+
3242
return (
3343
<ButtonGroup isAttached orientation="vertical">
3444
<IAIIconButton
@@ -52,6 +62,12 @@ const ViewportControls = () => {
5262
aria-label="Show/Hide Graph"
5363
icon={<FaCode />}
5464
/>
65+
<IAIIconButton
66+
isChecked={shouldShowFieldTypeLegend}
67+
onClick={handleClickedToggleFieldTypeLegend}
68+
aria-label="Show/Hide Field Type Legend"
69+
icon={<FaInfo />}
70+
/>
5571
</ButtonGroup>
5672
);
5773
};

invokeai/frontend/web/src/features/nodes/components/panels/TopRightPanel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ const TopRightPanel = () => {
99
const shouldShowGraphOverlay = useAppSelector(
1010
(state: RootState) => state.nodes.shouldShowGraphOverlay
1111
);
12+
const shouldShowFieldTypeLegend = useAppSelector(
13+
(state: RootState) => state.nodes.shouldShowFieldTypeLegend
14+
);
1215

1316
return (
1417
<Panel position="top-right">
15-
<FieldTypeLegend />
18+
{shouldShowFieldTypeLegend && <FieldTypeLegend />}
1619
{shouldShowGraphOverlay && <NodeGraphOverlay />}
1720
</Panel>
1821
);

invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type NodesState = {
3232
invocationTemplates: Record<string, InvocationTemplate>;
3333
connectionStartParams: OnConnectStartParams | null;
3434
shouldShowGraphOverlay: boolean;
35+
shouldShowFieldTypeLegend: boolean;
3536
editorInstance: ReactFlowInstance | undefined;
3637
};
3738

@@ -42,6 +43,7 @@ export const initialNodesState: NodesState = {
4243
invocationTemplates: {},
4344
connectionStartParams: null,
4445
shouldShowGraphOverlay: false,
46+
shouldShowFieldTypeLegend: false,
4547
editorInstance: undefined,
4648
};
4749

@@ -125,6 +127,12 @@ const nodesSlice = createSlice({
125127
shouldShowGraphOverlayChanged: (state, action: PayloadAction<boolean>) => {
126128
state.shouldShowGraphOverlay = action.payload;
127129
},
130+
shouldShowFieldTypeLegendChanged: (
131+
state,
132+
action: PayloadAction<boolean>
133+
) => {
134+
state.shouldShowFieldTypeLegend = action.payload;
135+
},
128136
nodeTemplatesBuilt: (
129137
state,
130138
action: PayloadAction<Record<string, InvocationTemplate>>
@@ -161,6 +169,7 @@ export const {
161169
connectionStarted,
162170
connectionEnded,
163171
shouldShowGraphOverlayChanged,
172+
shouldShowFieldTypeLegendChanged,
164173
nodeTemplatesBuilt,
165174
nodeEditorReset,
166175
imageCollectionFieldValueChanged,

0 commit comments

Comments
 (0)