From 06844edf244befafe0ca870b5f8d46111652b5a0 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 24 Jun 2022 18:59:30 +0200 Subject: [PATCH 1/2] refactor(gui): reuse confirmation dialog for rename batch form --- .../batchforms/ConfirmAnnotations.tsx | 8 +- .../batchforms/OldNewBatchForm.tsx | 89 ++----------------- 2 files changed, 16 insertions(+), 81 deletions(-) diff --git a/api-editor/gui/src/features/annotations/batchforms/ConfirmAnnotations.tsx b/api-editor/gui/src/features/annotations/batchforms/ConfirmAnnotations.tsx index 6ed63feea..f536ee39a 100644 --- a/api-editor/gui/src/features/annotations/batchforms/ConfirmAnnotations.tsx +++ b/api-editor/gui/src/features/annotations/batchforms/ConfirmAnnotations.tsx @@ -33,7 +33,13 @@ export const ConfirmAnnotations: React.FC = function ({ const useCancelRef = useRef(null); return ( - + diff --git a/api-editor/gui/src/features/annotations/batchforms/OldNewBatchForm.tsx b/api-editor/gui/src/features/annotations/batchforms/OldNewBatchForm.tsx index b92eb9fe2..57e5362b3 100644 --- a/api-editor/gui/src/features/annotations/batchforms/OldNewBatchForm.tsx +++ b/api-editor/gui/src/features/annotations/batchforms/OldNewBatchForm.tsx @@ -1,26 +1,11 @@ -import { - AlertDialog, - AlertDialogBody, - AlertDialogContent, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogOverlay, - Button, - FormControl, - FormErrorIcon, - FormErrorMessage, - FormLabel, - Heading, - Input, - ListItem, - UnorderedList, -} from '@chakra-ui/react'; -import React, { useRef, useState } from 'react'; +import { FormControl, FormErrorIcon, FormErrorMessage, FormLabel, Input } 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 OldNewBatchFormProps { targets: PythonDeclaration[]; @@ -51,8 +36,10 @@ export const OldNewBatchForm: React.FC = function ({ }, }); - let [confirmWindowVisible, setConfirmWindowVisible] = useState(false); - let [data, setData] = useState({ oldString: '', newString: '' }); + const [confirmWindowVisible, setConfirmWindowVisible] = useState(false); + const [data, setData] = useState({ oldString: '', newString: '' }); + + const filteredTargets = targets.filter((t) => t.name !== t.name.replace(data.oldString, data.newString)); // Event handlers ---------------------------------------------------------- @@ -71,6 +58,7 @@ export const OldNewBatchForm: React.FC = function ({ const handleCancel = () => { dispatch(hideAnnotationForm()); }; + // Rendering ------------------------------------------------------------------------------------------------------- return ( @@ -108,8 +96,7 @@ export const OldNewBatchForm: React.FC = function ({ {confirmWindowVisible && ( handleSave(data)} setConfirmVisible={setConfirmWindowVisible} /> @@ -117,61 +104,3 @@ export const OldNewBatchForm: React.FC = function ({ ); }; - -interface ConfirmAnnotationsProps { - targets: PythonDeclaration[]; - data: OldNewBatchFormState; - handleSave: () => void; - setConfirmVisible: (visible: boolean) => void; -} - -const ConfirmAnnotations: React.FC = function ({ - targets, - data, - handleSave, - setConfirmVisible, -}) { - const handleCancel = () => { - setConfirmVisible(false); - hideAnnotationForm(); - }; - - const useCancelRef = useRef(null); - - const filteredTargets = targets.filter((t) => t.name !== t.name.replace(data.oldString, data.newString)); - - return ( - - - - - This will annotate these {filteredTargets.length} items - - - - - {filteredTargets.map((target) => ( - {target.id} - ))} - - - - - - - - - - - ); -}; From 12ff95260a018415326095bfacceaf496dbeef9d Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 24 Jun 2022 19:14:50 +0200 Subject: [PATCH 2/2] feat(gui): when renaming allow empty replacement string --- .../annotations/batchforms/DestinationBatchForm.tsx | 4 ++-- .../annotations/batchforms/OldNewBatchForm.tsx | 10 +++------- .../annotations/batchforms/TypeValueBatchForm.tsx | 3 ++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx b/api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx index 58274176c..82715d8e6 100644 --- a/api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx +++ b/api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx @@ -1,4 +1,4 @@ -import { FormControl, FormErrorIcon, FormErrorMessage, FormLabel, Input } from '@chakra-ui/react'; +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'; @@ -75,7 +75,7 @@ export const DestinationBatchForm: React.FC = functio - This will annotate classes and global functions. + This will annotate classes and global functions. {confirmWindowVisible && ( = function ({ Replacement String: - + {errors.newString?.message} - This will annotate classes, functions, and parameters. + This will annotate classes, functions, and parameters. {confirmWindowVisible && ( = function ({ )} - This will annotate parameters. + This will annotate parameters. {confirmWindowVisible && (