@@ -18,6 +18,7 @@ import EmptyState from 'components/EmptyState/EmptyState
18
18
import ExportDialog from 'dashboard/Data/Browser/ExportDialog.react' ;
19
19
import AttachRowsDialog from 'dashboard/Data/Browser/AttachRowsDialog.react' ;
20
20
import AttachSelectedRowsDialog from 'dashboard/Data/Browser/AttachSelectedRowsDialog.react' ;
21
+ import CloneSelectedRowsDialog from 'dashboard/Data/Browser/CloneSelectedRowsDialog.react' ;
21
22
import history from 'dashboard/history' ;
22
23
import { List , Map } from 'immutable' ;
23
24
import Notification from 'dashboard/Data/Browser/Notification.react' ;
@@ -86,6 +87,9 @@ class Browser extends DashboardView {
86
87
this . showAttachSelectedRowsDialog = this . showAttachSelectedRowsDialog . bind ( this ) ;
87
88
this . confirmAttachSelectedRows = this . confirmAttachSelectedRows . bind ( this ) ;
88
89
this . cancelAttachSelectedRows = this . cancelAttachSelectedRows . bind ( this ) ;
90
+ this . showCloneSelectedRowsDialog = this . showCloneSelectedRowsDialog . bind ( this ) ;
91
+ this . confirmCloneSelectedRows = this . confirmCloneSelectedRows . bind ( this ) ;
92
+ this . cancelCloneSelectedRows = this . cancelCloneSelectedRows . bind ( this ) ;
89
93
this . getClassRelationColumns = this . getClassRelationColumns . bind ( this ) ;
90
94
this . showCreateClass = this . showCreateClass . bind ( this ) ;
91
95
this . refresh = this . refresh . bind ( this ) ;
@@ -656,7 +660,8 @@ class Browser extends DashboardView {
656
660
this . state . showExportDialog ||
657
661
this . state . rowsToDelete ||
658
662
this . state . showAttachRowsDialog ||
659
- this . state . showAttachSelectedRowsDialog
663
+ this . state . showAttachSelectedRowsDialog ||
664
+ this . state . showCloneSelectedRowsDialog
660
665
) ;
661
666
}
662
667
@@ -732,6 +737,41 @@ class Browser extends DashboardView {
732
737
} ) ;
733
738
}
734
739
740
+ showCloneSelectedRowsDialog ( ) {
741
+ this . setState ( {
742
+ showCloneSelectedRowsDialog : true ,
743
+ } ) ;
744
+ }
745
+
746
+ cancelCloneSelectedRows ( ) {
747
+ this . setState ( {
748
+ showCloneSelectedRowsDialog : false ,
749
+ } ) ;
750
+ }
751
+
752
+ async confirmCloneSelectedRows ( ) {
753
+ const objectIds = [ ] ;
754
+ for ( const objectId in this . state . selection ) {
755
+ objectIds . push ( objectId ) ;
756
+ }
757
+ const query = new Parse . Query ( this . props . params . className ) ;
758
+ query . containedIn ( 'objectId' , objectIds ) ;
759
+ const objects = await query . find ( { useMasterKey : true } ) ;
760
+ const toClone = [ ] ;
761
+ for ( const object of objects ) {
762
+ toClone . push ( object . clone ( ) ) ;
763
+ }
764
+ await Parse . Object . saveAll ( toClone , { useMasterKey : true } ) ;
765
+ this . setState ( {
766
+ selection : { } ,
767
+ data : [
768
+ ...toClone ,
769
+ ...this . state . data ,
770
+ ] ,
771
+ showCloneSelectedRowsDialog : false ,
772
+ } ) ;
773
+ }
774
+
735
775
getClassRelationColumns ( className ) {
736
776
const currentClassName = this . props . params . className ;
737
777
return this . getClassColumns ( className , false )
@@ -883,6 +923,7 @@ class Browser extends DashboardView {
883
923
onRefresh = { this . refresh }
884
924
onAttachRows = { this . showAttachRowsDialog }
885
925
onAttachSelectedRows = { this . showAttachSelectedRowsDialog }
926
+ onCloneSelectedRows = { this . showCloneSelectedRowsDialog }
886
927
887
928
columns = { columns }
888
929
className = { className }
@@ -978,6 +1019,15 @@ class Browser extends DashboardView {
978
1019
onConfirm = { this . confirmAttachSelectedRows }
979
1020
/>
980
1021
) ;
1022
+ } else if ( this . state . showCloneSelectedRowsDialog ) {
1023
+ extras = (
1024
+ < CloneSelectedRowsDialog
1025
+ className = { className }
1026
+ selection = { this . state . selection }
1027
+ onCancel = { this . cancelCloneSelectedRows }
1028
+ onConfirm = { this . confirmCloneSelectedRows }
1029
+ />
1030
+ ) ;
981
1031
}
982
1032
983
1033
let notification = null ;
0 commit comments