@@ -79,10 +79,12 @@ class Browser extends DashboardView {
79
79
filters : new List ( ) ,
80
80
ordering : '-createdAt' ,
81
81
selection : { } ,
82
+ uniqueClassFields : new List ( ) ,
82
83
83
84
data : null ,
84
85
lastMax : - 1 ,
85
86
newObject : null ,
87
+ editCloneRows : null ,
86
88
87
89
lastError : null ,
88
90
lastNote : null ,
@@ -99,6 +101,7 @@ class Browser extends DashboardView {
99
101
this . fetchData = this . fetchData . bind ( this ) ;
100
102
this . fetchRelation = this . fetchRelation . bind ( this ) ;
101
103
this . fetchRelationCount = this . fetchRelationCount . bind ( this ) ;
104
+ this . fetchClassIndexes = this . fetchClassIndexes . bind ( this ) ;
102
105
this . fetchNextPage = this . fetchNextPage . bind ( this ) ;
103
106
this . updateFilters = this . updateFilters . bind ( this ) ;
104
107
this . showRemoveColumn = this . showRemoveColumn . bind ( this ) ;
@@ -141,6 +144,8 @@ class Browser extends DashboardView {
141
144
this . closeEditRowDialog = this . closeEditRowDialog . bind ( this ) ;
142
145
this . handleShowAcl = this . handleShowAcl . bind ( this ) ;
143
146
this . onDialogToggle = this . onDialogToggle . bind ( this ) ;
147
+ this . addEditCloneRows = this . addEditCloneRows . bind ( this ) ;
148
+ this . abortEditCloneRows = this . abortEditCloneRows . bind ( this ) ;
144
149
}
145
150
146
151
getFooterMenuButtons ( ) {
@@ -421,6 +426,7 @@ class Browser extends DashboardView {
421
426
this . fetchRelation ( relation , filters ) ;
422
427
} else if ( className ) {
423
428
this . fetchData ( className , filters ) ;
429
+ this . fetchClassIndexes ( className ) ;
424
430
}
425
431
}
426
432
@@ -596,6 +602,20 @@ class Browser extends DashboardView {
596
602
}
597
603
}
598
604
605
+ addEditCloneRows ( cloneRows ) {
606
+ this . setState ( {
607
+ editCloneRows : cloneRows
608
+ } ) ;
609
+ }
610
+
611
+ abortEditCloneRows ( ) {
612
+ if ( this . state . editCloneRows ) {
613
+ this . setState ( {
614
+ editCloneRows : null
615
+ } ) ;
616
+ }
617
+ }
618
+
599
619
abortAddRow ( ) {
600
620
if ( this . state . newObject ) {
601
621
this . setState ( {
@@ -647,7 +667,8 @@ class Browser extends DashboardView {
647
667
newObject : null ,
648
668
lastMax : - 1 ,
649
669
selection : { } ,
650
- relation : null
670
+ relation : null ,
671
+ editCloneRows : null
651
672
} ;
652
673
if ( relation ) {
653
674
await this . setState ( initialState ) ;
@@ -733,6 +754,24 @@ class Browser extends DashboardView {
733
754
return await this . context . currentApp . getRelationCount ( relation ) ;
734
755
}
735
756
757
+ async fetchClassIndexes ( className ) {
758
+ try {
759
+ const data = await this . context . currentApp . getIndexes ( className ) ;
760
+ if ( data ) {
761
+ this . setState ( {
762
+ uniqueClassFields : data
763
+ . filter ( idxObj => idxObj . unique )
764
+ . map ( obj => Object . keys ( JSON . parse ( obj . index ) ) )
765
+ . flat ( )
766
+ } ) ;
767
+ }
768
+ } catch ( error ) {
769
+ this . setState ( {
770
+ uniqueClassFields : [ ]
771
+ } ) ;
772
+ }
773
+ }
774
+
736
775
fetchNextPage ( ) {
737
776
if ( ! this . state . data || this . state . isUnique ) {
738
777
return null ;
@@ -860,12 +899,16 @@ class Browser extends DashboardView {
860
899
}
861
900
862
901
updateRow ( row , attr , value ) {
863
- let isNewObject = row < 0 ;
902
+ let isNewObject = row === - 1 ;
903
+ let isEditCloneObj = row < - 1 ;
864
904
let obj = isNewObject ? this . state . newObject : this . state . data [ row ] ;
865
905
if ( ! obj && isNewObject ) {
866
906
obj = this . getLastCreatedObject ( this . state . data )
867
907
isNewObject = false
868
908
}
909
+ if ( isEditCloneObj ) {
910
+ obj = this . state . editCloneRows [ row + ( this . state . editCloneRows . length + 1 ) ] ;
911
+ }
869
912
const prev = obj . get ( attr ) ;
870
913
if ( value === prev ) {
871
914
return ;
@@ -876,11 +919,11 @@ class Browser extends DashboardView {
876
919
obj . set ( attr , value ) ;
877
920
}
878
921
obj . save ( null , { useMasterKey : true } ) . then ( ( objectSaved ) => {
879
- const createdOrUpdated = isNewObject ? 'created' : 'updated' ;
922
+ const createdOrUpdated = isNewObject || isEditCloneObj ? 'created' : 'updated' ;
880
923
let msg = objectSaved . className + ' with id \'' + objectSaved . id + '\' ' + createdOrUpdated ;
881
924
this . showNote ( msg , false ) ;
882
925
883
- const state = { data : this . state . data } ;
926
+ const state = { data : this . state . data , editCloneRows : this . state . editCloneRows } ;
884
927
885
928
if ( isNewObject ) {
886
929
const relation = this . state . relation ;
@@ -919,13 +962,24 @@ class Browser extends DashboardView {
919
962
this . state . counts [ obj . className ] += 1 ;
920
963
}
921
964
}
965
+ if ( isEditCloneObj ) {
966
+ state . editCloneRows = state . editCloneRows . filter (
967
+ cloneObj => cloneObj . _localId !== obj . _localId
968
+ ) ;
969
+ if ( state . editCloneRows . length === 0 )
970
+ state . editCloneRows = null ;
971
+ if ( this . props . params . className === obj . className ) {
972
+ this . state . data . unshift ( obj ) ;
973
+ }
974
+ this . state . counts [ obj . className ] += 1 ;
975
+ }
922
976
this . setState ( state ) ;
923
977
} , ( error ) => {
924
978
let msg = typeof error === 'string' ? error : error . message ;
925
979
if ( msg ) {
926
980
msg = msg [ 0 ] . toUpperCase ( ) + msg . substr ( 1 ) ;
927
981
}
928
- if ( ! isNewObject ) {
982
+ if ( ! isNewObject && ! isEditCloneObj ) {
929
983
obj . set ( attr , prev ) ;
930
984
this . setState ( { data : this . state . data } ) ;
931
985
}
@@ -1161,6 +1215,17 @@ class Browser extends DashboardView {
1161
1215
try {
1162
1216
await Parse . Object . saveAll ( toClone , { useMasterKey : true } ) ;
1163
1217
} catch ( error ) {
1218
+ if ( error . code === 137 ) {
1219
+ const newClonedObjects = [ ] ;
1220
+ toClone . forEach ( cloneObj => {
1221
+ this . state . uniqueClassFields . forEach ( field => {
1222
+ const fieldType = typeof cloneObj . get ( field ) ;
1223
+ cloneObj . set ( field , fieldType === 'string' ? '' : undefined ) ;
1224
+ } ) ;
1225
+ newClonedObjects . push ( cloneObj ) ;
1226
+ } ) ;
1227
+ this . addEditCloneRows ( newClonedObjects ) ;
1228
+ }
1164
1229
this . setState ( {
1165
1230
selection : { } ,
1166
1231
showCloneSelectedRowsDialog : false
@@ -1348,6 +1413,7 @@ class Browser extends DashboardView {
1348
1413
uniqueField = { this . state . uniqueField }
1349
1414
count = { count }
1350
1415
perms = { this . state . clp [ className ] }
1416
+ editCloneRows = { this . state . editCloneRows }
1351
1417
schema = { this . props . schema }
1352
1418
filters = { this . state . filters }
1353
1419
onFilterChange = { this . updateFilters }
@@ -1385,6 +1451,7 @@ class Browser extends DashboardView {
1385
1451
onAbortAddRow = { this . abortAddRow }
1386
1452
onAddRowWithModal = { this . addRowWithModal }
1387
1453
onAddClass = { this . showCreateClass }
1454
+ onAbortEditCloneRows = { this . abortEditCloneRows }
1388
1455
err = { this . state . err }
1389
1456
showNote = { this . showNote }
1390
1457
onClickIndexManager = { this . onClickIndexManager } />
0 commit comments