Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion api-editor/gui/src/features/annotations/AnnotationDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { FaChevronDown } from 'react-icons/fa';
import { useAppDispatch, useAppSelector } from '../../app/hooks';
import { addPure, addRemove, addRequired, selectComplete, selectUsernameIsValid } from './annotationSlice';
import {
hideAnnotationForm,
selectCurrentUserAction,
showAttributeAnnotationForm,
showBoundaryAnnotationForm,
showCalledAfterAnnotationForm,
Expand Down Expand Up @@ -56,7 +58,22 @@ export const AnnotationDropdown: React.FC<AnnotationDropdownProps> = function ({
const isComplete = Boolean(useAppSelector(selectComplete(target)));
const isValidUsername = Boolean(useAppSelector(selectUsernameIsValid));
const isDisabled = isComplete || !isValidUsername;
const currentUserAction = useAppSelector(selectCurrentUserAction);

// Event Handlers --------------------------------------------------------------------------------------------------
const onSelectRequired = () => {
if (
currentUserAction.target === target &&
(currentUserAction.type === 'attribute' ||
currentUserAction.type === 'constant' ||
currentUserAction.type === 'optional')
) {
dispatch(hideAnnotationForm());
}
dispatch(addRequired({ target }));
};

// Render ----------------------------------------------------------------------------------------------------------
return (
// Box gets rid of popper.js warning "CSS margin styles cannot be used"
<Box>
Expand Down Expand Up @@ -104,7 +121,7 @@ export const AnnotationDropdown: React.FC<AnnotationDropdownProps> = function ({
</MenuItem>
)}
{showRequired && (
<MenuItem onClick={() => dispatch(addRequired({ target }))} paddingLeft={8}>
<MenuItem onClick={onSelectRequired} paddingLeft={8}>
@required
</MenuItem>
)}
Expand Down