@@ -18,6 +18,7 @@ import EmptyState from 'components/EmptyState/EmptyState.react';
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 ExecuteScriptRowsDialog from 'dashboard/Data/Browser/ExecuteScriptRowsDialog.react' ;
21
22
import CloneSelectedRowsDialog from 'dashboard/Data/Browser/CloneSelectedRowsDialog.react' ;
22
23
import EditRowDialog from 'dashboard/Data/Browser/EditRowDialog.react' ;
23
24
import ExportSelectedRowsDialog from 'dashboard/Data/Browser/ExportSelectedRowsDialog.react' ;
@@ -95,6 +96,8 @@ class Browser extends DashboardView {
95
96
96
97
useMasterKey : true ,
97
98
currentUser : Parse . User . current ( ) ,
99
+
100
+ processedScripts : 0 ,
98
101
} ;
99
102
100
103
this . prefetchData = this . prefetchData . bind ( this ) ;
@@ -114,6 +117,9 @@ class Browser extends DashboardView {
114
117
this . cancelAttachRows = this . cancelAttachRows . bind ( this ) ;
115
118
this . confirmAttachRows = this . confirmAttachRows . bind ( this ) ;
116
119
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 ) ;
117
123
this . confirmAttachSelectedRows = this . confirmAttachSelectedRows . bind ( this ) ;
118
124
this . cancelAttachSelectedRows = this . cancelAttachSelectedRows . bind ( this ) ;
119
125
this . showCloneSelectedRowsDialog = this . showCloneSelectedRowsDialog . bind ( this ) ;
@@ -1326,6 +1332,18 @@ class Browser extends DashboardView {
1326
1332
} ) ;
1327
1333
}
1328
1334
1335
+ showExecuteScriptRowsDialog ( ) {
1336
+ this . setState ( {
1337
+ showExecuteScriptRowsDialog : true ,
1338
+ } ) ;
1339
+ }
1340
+
1341
+ cancelExecuteScriptRowsDialog ( ) {
1342
+ this . setState ( {
1343
+ showExecuteScriptRowsDialog : false ,
1344
+ } ) ;
1345
+ }
1346
+
1329
1347
async confirmAttachSelectedRows (
1330
1348
className ,
1331
1349
targetObjectId ,
@@ -1346,6 +1364,37 @@ class Browser extends DashboardView {
1346
1364
} ) ;
1347
1365
}
1348
1366
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
+
1349
1398
showCloneSelectedRowsDialog ( ) {
1350
1399
this . setState ( {
1351
1400
showCloneSelectedRowsDialog : true ,
@@ -1790,6 +1839,7 @@ class Browser extends DashboardView {
1790
1839
onRefresh = { this . refresh }
1791
1840
onAttachRows = { this . showAttachRowsDialog }
1792
1841
onAttachSelectedRows = { this . showAttachSelectedRowsDialog }
1842
+ onExecuteScriptRows = { this . showExecuteScriptRowsDialog }
1793
1843
onCloneSelectedRows = { this . showCloneSelectedRowsDialog }
1794
1844
onEditSelectedRow = { this . showEditRowDialog }
1795
1845
onEditPermissions = { this . onDialogToggle }
@@ -1943,6 +1993,16 @@ class Browser extends DashboardView {
1943
1993
onConfirm = { this . confirmAttachSelectedRows }
1944
1994
/>
1945
1995
) ;
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
+ ) ;
1946
2006
} else if ( this . state . showCloneSelectedRowsDialog ) {
1947
2007
extras = (
1948
2008
< CloneSelectedRowsDialog
0 commit comments