@@ -39,6 +39,7 @@ export default class Browser extends DashboardView {
39
39
this . section = 'Core' ;
40
40
this . subsection = 'Browser'
41
41
this . action = new SidebarAction ( 'Create a class' , this . showCreateClass . bind ( this ) ) ;
42
+ this . noteTimeout = null ;
42
43
43
44
this . state = {
44
45
showCreateClassDialog : false ,
@@ -62,6 +63,8 @@ export default class Browser extends DashboardView {
62
63
newObject : null ,
63
64
64
65
lastError : null ,
66
+ lastNote : null ,
67
+
65
68
relationCount : 0 ,
66
69
} ;
67
70
@@ -225,7 +228,8 @@ export default class Browser extends DashboardView {
225
228
if ( msg ) {
226
229
msg = msg [ 0 ] . toUpperCase ( ) + msg . substr ( 1 ) ;
227
230
}
228
- this . setState ( { lastError : msg } ) ;
231
+
232
+ this . showNote ( msg , true ) ;
229
233
} ) ;
230
234
}
231
235
@@ -480,8 +484,13 @@ export default class Browser extends DashboardView {
480
484
} else {
481
485
obj . set ( attr , value ) ;
482
486
}
483
- obj . save ( null , { useMasterKey : true } ) . then ( ( ) => {
484
- const state = { data : this . state . data , lastError : null } ;
487
+ obj . save ( null , { useMasterKey : true } ) . then ( ( objectSaved ) => {
488
+ const createdOrUpdated = isNewObject ? "created" : "updated" ;
489
+ let msg = objectSaved . className + " with id '" + objectSaved . id + "' " + createdOrUpdated ;
490
+ this . showNote ( msg , false ) ;
491
+
492
+ const state = { data : this . state . data } ;
493
+
485
494
if ( isNewObject ) {
486
495
const relation = this . state . relation ;
487
496
if ( relation ) {
@@ -508,7 +517,8 @@ export default class Browser extends DashboardView {
508
517
msg = msg [ 0 ] . toUpperCase ( ) + msg . substr ( 1 ) ;
509
518
}
510
519
obj . set ( attr , prev ) ;
511
- this . setState ( { data : this . state . data , lastError : msg } ) ;
520
+ this . setState ( { data : this . state . data } ) ;
521
+ this . showNote ( msg , true ) ;
512
522
} ) ;
513
523
} else {
514
524
state . newObject = null ;
@@ -526,10 +536,10 @@ export default class Browser extends DashboardView {
526
536
}
527
537
if ( ! isNewObject ) {
528
538
obj . set ( attr , prev ) ;
529
- this . setState ( { data : this . state . data , lastError : msg } ) ;
530
- } else {
531
- this . setState ( { lastError : msg } ) ;
539
+ this . setState ( { data : this . state . data } ) ;
532
540
}
541
+
542
+ this . showNote ( msg , true ) ;
533
543
} ) ;
534
544
}
535
545
@@ -561,6 +571,10 @@ export default class Browser extends DashboardView {
561
571
toDelete . push ( this . state . data [ i ] ) ;
562
572
}
563
573
}
574
+
575
+ const toDeleteObjectIds = [ ] ;
576
+ toDelete . forEach ( ( obj ) => { toDeleteObjectIds . push ( obj . id ) ; } ) ;
577
+
564
578
let relation = this . state . relation ;
565
579
if ( relation && toDelete . length ) {
566
580
relation . remove ( toDelete ) ;
@@ -576,13 +590,43 @@ export default class Browser extends DashboardView {
576
590
} ) ;
577
591
} else if ( toDelete . length ) {
578
592
Parse . Object . destroyAll ( toDelete , { useMasterKey : true } ) . then ( ( ) => {
593
+ let deletedNote ;
594
+
595
+ if ( toDeleteObjectIds . length == 1 ) {
596
+ deletedNote = className + " with id '" + toDeleteObjectIds [ 0 ] + "' deleted" ;
597
+ } else {
598
+ deletedNote = toDeleteObjectIds . length + " " + className + " objects deleted" ;
599
+ }
600
+
601
+ this . showNote ( deletedNote , false ) ;
602
+
579
603
if ( this . props . params . className === className ) {
580
604
for ( let i = 0 ; i < indexes . length ; i ++ ) {
581
605
this . state . data . splice ( indexes [ i ] - i , 1 ) ;
582
606
}
583
607
this . state . counts [ className ] -= indexes . length ;
584
608
this . forceUpdate ( ) ;
585
609
}
610
+ } , ( error ) => {
611
+ let errorDeletingNote = null ;
612
+
613
+ if ( error . code === Parse . Error . AGGREGATE_ERROR ) {
614
+ if ( error . errors . length == 1 ) {
615
+ errorDeletingNote = "Error deleting " + className + " with id '" + error . errors [ 0 ] . object . id + "'" ;
616
+ } else if ( error . errors . length < toDeleteObjectIds . length ) {
617
+ errorDeletingNote = "Error deleting " + error . errors . length + " out of " + toDeleteObjectIds . length + " " + className + " objects" ;
618
+ } else {
619
+ errorDeletingNote = "Error deleting all " + error . errors . length + " " + className + " objects" ;
620
+ }
621
+ } else {
622
+ if ( toDeleteObjectIds . length == 1 ) {
623
+ errorDeletingNote = "Error deleting " + className + " with id '" + toDeleteObjectIds [ 0 ] + "'" ;
624
+ } else {
625
+ errorDeletingNote = "Error deleting " + toDeleteObjectIds . length + " " + className + " objects" ;
626
+ }
627
+ }
628
+
629
+ this . showNote ( errorDeletingNote , true ) ;
586
630
} ) ;
587
631
}
588
632
}
@@ -748,6 +792,24 @@ export default class Browser extends DashboardView {
748
792
) ;
749
793
}
750
794
795
+ showNote ( message , isError ) {
796
+ if ( ! message ) {
797
+ return ;
798
+ }
799
+
800
+ clearTimeout ( this . noteTimeout ) ;
801
+
802
+ if ( isError ) {
803
+ this . setState ( { lastError : message , lastNote : null } ) ;
804
+ } else {
805
+ this . setState ( { lastNote : message , lastError : null } ) ;
806
+ }
807
+
808
+ this . noteTimeout = setTimeout ( ( ) => {
809
+ this . setState ( { lastError : null , lastNote : null } ) ;
810
+ } , 3500 ) ;
811
+ }
812
+
751
813
renderContent ( ) {
752
814
let browser = null ;
753
815
let className = this . props . params . className ;
@@ -886,6 +948,7 @@ export default class Browser extends DashboardView {
886
948
onCancel = { ( ) => this . setState ( {
887
949
showDropClassDialog : false ,
888
950
lastError : null ,
951
+ lastNote : null ,
889
952
} ) }
890
953
onConfirm = { ( ) => this . dropClass ( className ) } />
891
954
) ;
@@ -915,10 +978,22 @@ export default class Browser extends DashboardView {
915
978
/>
916
979
) ;
917
980
}
981
+
982
+ let notification = null ;
983
+
984
+ if ( this . state . lastError ) {
985
+ notification = (
986
+ < Notification note = { this . state . lastError } isErrorNote = { true } />
987
+ ) ;
988
+ } else if ( this . state . lastNote ) {
989
+ notification = (
990
+ < Notification note = { this . state . lastNote } isErrorNote = { false } />
991
+ ) ;
992
+ }
918
993
return (
919
994
< div >
920
995
{ browser }
921
- < Notification note = { this . state . lastError } />
996
+ { notification }
922
997
{ extras }
923
998
</ div >
924
999
) ;
0 commit comments