@@ -189,22 +189,32 @@ const annotationsSlice = createSlice({
189
189
190
190
updateQueue ( state ) ;
191
191
} ,
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 ] = { } ;
195
203
}
196
204
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
+ }
201
217
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
- ) ;
208
218
updateQueue ( state ) ;
209
219
} ,
210
220
removeCalledAfterAnnotation ( state , action : PayloadAction < CalledAfterTarget > ) {
@@ -310,19 +320,27 @@ const annotationsSlice = createSlice({
310
320
311
321
updateQueue ( state ) ;
312
322
} ,
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 ] = { } ;
316
334
} else {
317
- const targetGroups = state . annotations . groupAnnotations [ action . payload . target ] ;
335
+ const targetGroups = state . annotations . groupAnnotations [ action . payload . annotation . target ] ;
318
336
const otherGroupNames = Object . values ( targetGroups )
319
- . filter ( ( group ) => group . groupName !== action . payload . groupName )
337
+ . filter ( ( group ) => group . groupName !== action . payload . annotation . groupName )
320
338
. map ( ( group ) => group . groupName ) ;
321
339
322
340
for ( const nameOfGroup of otherGroupNames ) {
323
341
let needsChange = false ;
324
342
const group = targetGroups [ nameOfGroup ] ;
325
- const currentAnnotationParameter = action . payload . parameters ;
343
+ const currentAnnotationParameter = action . payload . annotation . parameters ;
326
344
const currentGroupParameter = [ ...group . parameters ] ;
327
345
for ( const parameter of currentAnnotationParameter ) {
328
346
const index = currentGroupParameter . indexOf ( parameter ) ;
@@ -333,7 +351,7 @@ const annotationsSlice = createSlice({
333
351
}
334
352
if ( currentGroupParameter . length < 1 ) {
335
353
removeGroupAnnotation ( {
336
- target : action . payload . target ,
354
+ target : action . payload . annotation . target ,
337
355
groupName : group . groupName ,
338
356
} ) ;
339
357
} else if ( needsChange ) {
@@ -350,17 +368,17 @@ const annotationsSlice = createSlice({
350
368
}
351
369
}
352
370
353
- updateCreationOrChangedCount (
354
- state ,
355
- state . annotations . groupAnnotations [ action . payload . target ] [ action . payload . groupName ] ,
356
- ) ;
371
+ updateCreationOrChangedCount ( state , oldAnnotation ) ;
357
372
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
+ }
364
382
365
383
updateQueue ( state ) ;
366
384
} ,
@@ -424,7 +442,7 @@ const annotationsSlice = createSlice({
424
442
425
443
updateQueue ( state ) ;
426
444
} ,
427
- addPureAnnotation ( state , action : PayloadAction < PureAnnotation > ) {
445
+ upsertPureAnnotation ( state , action : PayloadAction < PureAnnotation > ) {
428
446
updateCreationOrChangedCount ( state , state . annotations . pureAnnotations [ action . payload . target ] ) ;
429
447
430
448
state . annotations . pureAnnotations [ action . payload . target ] = withAuthorAndReviewers (
@@ -448,7 +466,7 @@ const annotationsSlice = createSlice({
448
466
449
467
updateQueue ( state ) ;
450
468
} ,
451
- addRemoveAnnotation ( state , action : PayloadAction < RemoveAnnotation > ) {
469
+ upsertRemoveAnnotation ( state , action : PayloadAction < RemoveAnnotation > ) {
452
470
updateCreationOrChangedCount ( state , state . annotations . removeAnnotations [ action . payload . target ] ) ;
453
471
454
472
state . annotations . removeAnnotations [ action . payload . target ] = withAuthorAndReviewers (
@@ -459,7 +477,7 @@ const annotationsSlice = createSlice({
459
477
460
478
updateQueue ( state ) ;
461
479
} ,
462
- addRemoveAnnotations ( state , action : PayloadAction < RemoveAnnotation [ ] > ) {
480
+ upsertRemoveAnnotations ( state , action : PayloadAction < RemoveAnnotation [ ] > ) {
463
481
action . payload . forEach ( ( annotation ) => {
464
482
updateCreationOrChangedCount ( state , state . annotations . removeAnnotations [ annotation . target ] ) ;
465
483
@@ -697,11 +715,11 @@ export const {
697
715
upsertMoveAnnotations,
698
716
removeMoveAnnotation,
699
717
reviewMoveAnnotation,
700
- addPureAnnotation ,
718
+ upsertPureAnnotation ,
701
719
removePureAnnotation,
702
720
reviewPureAnnotation,
703
- addRemoveAnnotation ,
704
- addRemoveAnnotations ,
721
+ upsertRemoveAnnotation ,
722
+ upsertRemoveAnnotations ,
705
723
removeRemoveAnnotation,
706
724
reviewRemoveAnnotation,
707
725
upsertRenameAnnotation,
0 commit comments