@@ -21,6 +21,7 @@ import AttachSelectedRowsDialog from 'dashboard/Data/Browser/AttachSel
21
21
import CloneSelectedRowsDialog from 'dashboard/Data/Browser/CloneSelectedRowsDialog.react' ;
22
22
import EditRowDialog from 'dashboard/Data/Browser/EditRowDialog.react' ;
23
23
import ExportSelectedRowsDialog from 'dashboard/Data/Browser/ExportSelectedRowsDialog.react' ;
24
+ import ExportSchemaDialog from 'dashboard/Data/Browser/ExportSchemaDialog.react' ;
24
25
import { List , Map } from 'immutable' ;
25
26
import Notification from 'dashboard/Data/Browser/Notification.react' ;
26
27
import Parse from 'parse' ;
@@ -56,6 +57,7 @@ class Browser extends DashboardView {
56
57
showRemoveColumnDialog : false ,
57
58
showDropClassDialog : false ,
58
59
showExportDialog : false ,
60
+ showExportSchemaDialog : false ,
59
61
showAttachRowsDialog : false ,
60
62
showEditRowDialog : false ,
61
63
showPointerKeyDialog : false ,
@@ -88,7 +90,7 @@ class Browser extends DashboardView {
88
90
requiredColumnFields : [ ] ,
89
91
90
92
useMasterKey : true ,
91
- currentUser : Parse . User . current ( )
93
+ currentUser : Parse . User . current ( ) ,
92
94
} ;
93
95
94
96
this . prefetchData = this . prefetchData . bind ( this ) ;
@@ -114,6 +116,7 @@ class Browser extends DashboardView {
114
116
this . confirmCloneSelectedRows = this . confirmCloneSelectedRows . bind ( this ) ;
115
117
this . cancelCloneSelectedRows = this . cancelCloneSelectedRows . bind ( this ) ;
116
118
this . showExportSelectedRowsDialog = this . showExportSelectedRowsDialog . bind ( this ) ;
119
+ this . showExportSchemaDialog = this . showExportSchemaDialog . bind ( this ) ;
117
120
this . confirmExportSelectedRows = this . confirmExportSelectedRows . bind ( this ) ;
118
121
this . cancelExportSelectedRows = this . cancelExportSelectedRows . bind ( this ) ;
119
122
this . getClassRelationColumns = this . getClassRelationColumns . bind ( this ) ;
@@ -326,6 +329,37 @@ class Browser extends DashboardView {
326
329
} ) ;
327
330
}
328
331
332
+ async exportSchema ( className , all ) {
333
+ try {
334
+ this . showNote ( 'Exporting schema...' ) ;
335
+ this . setState ( { showExportSchemaDialog : false } ) ;
336
+ let schema = [ ] ;
337
+ if ( all ) {
338
+ schema = await Parse . Schema . all ( ) ;
339
+ } else {
340
+ schema = await new Parse . Schema ( className ) . get ( ) ;
341
+ }
342
+ const element = document . createElement ( 'a' ) ;
343
+ const file = new Blob (
344
+ [
345
+ JSON . stringify (
346
+ schema ,
347
+ null ,
348
+ 2 ,
349
+ ) ,
350
+ ] ,
351
+ { type : 'application/json' }
352
+ ) ;
353
+ element . href = URL . createObjectURL ( file ) ;
354
+ element . download = `${ all ? 'schema' : className } .json` ;
355
+ document . body . appendChild ( element ) ; // Required for this to work in FireFox
356
+ element . click ( ) ;
357
+ document . body . removeChild ( element ) ;
358
+ } catch ( msg ) {
359
+ this . showNote ( msg , true ) ;
360
+ }
361
+ }
362
+
329
363
newColumn ( payload , required ) {
330
364
return this . props . schema . dispatch ( ActionTypes . ADD_COLUMN , payload )
331
365
. then ( ( ) => {
@@ -1089,6 +1123,7 @@ class Browser extends DashboardView {
1089
1123
this . state . showRemoveColumnDialog ||
1090
1124
this . state . showDropClassDialog ||
1091
1125
this . state . showExportDialog ||
1126
+ this . state . showExportSchema ||
1092
1127
this . state . rowsToDelete ||
1093
1128
this . state . showAttachRowsDialog ||
1094
1129
this . state . showAttachSelectedRowsDialog ||
@@ -1249,6 +1284,12 @@ class Browser extends DashboardView {
1249
1284
} ) ;
1250
1285
}
1251
1286
1287
+ showExportSchemaDialog ( ) {
1288
+ this . setState ( {
1289
+ showExportSchemaDialog : true
1290
+ } )
1291
+ }
1292
+
1252
1293
cancelExportSelectedRows ( ) {
1253
1294
this . setState ( {
1254
1295
rowsToExport : null
@@ -1545,6 +1586,7 @@ class Browser extends DashboardView {
1545
1586
onEditSelectedRow = { this . showEditRowDialog }
1546
1587
onEditPermissions = { this . onDialogToggle }
1547
1588
onExportSelectedRows = { this . showExportSelectedRowsDialog }
1589
+ onExportSchema = { this . showExportSchemaDialog }
1548
1590
1549
1591
onSaveNewRow = { this . saveNewRow }
1550
1592
onShowPointerKey = { this . showPointerKeyDialog }
@@ -1659,6 +1701,14 @@ class Browser extends DashboardView {
1659
1701
onCancel = { ( ) => this . setState ( { showExportDialog : false } ) }
1660
1702
onConfirm = { ( ) => this . exportClass ( className ) } />
1661
1703
) ;
1704
+ } else if ( this . state . showExportSchemaDialog ) {
1705
+ extras = (
1706
+ < ExportSchemaDialog
1707
+ className = { className }
1708
+ schema = { this . props . schema . data . get ( 'classes' ) }
1709
+ onCancel = { ( ) => this . setState ( { showExportSchemaDialog : false } ) }
1710
+ onConfirm = { ( ...args ) => this . exportSchema ( ...args ) } />
1711
+ ) ;
1662
1712
} else if ( this . state . showAttachRowsDialog ) {
1663
1713
extras = (
1664
1714
< AttachRowsDialog
0 commit comments