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

Commit 2d700df

Browse files
Masaralars-reimann
andauthored
feat: Added undo and redo buttons for annotation editing (#665)
* feat: Added undo and redo buttons for annotation editing. Importing annotations are broken * revert(gui): changes to filter files * fix(gui): build errors * style: apply automatic fixes of linters * feat(gui): update access keys * fix(gui): array bounds check * fix(gui): crash when element in tree view is selected * style: apply automatic fixes of linters * feat(gui): allow undoing annotation import * feat(gui): allow undoing "delete all annotations" * style: apply automatic fixes of linters * feat(gui): allow undoing batch operations * feat(gui): reduce code duplication * style: apply automatic fixes of linters Co-authored-by: Lars Reimann <[email protected]> Co-authored-by: lars-reimann <[email protected]>
1 parent 566ba8f commit 2d700df

File tree

12 files changed

+253
-114
lines changed

12 files changed

+253
-114
lines changed

api-editor/gui/src/app/App.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
AnnotationStore,
1919
initializeAnnotations,
2020
persistAnnotations,
21-
selectAnnotations,
21+
selectAnnotationSlice,
22+
selectAnnotationStore,
2223
} from '../features/annotations/annotationSlice';
2324
import { BoundaryForm } from '../features/annotations/forms/BoundaryForm';
2425
import { CalledAfterForm } from '../features/annotations/forms/CalledAfterForm';
@@ -71,7 +72,7 @@ export const App: React.FC = function () {
7172
useIndexedDB();
7273

7374
const rawPythonPackage = useAppSelector(selectRawPythonPackage);
74-
const annotationStore = useAppSelector(selectAnnotations);
75+
const annotationStore = useAppSelector(selectAnnotationStore);
7576
const usages = useAppSelector(selectUsages);
7677
const filter = useAppSelector(selectFilter);
7778

@@ -233,7 +234,7 @@ const useIndexedDB = function () {
233234

234235
const usePersistentAnnotations = function () {
235236
const dispatch = useAppDispatch();
236-
const annotationStore = useAppSelector(selectAnnotations);
237+
const annotationSlice = useAppSelector(selectAnnotationSlice);
237238
const [isInitialized, setIsInitialized] = useState(false);
238239

239240
useEffect(() => {
@@ -245,9 +246,9 @@ const usePersistentAnnotations = function () {
245246

246247
useEffect(() => {
247248
if (isInitialized) {
248-
dispatch(persistAnnotations(annotationStore));
249+
dispatch(persistAnnotations(annotationSlice));
249250
}
250-
}, [dispatch, annotationStore, isInitialized]);
251+
}, [dispatch, annotationSlice, isInitialized]);
251252
};
252253

253254
const usePersistentAPIState = function () {

api-editor/gui/src/common/DeleteAllAnnotations.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '@chakra-ui/react';
1313
import React, { useRef, useState } from 'react';
1414
import { useAppDispatch } from '../app/hooks';
15-
import { resetAnnotations } from '../features/annotations/annotationSlice';
15+
import { resetAnnotationStore } from '../features/annotations/annotationSlice';
1616

1717
export const DeleteAllAnnotations = function () {
1818
const dispatch = useAppDispatch();
@@ -22,7 +22,7 @@ export const DeleteAllAnnotations = function () {
2222
// Event handlers ----------------------------------------------------------
2323

2424
const handleConfirm = () => {
25-
dispatch(resetAnnotations());
25+
dispatch(resetAnnotationStore());
2626
setIsOpen(false);
2727
};
2828
const handleCancel = () => setIsOpen(false);

api-editor/gui/src/common/GenerateAdapters.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '@chakra-ui/react';
1717
import React, { useRef, useState } from 'react';
1818
import { useAppSelector } from '../app/hooks';
19-
import { selectAnnotations } from '../features/annotations/annotationSlice';
19+
import { selectAnnotationStore } from '../features/annotations/annotationSlice';
2020
import { AnnotatedPythonPackageBuilder } from '../features/annotatedPackageData/model/AnnotatedPythonPackageBuilder';
2121
import { selectRawPythonPackage } from '../features/packageData/apiSlice';
2222

@@ -30,7 +30,7 @@ export const GenerateAdapters: React.FC<GenerateAdaptersProps> = function ({ dis
3030
const [shouldValidate, setShouldValidate] = useState(false);
3131
const cancelRef = useRef(null);
3232

33-
const annotationStore = useAppSelector(selectAnnotations);
33+
const annotationStore = useAppSelector(selectAnnotationStore);
3434
const pythonPackage = useAppSelector(selectRawPythonPackage);
3535

3636
const packageNameIsValid = !shouldValidate || newPackageName !== '';

api-editor/gui/src/common/MenuBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import React from 'react';
2020
import { FaChevronDown } from 'react-icons/fa';
2121
import { useAppDispatch, useAppSelector } from '../app/hooks';
22-
import { selectAnnotations } from '../features/annotations/annotationSlice';
22+
import { selectAnnotationStore } from '../features/annotations/annotationSlice';
2323
import { FilterHelpButton } from './FilterHelpButton';
2424
import {
2525
BatchMode,
@@ -49,7 +49,7 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
4949
const dispatch = useAppDispatch();
5050
const navigate = useNavigate();
5151

52-
const annotationStore = useAppSelector(selectAnnotations);
52+
const annotationStore = useAppSelector(selectAnnotationStore);
5353
const sortingMode = useAppSelector(selectSortingMode);
5454
const heatMapMode = useAppSelector(selectHeatMapMode);
5555

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ import React, { useState } from 'react';
1717
import { useAppDispatch } from '../../app/hooks';
1818
import { StyledDropzone } from '../../common/StyledDropzone';
1919
import { isValidJsonFile } from '../../common/util/validation';
20-
import { AnnotationStore, initialState, mergeAnnotations, setAnnotations } from './annotationSlice';
20+
import { AnnotationStore, initialAnnotationStore, mergeAnnotationStore, setAnnotationStore } from './annotationSlice';
2121
import { hideAnnotationImportDialog, toggleAnnotationImportDialog } from '../ui/uiSlice';
2222

2323
export const AnnotationImportDialog: React.FC = function () {
2424
const [fileName, setFileName] = useState('');
25-
const [newAnnotationStore, setNewAnnotationStore] = useState<AnnotationStore>(initialState);
25+
const [newAnnotationStore, setNewAnnotationStore] = useState<AnnotationStore>(initialAnnotationStore);
2626
const dispatch = useAppDispatch();
2727

2828
const merge = () => {
2929
if (fileName) {
30-
dispatch(mergeAnnotations(newAnnotationStore));
30+
dispatch(mergeAnnotationStore(newAnnotationStore));
3131
}
3232
dispatch(hideAnnotationImportDialog());
3333
};
3434
const replace = () => {
3535
if (fileName) {
36-
dispatch(setAnnotations(newAnnotationStore));
36+
dispatch(setAnnotationStore(newAnnotationStore));
3737
}
3838
dispatch(hideAnnotationImportDialog());
3939
};

0 commit comments

Comments
 (0)