@@ -23,6 +23,7 @@ import {
23
23
ValueAnnotation ,
24
24
} from './versioning/AnnotationStoreV2' ;
25
25
import { migrateAnnotationStoreToCurrentVersion } from './versioning/migrations' ;
26
+ import { isEqual } from 'lodash/fp' ;
26
27
27
28
export const EXPECTED_ANNOTATION_SLICE_SCHEMA_VERSION = 1 ;
28
29
@@ -167,7 +168,11 @@ const annotationsSlice = createSlice({
167
168
updateQueue ( state ) ;
168
169
} ,
169
170
upsertBoundaryAnnotation ( state , action : PayloadAction < BoundaryAnnotation > ) {
170
- updateCreationOrChangedCount ( state , state . annotations . boundaryAnnotations [ action . payload . target ] ) ;
171
+ updateCreationOrChangedCount (
172
+ state ,
173
+ state . annotations . boundaryAnnotations [ action . payload . target ] ,
174
+ action . payload ,
175
+ ) ;
171
176
172
177
state . annotations . boundaryAnnotations [ action . payload . target ] = withAuthorAndReviewers (
173
178
state . annotations . boundaryAnnotations [ action . payload . target ] ,
@@ -204,7 +209,7 @@ const annotationsSlice = createSlice({
204
209
state . annotations . calledAfterAnnotations [ action . payload . annotation . target ] = { } ;
205
210
}
206
211
207
- updateCreationOrChangedCount ( state , oldAnnotation ) ;
212
+ updateCreationOrChangedCount ( state , oldAnnotation , action . payload . annotation ) ;
208
213
209
214
state . annotations . calledAfterAnnotations [ action . payload . annotation . target ] [
210
215
action . payload . annotation . calledAfterName
@@ -282,7 +287,11 @@ const annotationsSlice = createSlice({
282
287
} ,
283
288
// Cannot review complete annotations
284
289
upsertDescriptionAnnotation ( state , action : PayloadAction < DescriptionAnnotation > ) {
285
- updateCreationOrChangedCount ( state , state . annotations . descriptionAnnotations [ action . payload . target ] ) ;
290
+ updateCreationOrChangedCount (
291
+ state ,
292
+ state . annotations . descriptionAnnotations [ action . payload . target ] ,
293
+ action . payload ,
294
+ ) ;
286
295
287
296
state . annotations . descriptionAnnotations [ action . payload . target ] = withAuthorAndReviewers (
288
297
state . annotations . descriptionAnnotations [ action . payload . target ] ,
@@ -307,7 +316,11 @@ const annotationsSlice = createSlice({
307
316
updateQueue ( state ) ;
308
317
} ,
309
318
upsertEnumAnnotation ( state , action : PayloadAction < EnumAnnotation > ) {
310
- updateCreationOrChangedCount ( state , state . annotations . enumAnnotations [ action . payload . target ] ) ;
319
+ updateCreationOrChangedCount (
320
+ state ,
321
+ state . annotations . enumAnnotations [ action . payload . target ] ,
322
+ action . payload ,
323
+ ) ;
311
324
312
325
state . annotations . enumAnnotations [ action . payload . target ] = withAuthorAndReviewers (
313
326
state . annotations . enumAnnotations [ action . payload . target ] ,
@@ -379,7 +392,7 @@ const annotationsSlice = createSlice({
379
392
}
380
393
}
381
394
382
- updateCreationOrChangedCount ( state , oldAnnotation ) ;
395
+ updateCreationOrChangedCount ( state , oldAnnotation , action . payload . annotation ) ;
383
396
384
397
state . annotations . groupAnnotations [ action . payload . annotation . target ] [ action . payload . annotation . groupName ] =
385
398
withAuthorAndReviewers ( oldAnnotation , action . payload . annotation , state . username ) ;
@@ -419,7 +432,11 @@ const annotationsSlice = createSlice({
419
432
updateQueue ( state ) ;
420
433
} ,
421
434
upsertMoveAnnotation ( state , action : PayloadAction < MoveAnnotation > ) {
422
- updateCreationOrChangedCount ( state , state . annotations . moveAnnotations [ action . payload . target ] ) ;
435
+ updateCreationOrChangedCount (
436
+ state ,
437
+ state . annotations . moveAnnotations [ action . payload . target ] ,
438
+ action . payload ,
439
+ ) ;
423
440
424
441
state . annotations . moveAnnotations [ action . payload . target ] = withAuthorAndReviewers (
425
442
state . annotations . moveAnnotations [ action . payload . target ] ,
@@ -431,7 +448,7 @@ const annotationsSlice = createSlice({
431
448
} ,
432
449
upsertMoveAnnotations ( state , action : PayloadAction < MoveAnnotation [ ] > ) {
433
450
action . payload . forEach ( ( annotation ) => {
434
- updateCreationOrChangedCount ( state , state . annotations . moveAnnotations [ annotation . target ] ) ;
451
+ updateCreationOrChangedCount ( state , state . annotations . moveAnnotations [ annotation . target ] , annotation ) ;
435
452
436
453
state . annotations . moveAnnotations [ annotation . target ] = withAuthorAndReviewers (
437
454
state . annotations . moveAnnotations [ annotation . target ] ,
@@ -457,7 +474,11 @@ const annotationsSlice = createSlice({
457
474
updateQueue ( state ) ;
458
475
} ,
459
476
upsertPureAnnotation ( state , action : PayloadAction < PureAnnotation > ) {
460
- updateCreationOrChangedCount ( state , state . annotations . pureAnnotations [ action . payload . target ] ) ;
477
+ updateCreationOrChangedCount (
478
+ state ,
479
+ state . annotations . pureAnnotations [ action . payload . target ] ,
480
+ action . payload ,
481
+ ) ;
461
482
462
483
state . annotations . pureAnnotations [ action . payload . target ] = withAuthorAndReviewers (
463
484
state . annotations . pureAnnotations [ action . payload . target ] ,
@@ -482,7 +503,11 @@ const annotationsSlice = createSlice({
482
503
updateQueue ( state ) ;
483
504
} ,
484
505
upsertRemoveAnnotation ( state , action : PayloadAction < RemoveAnnotation > ) {
485
- updateCreationOrChangedCount ( state , state . annotations . removeAnnotations [ action . payload . target ] ) ;
506
+ updateCreationOrChangedCount (
507
+ state ,
508
+ state . annotations . removeAnnotations [ action . payload . target ] ,
509
+ action . payload ,
510
+ ) ;
486
511
487
512
state . annotations . removeAnnotations [ action . payload . target ] = withAuthorAndReviewers (
488
513
state . annotations . removeAnnotations [ action . payload . target ] ,
@@ -494,7 +519,7 @@ const annotationsSlice = createSlice({
494
519
} ,
495
520
upsertRemoveAnnotations ( state , action : PayloadAction < RemoveAnnotation [ ] > ) {
496
521
action . payload . forEach ( ( annotation ) => {
497
- updateCreationOrChangedCount ( state , state . annotations . removeAnnotations [ annotation . target ] ) ;
522
+ updateCreationOrChangedCount ( state , state . annotations . removeAnnotations [ annotation . target ] , annotation ) ;
498
523
499
524
state . annotations . removeAnnotations [ annotation . target ] = withAuthorAndReviewers (
500
525
state . annotations . removeAnnotations [ annotation . target ] ,
@@ -520,7 +545,11 @@ const annotationsSlice = createSlice({
520
545
updateQueue ( state ) ;
521
546
} ,
522
547
upsertRenameAnnotation ( state , action : PayloadAction < RenameAnnotation > ) {
523
- updateCreationOrChangedCount ( state , state . annotations . renameAnnotations [ action . payload . target ] ) ;
548
+ updateCreationOrChangedCount (
549
+ state ,
550
+ state . annotations . renameAnnotations [ action . payload . target ] ,
551
+ action . payload ,
552
+ ) ;
524
553
525
554
state . annotations . renameAnnotations [ action . payload . target ] = withAuthorAndReviewers (
526
555
state . annotations . renameAnnotations [ action . payload . target ] ,
@@ -532,7 +561,7 @@ const annotationsSlice = createSlice({
532
561
} ,
533
562
upsertRenameAnnotations ( state , action : PayloadAction < RenameAnnotation [ ] > ) {
534
563
action . payload . forEach ( ( annotation ) => {
535
- updateCreationOrChangedCount ( state , state . annotations . renameAnnotations [ annotation . target ] ) ;
564
+ updateCreationOrChangedCount ( state , state . annotations . renameAnnotations [ annotation . target ] , annotation ) ;
536
565
537
566
state . annotations . renameAnnotations [ annotation . target ] = withAuthorAndReviewers (
538
567
state . annotations . renameAnnotations [ annotation . target ] ,
@@ -558,7 +587,11 @@ const annotationsSlice = createSlice({
558
587
updateQueue ( state ) ;
559
588
} ,
560
589
upsertTodoAnnotation ( state , action : PayloadAction < TodoAnnotation > ) {
561
- updateCreationOrChangedCount ( state , state . annotations . todoAnnotations [ action . payload . target ] ) ;
590
+ updateCreationOrChangedCount (
591
+ state ,
592
+ state . annotations . todoAnnotations [ action . payload . target ] ,
593
+ action . payload ,
594
+ ) ;
562
595
563
596
state . annotations . todoAnnotations [ action . payload . target ] = withAuthorAndReviewers (
564
597
state . annotations . todoAnnotations [ action . payload . target ] ,
@@ -583,7 +616,23 @@ const annotationsSlice = createSlice({
583
616
updateQueue ( state ) ;
584
617
} ,
585
618
upsertValueAnnotation ( state , action : PayloadAction < ValueAnnotation > ) {
586
- updateCreationOrChangedCount ( state , state . annotations . valueAnnotations [ action . payload . target ] ) ;
619
+ updateCreationOrChangedCount (
620
+ state ,
621
+ state . annotations . valueAnnotations [ action . payload . target ] ,
622
+ action . payload ,
623
+ ) ;
624
+
625
+ if ( action . payload . variant === 'required' || action . payload . variant === 'omitted' ) {
626
+ // @ts -ignore
627
+ delete action . payload . defaultValue ;
628
+ // @ts -ignore
629
+ delete action . payload . defaultValueType ;
630
+ }
631
+
632
+ if ( action . payload . defaultValueType === 'number' && typeof action . payload . defaultValue === 'string' ) {
633
+ // @ts -ignore
634
+ action . payload . defaultValue = parseFloat ( action . payload . defaultValue ) ;
635
+ }
587
636
588
637
state . annotations . valueAnnotations [ action . payload . target ] = withAuthorAndReviewers (
589
638
state . annotations . valueAnnotations [ action . payload . target ] ,
@@ -595,7 +644,19 @@ const annotationsSlice = createSlice({
595
644
} ,
596
645
upsertValueAnnotations ( state , action : PayloadAction < ValueAnnotation [ ] > ) {
597
646
action . payload . forEach ( ( annotation ) => {
598
- updateCreationOrChangedCount ( state , state . annotations . valueAnnotations [ annotation . target ] ) ;
647
+ updateCreationOrChangedCount ( state , state . annotations . valueAnnotations [ annotation . target ] , annotation ) ;
648
+
649
+ if ( annotation . variant === 'required' || annotation . variant === 'omitted' ) {
650
+ // @ts -ignore
651
+ delete annotation . defaultValue ;
652
+ // @ts -ignore
653
+ delete annotation . defaultValueType ;
654
+ }
655
+
656
+ if ( annotation . defaultValueType === 'number' && typeof annotation . defaultValue === 'string' ) {
657
+ // @ts -ignore
658
+ annotation . defaultValue = parseFloat ( annotation . defaultValue ) ;
659
+ }
599
660
600
661
state . annotations . valueAnnotations [ annotation . target ] = withAuthorAndReviewers (
601
662
state . annotations . valueAnnotations [ annotation . target ] ,
@@ -662,9 +723,15 @@ const updateQueue = function (state: AnnotationSlice) {
662
723
state . queueIndex = state . queueIndex + 1 ;
663
724
} ;
664
725
665
- const updateCreationOrChangedCount = function ( state : AnnotationSlice , annotationOrNull : Annotation | null ) {
666
- if ( annotationOrNull ) {
667
- state . numberOfAnnotationsChanged ++ ;
726
+ const updateCreationOrChangedCount = function (
727
+ state : AnnotationSlice ,
728
+ oldAnnotation : Annotation | null ,
729
+ newAnnotation : Annotation ,
730
+ ) {
731
+ if ( oldAnnotation ) {
732
+ if ( annotationWasChanged ( oldAnnotation , newAnnotation ) ) {
733
+ state . numberOfAnnotationsChanged ++ ;
734
+ }
668
735
} else {
669
736
state . numberOfAnnotationsCreated ++ ;
670
737
}
@@ -678,7 +745,9 @@ const withAuthorAndReviewers = function <T extends Annotation>(
678
745
let authors = oldAnnotation ?. authors ?? [ ] ;
679
746
const reviewers = oldAnnotation ?. reviewers ?? [ ] ;
680
747
681
- authors = [ ...authors . filter ( ( it ) => it !== author ) , author ] ;
748
+ if ( ! oldAnnotation || annotationWasChanged ( oldAnnotation , newAnnotation ) ) {
749
+ authors = [ ...authors . filter ( ( it ) => it !== author ) , author ] ;
750
+ }
682
751
683
752
return {
684
753
...newAnnotation ,
@@ -687,6 +756,24 @@ const withAuthorAndReviewers = function <T extends Annotation>(
687
756
} ;
688
757
} ;
689
758
759
+ const annotationWasChanged = function < T extends Annotation > ( oldAnnotation : T , newAnnotation : T ) : boolean {
760
+ // Unify the metadata, so we only compare the actual annotation data
761
+ const oldAnnotationWithoutMetadata = annotationWithoutMetadata ( oldAnnotation ) ;
762
+ const newAnnotationWithoutMetadata = annotationWithoutMetadata ( newAnnotation ) ;
763
+
764
+ return ! isEqual ( oldAnnotationWithoutMetadata , newAnnotationWithoutMetadata ) ;
765
+ } ;
766
+
767
+ const annotationWithoutMetadata = function < T extends Annotation > ( annotation : T ) : T {
768
+ return {
769
+ ...annotation ,
770
+ authors : undefined ,
771
+ reviewers : undefined ,
772
+ reviewResult : undefined ,
773
+ comment : undefined ,
774
+ } ;
775
+ } ;
776
+
690
777
const withToggledReviewer = function < T extends Annotation > (
691
778
state : AnnotationSlice ,
692
779
oldAnnotation : T ,
0 commit comments