From c77c2c1fae1a12022efb08ece0451ddf8184ac7b Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sun, 3 Jul 2022 21:26:00 +0200 Subject: [PATCH 1/6] feat(gui): comments for annotations --- .../batchforms/DestinationBatchForm.tsx | 92 ------------- .../annotations/batchforms/EmptyBatchForm.tsx | 65 ---------- .../annotations/batchforms/MoveBatchForm.tsx | 108 +++++++++++++++- .../batchforms/OldNewBatchForm.tsx | 105 --------------- .../batchforms/RemoveBatchForm.tsx | 90 ++++++++++++- .../batchforms/RenameBatchForm.tsx | 121 +++++++++++++++++- .../annotations/batchforms/ValueBatchForm.tsx | 10 ++ .../annotations/forms/BoundaryForm.tsx | 52 +++++--- .../annotations/forms/CalledAfterForm.tsx | 10 +- .../annotations/forms/DescriptionForm.tsx | 16 ++- .../features/annotations/forms/EnumForm.tsx | 19 ++- .../features/annotations/forms/GroupForm.tsx | 36 ++++-- .../features/annotations/forms/MoveForm.tsx | 19 ++- .../features/annotations/forms/RenameForm.tsx | 18 ++- .../features/annotations/forms/TodoForm.tsx | 16 ++- .../features/annotations/forms/ValueForm.tsx | 60 +++++---- .../versioning/AnnotationStoreV2.ts | 5 + 17 files changed, 498 insertions(+), 344 deletions(-) delete mode 100644 api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx delete mode 100644 api-editor/gui/src/features/annotations/batchforms/EmptyBatchForm.tsx delete mode 100644 api-editor/gui/src/features/annotations/batchforms/OldNewBatchForm.tsx diff --git a/api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx b/api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx deleted file mode 100644 index a7384dfba..000000000 --- a/api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { FormControl, FormErrorIcon, FormErrorMessage, FormLabel, Input, Text as ChakraText } from '@chakra-ui/react'; -import React, { useState } from 'react'; -import { useForm } from 'react-hook-form'; -import { useAppDispatch } from '../../../app/hooks'; -import { PythonDeclaration } from '../../packageData/model/PythonDeclaration'; -import { AnnotationBatchForm } from './AnnotationBatchForm'; -import { hideAnnotationForm } from '../../ui/uiSlice'; -import { ConfirmAnnotations } from './ConfirmAnnotations'; - -interface DestinationBatchFormProps { - targets: PythonDeclaration[]; - annotationType: string; - description: string; - onUpsertAnnotation: (data: DestinationBatchFormState) => void; -} - -export interface DestinationBatchFormState { - destination: string; -} - -export const DestinationBatchForm: React.FC = function ({ - targets, - annotationType, - description, - onUpsertAnnotation, -}) { - const dispatch = useAppDispatch(); - - const { - handleSubmit, - register, - formState: { errors }, - } = useForm({ - defaultValues: { - destination: '', - }, - }); - - let [confirmWindowVisible, setConfirmWindowVisible] = useState(false); - let [data, setData] = useState({ destination: '' }); - - // Event handlers ---------------------------------------------------------- - - const handleSave = (annotationData: DestinationBatchFormState) => { - onUpsertAnnotation({ ...annotationData }); - - setConfirmWindowVisible(false); - dispatch(hideAnnotationForm()); - }; - - const handleConfirm = (newData: DestinationBatchFormState) => { - setData(newData); - setConfirmWindowVisible(true); - }; - - const handleCancel = () => { - dispatch(hideAnnotationForm()); - }; - // Rendering ------------------------------------------------------------------------------------------------------- - - return ( - <> - - - Destination module: - - - {errors.destination?.message} - - - - This will annotate classes and global functions. - - {confirmWindowVisible && ( - handleSave(data)} - setConfirmVisible={setConfirmWindowVisible} - /> - )} - - ); -}; diff --git a/api-editor/gui/src/features/annotations/batchforms/EmptyBatchForm.tsx b/api-editor/gui/src/features/annotations/batchforms/EmptyBatchForm.tsx deleted file mode 100644 index 79dd5211a..000000000 --- a/api-editor/gui/src/features/annotations/batchforms/EmptyBatchForm.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { FormLabel } from '@chakra-ui/react'; -import React, { useState } from 'react'; -import { useAppDispatch } from '../../../app/hooks'; -import { PythonDeclaration } from '../../packageData/model/PythonDeclaration'; -import { AnnotationBatchForm } from './AnnotationBatchForm'; -import { hideAnnotationForm } from '../../ui/uiSlice'; -import { ConfirmAnnotations } from './ConfirmAnnotations'; - -interface EmptyBatchFormProps { - targets: PythonDeclaration[]; - annotationType: string; - description: string; - onUpsertAnnotation: () => void; - targetLabel: string; -} - -export const EmptyBatchForm: React.FC = function ({ - targets, - annotationType, - description, - onUpsertAnnotation, - targetLabel, -}) { - const dispatch = useAppDispatch(); - - let [confirmWindowVisible, setConfirmWindowVisible] = useState(false); - - // Event handlers ---------------------------------------------------------- - - const handleSave = () => { - onUpsertAnnotation(); - - setConfirmWindowVisible(false); - dispatch(hideAnnotationForm()); - }; - - const handleConfirm = () => { - setConfirmWindowVisible(true); - }; - - const handleCancel = () => { - dispatch(hideAnnotationForm()); - }; - // Rendering ------------------------------------------------------------------------------------------------------- - - return ( - <> - - {targetLabel} - - {confirmWindowVisible && ( - handleSave()} - setConfirmVisible={setConfirmWindowVisible} - /> - )} - - ); -}; diff --git a/api-editor/gui/src/features/annotations/batchforms/MoveBatchForm.tsx b/api-editor/gui/src/features/annotations/batchforms/MoveBatchForm.tsx index 0e4f98e86..c6651c32d 100644 --- a/api-editor/gui/src/features/annotations/batchforms/MoveBatchForm.tsx +++ b/api-editor/gui/src/features/annotations/batchforms/MoveBatchForm.tsx @@ -1,11 +1,23 @@ -import React from 'react'; +import React, { useState } from 'react'; import { useAppDispatch } from '../../../app/hooks'; import { PythonDeclaration } from '../../packageData/model/PythonDeclaration'; import { PythonClass } from '../../packageData/model/PythonClass'; -import { DestinationBatchForm, DestinationBatchFormState } from './DestinationBatchForm'; import { PythonFunction } from '../../packageData/model/PythonFunction'; import { MoveAnnotation } from '../versioning/AnnotationStoreV2'; import { upsertMoveAnnotations } from '../annotationSlice'; +import { hideAnnotationForm } from '../../ui/uiSlice'; +import { AnnotationBatchForm } from './AnnotationBatchForm'; +import { ConfirmAnnotations } from './ConfirmAnnotations'; +import { + FormControl, + FormErrorIcon, + FormErrorMessage, + FormLabel, + Input, + Text as ChakraText, + Textarea, +} from '@chakra-ui/react'; +import { useForm } from 'react-hook-form'; interface MoveBatchFormProps { targets: PythonDeclaration[]; @@ -28,6 +40,7 @@ export const MoveBatchForm: React.FC = function ({ targets } all.push({ target: targetPath, destination: data.destination, + comment: data.comment, }); }); dispatch(upsertMoveAnnotations(all)); @@ -44,3 +57,94 @@ export const MoveBatchForm: React.FC = function ({ targets } /> ); }; + +interface DestinationBatchFormProps { + targets: PythonDeclaration[]; + annotationType: string; + description: string; + onUpsertAnnotation: (data: DestinationBatchFormState) => void; +} + +export interface DestinationBatchFormState { + destination: string; + comment: string; +} + +export const DestinationBatchForm: React.FC = function ({ + targets, + annotationType, + description, + onUpsertAnnotation, + }) { + const dispatch = useAppDispatch(); + + const { + handleSubmit, + register, + formState: { errors }, + } = useForm({ + defaultValues: { + destination: '', + comment: '', + }, + }); + + let [confirmWindowVisible, setConfirmWindowVisible] = useState(false); + let [data, setData] = useState({ destination: '', comment: '' }); + + // Event handlers ---------------------------------------------------------- + + const handleSave = (annotationData: DestinationBatchFormState) => { + onUpsertAnnotation({ ...annotationData }); + + setConfirmWindowVisible(false); + dispatch(hideAnnotationForm()); + }; + + const handleConfirm = (newData: DestinationBatchFormState) => { + setData(newData); + setConfirmWindowVisible(true); + }; + + const handleCancel = () => { + dispatch(hideAnnotationForm()); + }; + // Rendering ------------------------------------------------------------------------------------------------------- + + return ( + <> + + + Destination module: + + + {errors.destination?.message} + + + + + Comment: +