@@ -18,6 +18,7 @@ import EmptyState from 'components/EmptyState/EmptyState.react';
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 ExecuteScriptRowsDialog from 'dashboard/Data/Browser/ExecuteScriptRowsDialog.react' ;
2122import CloneSelectedRowsDialog from 'dashboard/Data/Browser/CloneSelectedRowsDialog.react' ;
2223import EditRowDialog from 'dashboard/Data/Browser/EditRowDialog.react' ;
2324import ExportSelectedRowsDialog from 'dashboard/Data/Browser/ExportSelectedRowsDialog.react' ;
@@ -95,6 +96,8 @@ class Browser extends DashboardView {
9596
9697 useMasterKey : true ,
9798 currentUser : Parse . User . current ( ) ,
99+
100+ processedScripts : 0 ,
98101 } ;
99102
100103 this . prefetchData = this . prefetchData . bind ( this ) ;
@@ -114,6 +117,9 @@ class Browser extends DashboardView {
114117 this . cancelAttachRows = this . cancelAttachRows . bind ( this ) ;
115118 this . confirmAttachRows = this . confirmAttachRows . bind ( this ) ;
116119 this . showAttachSelectedRowsDialog = this . showAttachSelectedRowsDialog . bind ( this ) ;
120+ this . showExecuteScriptRowsDialog = this . showExecuteScriptRowsDialog . bind ( this ) ;
121+ this . confirmExecuteScriptRows = this . confirmExecuteScriptRows . bind ( this ) ;
122+ this . cancelExecuteScriptRowsDialog = this . cancelExecuteScriptRowsDialog . bind ( this ) ;
117123 this . confirmAttachSelectedRows = this . confirmAttachSelectedRows . bind ( this ) ;
118124 this . cancelAttachSelectedRows = this . cancelAttachSelectedRows . bind ( this ) ;
119125 this . showCloneSelectedRowsDialog = this . showCloneSelectedRowsDialog . bind ( this ) ;
@@ -1326,6 +1332,18 @@ class Browser extends DashboardView {
13261332 } ) ;
13271333 }
13281334
1335+ showExecuteScriptRowsDialog ( ) {
1336+ this . setState ( {
1337+ showExecuteScriptRowsDialog : true ,
1338+ } ) ;
1339+ }
1340+
1341+ cancelExecuteScriptRowsDialog ( ) {
1342+ this . setState ( {
1343+ showExecuteScriptRowsDialog : false ,
1344+ } ) ;
1345+ }
1346+
13291347 async confirmAttachSelectedRows (
13301348 className ,
13311349 targetObjectId ,
@@ -1346,6 +1364,37 @@ class Browser extends DashboardView {
13461364 } ) ;
13471365 }
13481366
1367+ async confirmExecuteScriptRows ( script ) {
1368+ try {
1369+ const objects = [ ] ;
1370+ Object . keys ( this . state . selection ) . forEach ( key =>
1371+ objects . push ( Parse . Object . extend ( this . props . params . className ) . createWithoutData ( key ) )
1372+ ) ;
1373+ for ( const object of objects ) {
1374+ const response = await Parse . Cloud . run (
1375+ script . cloudCodeFunction ,
1376+ { object : object . toPointer ( ) } ,
1377+ { useMasterKey : true }
1378+ ) ;
1379+ this . setState ( prevState => ( {
1380+ processedScripts : prevState . processedScripts + 1 ,
1381+ } ) ) ;
1382+ this . showNote (
1383+ response ||
1384+ `Ran script "${ script . title } " on "${ this . props . className } " object "${ object . id } ".`
1385+ ) ;
1386+ }
1387+ this . refresh ( ) ;
1388+ } catch ( e ) {
1389+ this . showNote ( e . message , true ) ;
1390+ console . log ( `Could not run ${ script . title } : ${ e } ` ) ;
1391+ } finally {
1392+ this . setState ( ( {
1393+ processedScripts : 0 ,
1394+ } ) ) ;
1395+ }
1396+ }
1397+
13491398 showCloneSelectedRowsDialog ( ) {
13501399 this . setState ( {
13511400 showCloneSelectedRowsDialog : true ,
@@ -1790,6 +1839,7 @@ class Browser extends DashboardView {
17901839 onRefresh = { this . refresh }
17911840 onAttachRows = { this . showAttachRowsDialog }
17921841 onAttachSelectedRows = { this . showAttachSelectedRowsDialog }
1842+ onExecuteScriptRows = { this . showExecuteScriptRowsDialog }
17931843 onCloneSelectedRows = { this . showCloneSelectedRowsDialog }
17941844 onEditSelectedRow = { this . showEditRowDialog }
17951845 onEditPermissions = { this . onDialogToggle }
@@ -1943,6 +1993,16 @@ class Browser extends DashboardView {
19431993 onConfirm = { this . confirmAttachSelectedRows }
19441994 />
19451995 ) ;
1996+ } else if ( this . state . showExecuteScriptRowsDialog ) {
1997+ extras = (
1998+ < ExecuteScriptRowsDialog
1999+ currentClass = { this . props . params . className }
2000+ selection = { this . state . selection }
2001+ onCancel = { this . cancelExecuteScriptRowsDialog }
2002+ onConfirm = { this . confirmExecuteScriptRows }
2003+ processedScripts = { this . state . processedScripts }
2004+ />
2005+ ) ;
19462006 } else if ( this . state . showCloneSelectedRowsDialog ) {
19472007 extras = (
19482008 < CloneSelectedRowsDialog
0 commit comments