@@ -18,6 +18,7 @@ import EmptyState from 'components/EmptyState/EmptyState
1818import ExportDialog from 'dashboard/Data/Browser/ExportDialog.react' ;
1919import AttachRowsDialog from 'dashboard/Data/Browser/AttachRowsDialog.react' ;
2020import AttachSelectedRowsDialog from 'dashboard/Data/Browser/AttachSelectedRowsDialog.react' ;
21+ import CloneSelectedRowsDialog from 'dashboard/Data/Browser/CloneSelectedRowsDialog.react' ;
2122import history from 'dashboard/history' ;
2223import { List , Map } from 'immutable' ;
2324import Notification from 'dashboard/Data/Browser/Notification.react' ;
@@ -86,6 +87,9 @@ class Browser extends DashboardView {
8687 this . showAttachSelectedRowsDialog = this . showAttachSelectedRowsDialog . bind ( this ) ;
8788 this . confirmAttachSelectedRows = this . confirmAttachSelectedRows . bind ( this ) ;
8889 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 ) ;
8993 this . getClassRelationColumns = this . getClassRelationColumns . bind ( this ) ;
9094 this . showCreateClass = this . showCreateClass . bind ( this ) ;
9195 this . refresh = this . refresh . bind ( this ) ;
@@ -656,7 +660,8 @@ class Browser extends DashboardView {
656660 this . state . showExportDialog ||
657661 this . state . rowsToDelete ||
658662 this . state . showAttachRowsDialog ||
659- this . state . showAttachSelectedRowsDialog
663+ this . state . showAttachSelectedRowsDialog ||
664+ this . state . showCloneSelectedRowsDialog
660665 ) ;
661666 }
662667
@@ -732,6 +737,41 @@ class Browser extends DashboardView {
732737 } ) ;
733738 }
734739
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+
735775 getClassRelationColumns ( className ) {
736776 const currentClassName = this . props . params . className ;
737777 return this . getClassColumns ( className , false )
@@ -883,6 +923,7 @@ class Browser extends DashboardView {
883923 onRefresh = { this . refresh }
884924 onAttachRows = { this . showAttachRowsDialog }
885925 onAttachSelectedRows = { this . showAttachSelectedRowsDialog }
926+ onCloneSelectedRows = { this . showCloneSelectedRowsDialog }
886927
887928 columns = { columns }
888929 className = { className }
@@ -978,6 +1019,15 @@ class Browser extends DashboardView {
9781019 onConfirm = { this . confirmAttachSelectedRows }
9791020 />
9801021 ) ;
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+ ) ;
9811031 }
9821032
9831033 let notification = null ;
0 commit comments