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

Commit f31c8bd

Browse files
authored
fix(gui): adding required annotation now closes attribute/constant/required form for same element (#864)
1 parent 2a1f71a commit f31c8bd

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

api-editor/gui/src/features/annotations/AnnotationDropdown.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { FaChevronDown } from 'react-icons/fa';
44
import { useAppDispatch, useAppSelector } from '../../app/hooks';
55
import { addPure, addRemove, addRequired, selectComplete, selectUsernameIsValid } from './annotationSlice';
66
import {
7+
hideAnnotationForm,
8+
selectCurrentUserAction,
79
showAttributeAnnotationForm,
810
showBoundaryAnnotationForm,
911
showCalledAfterAnnotationForm,
@@ -56,7 +58,22 @@ export const AnnotationDropdown: React.FC<AnnotationDropdownProps> = function ({
5658
const isComplete = Boolean(useAppSelector(selectComplete(target)));
5759
const isValidUsername = Boolean(useAppSelector(selectUsernameIsValid));
5860
const isDisabled = isComplete || !isValidUsername;
61+
const currentUserAction = useAppSelector(selectCurrentUserAction);
5962

63+
// Event Handlers --------------------------------------------------------------------------------------------------
64+
const onSelectRequired = () => {
65+
if (
66+
currentUserAction.target === target &&
67+
(currentUserAction.type === 'attribute' ||
68+
currentUserAction.type === 'constant' ||
69+
currentUserAction.type === 'optional')
70+
) {
71+
dispatch(hideAnnotationForm());
72+
}
73+
dispatch(addRequired({ target }));
74+
};
75+
76+
// Render ----------------------------------------------------------------------------------------------------------
6077
return (
6178
// Box gets rid of popper.js warning "CSS margin styles cannot be used"
6279
<Box>
@@ -104,7 +121,7 @@ export const AnnotationDropdown: React.FC<AnnotationDropdownProps> = function ({
104121
</MenuItem>
105122
)}
106123
{showRequired && (
107-
<MenuItem onClick={() => dispatch(addRequired({ target }))} paddingLeft={8}>
124+
<MenuItem onClick={onSelectRequired} paddingLeft={8}>
108125
@required
109126
</MenuItem>
110127
)}

0 commit comments

Comments
 (0)