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

Commit 20cc147

Browse files
authored
feat(gui): comment on annotations (#909)
* feat(gui): comments for annotations * feat(gui): comments for pure and remove annotations * feat(gui): edit calledAfter annotations * fix(gui): editing calledAfter annotations created new one instead of changing old one * fix(gui): editing group annotations created new one instead of changing old one * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 49606af commit 20cc147

24 files changed

+779
-401
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ import { SaveFilterDialog } from '../features/filter/SaveFilterDialog';
6767
import { StatisticsView } from '../features/statistics/StatisticsView';
6868
import { useAnnotationToasts } from '../features/achievements/AnnotationToast';
6969
import { ValueForm } from '../features/annotations/forms/ValueForm';
70-
import { AnnotationStore } from '../features/annotations/versioning/AnnotationStoreV2';
70+
import { AnnotationStore, CalledAfterTarget } from '../features/annotations/versioning/AnnotationStoreV2';
71+
import { RemoveForm } from '../features/annotations/forms/RemoveForm';
72+
import { PureForm } from '../features/annotations/forms/PureForm';
7173

7274
export const App: React.FC = function () {
7375
useIndexedDB();
@@ -122,7 +124,14 @@ export const App: React.FC = function () {
122124
<BoundaryForm target={userActionTarget || rawPythonPackage} />
123125
)}
124126
{currentUserAction.type === 'calledAfter' && userActionTarget instanceof PythonFunction && (
125-
<CalledAfterForm target={userActionTarget} />
127+
<CalledAfterForm
128+
target={userActionTarget}
129+
calledAfterName={
130+
(currentUserAction as CalledAfterTarget)?.calledAfterName
131+
? (currentUserAction as CalledAfterTarget)?.calledAfterName
132+
: ''
133+
}
134+
/>
126135
)}
127136
{currentUserAction.type === 'description' &&
128137
(userActionTarget instanceof PythonClass ||
@@ -143,6 +152,10 @@ export const App: React.FC = function () {
143152
)}
144153
{currentUserAction.type === 'move' && <MoveForm target={userActionTarget || rawPythonPackage} />}
145154
{currentUserAction.type === 'none' && <TreeView />}
155+
{currentUserAction.type === 'pure' && <PureForm target={userActionTarget || rawPythonPackage} />}
156+
{currentUserAction.type === 'remove' && (
157+
<RemoveForm target={userActionTarget || rawPythonPackage} />
158+
)}
146159
{currentUserAction.type === 'rename' && (
147160
<RenameForm target={userActionTarget || rawPythonPackage} />
148161
)}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { Box, Button, Icon, Menu, MenuButton, MenuGroup, MenuItem, MenuList } fr
22
import React from 'react';
33
import { FaChevronDown } from 'react-icons/fa';
44
import { useAppDispatch, useAppSelector } from '../../app/hooks';
5-
import { addPureAnnotation, addRemoveAnnotation, selectComplete, selectUsernameIsValid } from './annotationSlice';
5+
import { selectComplete, selectUsernameIsValid } from './annotationSlice';
66
import {
77
showBoundaryAnnotationForm,
88
showCalledAfterAnnotationForm,
99
showDescriptionAnnotationForm,
1010
showEnumAnnotationForm,
1111
showGroupAnnotationForm,
1212
showMoveAnnotationForm,
13+
showPureAnnotationForm,
14+
showRemoveAnnotationForm,
1315
showRenameAnnotationForm,
1416
showTodoAnnotationForm,
1517
showValueAnnotationForm,
@@ -133,12 +135,12 @@ export const AnnotationDropdown: React.FC<AnnotationDropdownProps> = function ({
133135
</MenuItem>
134136
)}
135137
{showPure && (
136-
<MenuItem onClick={() => dispatch(addPureAnnotation({ target }))} paddingLeft={8}>
138+
<MenuItem onClick={() => dispatch(showPureAnnotationForm(target))} paddingLeft={8}>
137139
@pure
138140
</MenuItem>
139141
)}
140142
{showRemove && (
141-
<MenuItem onClick={() => dispatch(addRemoveAnnotation({ target }))} paddingLeft={8}>
143+
<MenuItem onClick={() => dispatch(showRemoveAnnotationForm(target))} paddingLeft={8}>
142144
@remove
143145
</MenuItem>
144146
)}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ import {
4242
hideAnnotationForm,
4343
selectCurrentUserAction,
4444
showBoundaryAnnotationForm,
45+
showCalledAfterAnnotationForm,
4546
showDescriptionAnnotationForm,
4647
showEnumAnnotationForm,
4748
showGroupAnnotationForm,
4849
showMoveAnnotationForm,
50+
showPureAnnotationForm,
51+
showRemoveAnnotationForm,
4952
showRenameAnnotationForm,
5053
showTodoAnnotationForm,
5154
showValueAnnotationForm,
@@ -111,6 +114,7 @@ export const AnnotationView: React.FC<AnnotationViewProps> = function ({ target
111114
name={calledAfterName}
112115
key={calledAfterName}
113116
annotation={calledAfterAnnotation[calledAfterName]}
117+
onEdit={() => dispatch(showCalledAfterAnnotationForm({ target, calledAfterName }))}
114118
onDelete={() => dispatch(removeCalledAfterAnnotation({ target, calledAfterName }))}
115119
onReview={() => dispatch(reviewCalledAfterAnnotation({ target, calledAfterName }))}
116120
/>
@@ -166,6 +170,7 @@ export const AnnotationView: React.FC<AnnotationViewProps> = function ({ target
166170
<AnnotationTag
167171
type="pure"
168172
annotation={pureAnnotation}
173+
onEdit={() => dispatch(showPureAnnotationForm(target))}
169174
onDelete={() => dispatch(removePureAnnotation(target))}
170175
onReview={() => dispatch(reviewPureAnnotation(target))}
171176
/>
@@ -174,6 +179,7 @@ export const AnnotationView: React.FC<AnnotationViewProps> = function ({ target
174179
<AnnotationTag
175180
type="remove"
176181
annotation={removeAnnotation}
182+
onEdit={() => dispatch(showRemoveAnnotationForm(target))}
177183
onDelete={() => dispatch(removeRemoveAnnotation(target))}
178184
onReview={() => dispatch(reviewRemoveAnnotation(target))}
179185
reportable
@@ -271,7 +277,7 @@ interface AnnotationTagProps {
271277
type: string;
272278
name?: string;
273279
annotation: Annotation;
274-
onEdit?: () => void;
280+
onEdit: () => void;
275281
onDelete: () => void;
276282
onReview: () => void;
277283
reportable?: boolean;

api-editor/gui/src/features/annotations/annotationSlice.ts

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,32 @@ const annotationsSlice = createSlice({
189189

190190
updateQueue(state);
191191
},
192-
upsertCalledAfterAnnotation(state, action: PayloadAction<CalledAfterAnnotation>) {
193-
if (!state.annotations.calledAfterAnnotations[action.payload.target]) {
194-
state.annotations.calledAfterAnnotations[action.payload.target] = {};
192+
upsertCalledAfterAnnotation(
193+
state,
194+
action: PayloadAction<{ annotation: CalledAfterAnnotation; previousCalledAfterName?: string }>,
195+
) {
196+
const oldAnnotation =
197+
state.annotations.calledAfterAnnotations[action.payload.annotation.target][
198+
action.payload.previousCalledAfterName ?? ''
199+
];
200+
201+
if (!state.annotations.calledAfterAnnotations[action.payload.annotation.target]) {
202+
state.annotations.calledAfterAnnotations[action.payload.annotation.target] = {};
195203
}
196204

197-
updateCreationOrChangedCount(
198-
state,
199-
state.annotations.calledAfterAnnotations[action.payload.target][action.payload.calledAfterName],
200-
);
205+
updateCreationOrChangedCount(state, oldAnnotation);
206+
207+
state.annotations.calledAfterAnnotations[action.payload.annotation.target][
208+
action.payload.annotation.calledAfterName
209+
] = withAuthorAndReviewers(oldAnnotation, action.payload.annotation, state.username);
210+
211+
// Delete old annotation
212+
if (action.payload.previousCalledAfterName !== action.payload.annotation.calledAfterName) {
213+
delete state.annotations.calledAfterAnnotations[action.payload.annotation.target][
214+
action.payload.previousCalledAfterName ?? ''
215+
];
216+
}
201217

202-
state.annotations.calledAfterAnnotations[action.payload.target][action.payload.calledAfterName] =
203-
withAuthorAndReviewers(
204-
state.annotations.calledAfterAnnotations[action.payload.target][action.payload.calledAfterName],
205-
action.payload,
206-
state.username,
207-
);
208218
updateQueue(state);
209219
},
210220
removeCalledAfterAnnotation(state, action: PayloadAction<CalledAfterTarget>) {
@@ -310,19 +320,27 @@ const annotationsSlice = createSlice({
310320

311321
updateQueue(state);
312322
},
313-
upsertGroupAnnotation(state, action: PayloadAction<GroupAnnotation>) {
314-
if (!state.annotations.groupAnnotations[action.payload.target]) {
315-
state.annotations.groupAnnotations[action.payload.target] = {};
323+
upsertGroupAnnotation(
324+
state,
325+
action: PayloadAction<{ previousGroupName?: string; annotation: GroupAnnotation }>,
326+
) {
327+
const oldAnnotation =
328+
state.annotations.groupAnnotations[action.payload.annotation.target][
329+
action.payload.previousGroupName ?? ''
330+
];
331+
332+
if (!state.annotations.groupAnnotations[action.payload.annotation.target]) {
333+
state.annotations.groupAnnotations[action.payload.annotation.target] = {};
316334
} else {
317-
const targetGroups = state.annotations.groupAnnotations[action.payload.target];
335+
const targetGroups = state.annotations.groupAnnotations[action.payload.annotation.target];
318336
const otherGroupNames = Object.values(targetGroups)
319-
.filter((group) => group.groupName !== action.payload.groupName)
337+
.filter((group) => group.groupName !== action.payload.annotation.groupName)
320338
.map((group) => group.groupName);
321339

322340
for (const nameOfGroup of otherGroupNames) {
323341
let needsChange = false;
324342
const group = targetGroups[nameOfGroup];
325-
const currentAnnotationParameter = action.payload.parameters;
343+
const currentAnnotationParameter = action.payload.annotation.parameters;
326344
const currentGroupParameter = [...group.parameters];
327345
for (const parameter of currentAnnotationParameter) {
328346
const index = currentGroupParameter.indexOf(parameter);
@@ -333,7 +351,7 @@ const annotationsSlice = createSlice({
333351
}
334352
if (currentGroupParameter.length < 1) {
335353
removeGroupAnnotation({
336-
target: action.payload.target,
354+
target: action.payload.annotation.target,
337355
groupName: group.groupName,
338356
});
339357
} else if (needsChange) {
@@ -350,17 +368,17 @@ const annotationsSlice = createSlice({
350368
}
351369
}
352370

353-
updateCreationOrChangedCount(
354-
state,
355-
state.annotations.groupAnnotations[action.payload.target][action.payload.groupName],
356-
);
371+
updateCreationOrChangedCount(state, oldAnnotation);
357372

358-
state.annotations.groupAnnotations[action.payload.target][action.payload.groupName] =
359-
withAuthorAndReviewers(
360-
state.annotations.groupAnnotations[action.payload.target][action.payload.groupName],
361-
action.payload,
362-
state.username,
363-
);
373+
state.annotations.groupAnnotations[action.payload.annotation.target][action.payload.annotation.groupName] =
374+
withAuthorAndReviewers(oldAnnotation, action.payload.annotation, state.username);
375+
376+
// Delete old annotation
377+
if (action.payload.previousGroupName !== action.payload.annotation.groupName) {
378+
delete state.annotations.groupAnnotations[action.payload.annotation.target][
379+
action.payload.previousGroupName ?? ''
380+
];
381+
}
364382

365383
updateQueue(state);
366384
},
@@ -424,7 +442,7 @@ const annotationsSlice = createSlice({
424442

425443
updateQueue(state);
426444
},
427-
addPureAnnotation(state, action: PayloadAction<PureAnnotation>) {
445+
upsertPureAnnotation(state, action: PayloadAction<PureAnnotation>) {
428446
updateCreationOrChangedCount(state, state.annotations.pureAnnotations[action.payload.target]);
429447

430448
state.annotations.pureAnnotations[action.payload.target] = withAuthorAndReviewers(
@@ -448,7 +466,7 @@ const annotationsSlice = createSlice({
448466

449467
updateQueue(state);
450468
},
451-
addRemoveAnnotation(state, action: PayloadAction<RemoveAnnotation>) {
469+
upsertRemoveAnnotation(state, action: PayloadAction<RemoveAnnotation>) {
452470
updateCreationOrChangedCount(state, state.annotations.removeAnnotations[action.payload.target]);
453471

454472
state.annotations.removeAnnotations[action.payload.target] = withAuthorAndReviewers(
@@ -459,7 +477,7 @@ const annotationsSlice = createSlice({
459477

460478
updateQueue(state);
461479
},
462-
addRemoveAnnotations(state, action: PayloadAction<RemoveAnnotation[]>) {
480+
upsertRemoveAnnotations(state, action: PayloadAction<RemoveAnnotation[]>) {
463481
action.payload.forEach((annotation) => {
464482
updateCreationOrChangedCount(state, state.annotations.removeAnnotations[annotation.target]);
465483

@@ -697,11 +715,11 @@ export const {
697715
upsertMoveAnnotations,
698716
removeMoveAnnotation,
699717
reviewMoveAnnotation,
700-
addPureAnnotation,
718+
upsertPureAnnotation,
701719
removePureAnnotation,
702720
reviewPureAnnotation,
703-
addRemoveAnnotation,
704-
addRemoveAnnotations,
721+
upsertRemoveAnnotation,
722+
upsertRemoveAnnotations,
705723
removeRemoveAnnotation,
706724
reviewRemoveAnnotation,
707725
upsertRenameAnnotation,

api-editor/gui/src/features/annotations/batchforms/DestinationBatchForm.tsx

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)