@@ -4,6 +4,8 @@ import { FaChevronDown } from 'react-icons/fa';
4
4
import { useAppDispatch , useAppSelector } from '../../app/hooks' ;
5
5
import { addPure , addRemove , addRequired , selectComplete , selectUsernameIsValid } from './annotationSlice' ;
6
6
import {
7
+ hideAnnotationForm ,
8
+ selectCurrentUserAction ,
7
9
showAttributeAnnotationForm ,
8
10
showBoundaryAnnotationForm ,
9
11
showCalledAfterAnnotationForm ,
@@ -56,7 +58,22 @@ export const AnnotationDropdown: React.FC<AnnotationDropdownProps> = function ({
56
58
const isComplete = Boolean ( useAppSelector ( selectComplete ( target ) ) ) ;
57
59
const isValidUsername = Boolean ( useAppSelector ( selectUsernameIsValid ) ) ;
58
60
const isDisabled = isComplete || ! isValidUsername ;
61
+ const currentUserAction = useAppSelector ( selectCurrentUserAction ) ;
59
62
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 ----------------------------------------------------------------------------------------------------------
60
77
return (
61
78
// Box gets rid of popper.js warning "CSS margin styles cannot be used"
62
79
< Box >
@@ -104,7 +121,7 @@ export const AnnotationDropdown: React.FC<AnnotationDropdownProps> = function ({
104
121
</ MenuItem >
105
122
) }
106
123
{ showRequired && (
107
- < MenuItem onClick = { ( ) => dispatch ( addRequired ( { target } ) ) } paddingLeft = { 8 } >
124
+ < MenuItem onClick = { onSelectRequired } paddingLeft = { 8 } >
108
125
@required
109
126
</ MenuItem >
110
127
) }
0 commit comments