Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit b10afb6

Browse files
authored
fix(gui): disable navigation when an annotation form is open (#852)
1 parent 3af1c1e commit b10afb6

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

api-editor/gui/src/features/menuBar/MenuBar.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
import {
3131
BatchMode,
3232
HeatMapMode,
33+
NoUserAction,
34+
selectCurrentUserAction,
3335
selectExpandDocumentationByDefault,
3436
selectFilter,
3537
selectHeatMapMode,
@@ -87,6 +89,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
8789
const annotations = useAppSelector(selectAnnotationStore);
8890
const usages = useAppSelector(selectUsages);
8991
const declaration = rawPythonPackage.getDeclarationById(useLocation().pathname.split('/').splice(1).join('/'));
92+
const currentUserAction = useAppSelector(selectCurrentUserAction);
9093

9194
const exportAnnotations = () => {
9295
const a = document.createElement('a');
@@ -118,11 +121,11 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
118121
dispatch(toggleComplete(declaration.id));
119122
};
120123
const goToPreviousMatch = () => {
121-
if (!declaration) {
124+
if (!declaration || currentUserAction !== NoUserAction) {
122125
return;
123126
}
124127

125-
let { id: navStr, wrappedAround } = getPreviousElementPath(
128+
const { id: navStr, wrappedAround } = getPreviousElementPath(
126129
allDeclarations,
127130
declaration,
128131
pythonFilter,
@@ -149,11 +152,11 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
149152
}
150153
};
151154
const goToNextMatch = () => {
152-
if (!declaration) {
155+
if (!declaration || currentUserAction !== NoUserAction) {
153156
return;
154157
}
155158

156-
let { id: navStr, wrappedAround } = getNextElementPath(
159+
const { id: navStr, wrappedAround } = getNextElementPath(
157160
allDeclarations,
158161
declaration,
159162
pythonFilter,
@@ -180,24 +183,32 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
180183
}
181184
};
182185
const goToParent = () => {
186+
if (!declaration || currentUserAction !== NoUserAction) {
187+
return;
188+
}
189+
183190
const parent = declaration?.parent();
184191
if (parent && !(parent instanceof PythonPackage)) {
185192
navigate(`/${parent.id}`);
186193
}
187194
};
188195
const expandAll = () => {
189-
dispatch(setAllExpandedInTreeView(getDescendantsOrSelf(pythonPackage)));
196+
if (currentUserAction === NoUserAction) {
197+
dispatch(setAllExpandedInTreeView(getDescendantsOrSelf(pythonPackage)));
198+
}
190199
};
191200
const collapseAll = () => {
192-
dispatch(setAllCollapsedInTreeView(getDescendantsOrSelf(pythonPackage)));
201+
if (currentUserAction === NoUserAction) {
202+
dispatch(setAllCollapsedInTreeView(getDescendantsOrSelf(pythonPackage)));
203+
}
193204
};
194205
const expandSelected = () => {
195-
if (declaration) {
206+
if (declaration && currentUserAction === NoUserAction) {
196207
dispatch(setAllExpandedInTreeView(getDescendantsOrSelf(declaration)));
197208
}
198209
};
199210
const collapseSelected = () => {
200-
if (declaration) {
211+
if (declaration && currentUserAction === NoUserAction) {
201212
dispatch(setAllCollapsedInTreeView(getDescendantsOrSelf(declaration)));
202213
}
203214
};
@@ -331,7 +342,11 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
331342

332343
<Box>
333344
<Menu>
334-
<MenuButton as={Button} rightIcon={<Icon as={FaChevronDown} />}>
345+
<MenuButton
346+
as={Button}
347+
rightIcon={<Icon as={FaChevronDown} />}
348+
disabled={currentUserAction !== NoUserAction}
349+
>
335350
Navigate
336351
</MenuButton>
337352
<MenuList>

api-editor/gui/src/features/ui/uiSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type UserAction =
5252
| OptionalUserAction
5353
| TodoUserAction;
5454

55-
const NoUserAction = {
55+
export const NoUserAction = {
5656
type: 'none',
5757
target: '',
5858
};

0 commit comments

Comments
 (0)