@@ -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 ,
@@ -90,7 +92,7 @@ class Browser extends DashboardView {
90
92
requiredColumnFields : [ ] ,
91
93
92
94
useMasterKey : true ,
93
- currentUser : Parse . User . current ( )
95
+ currentUser : Parse . User . current ( ) ,
94
96
} ;
95
97
96
98
this . prefetchData = this . prefetchData . bind ( this ) ;
@@ -116,6 +118,7 @@ class Browser extends DashboardView {
116
118
this . confirmCloneSelectedRows = this . confirmCloneSelectedRows . bind ( this ) ;
117
119
this . cancelCloneSelectedRows = this . cancelCloneSelectedRows . bind ( this ) ;
118
120
this . showExportSelectedRowsDialog = this . showExportSelectedRowsDialog . bind ( this ) ;
121
+ this . showExportSchemaDialog = this . showExportSchemaDialog . bind ( this ) ;
119
122
this . confirmExportSelectedRows = this . confirmExportSelectedRows . bind ( this ) ;
120
123
this . cancelExportSelectedRows = this . cancelExportSelectedRows . bind ( this ) ;
121
124
this . getClassRelationColumns = this . getClassRelationColumns . bind ( this ) ;
@@ -328,6 +331,37 @@ class Browser extends DashboardView {
328
331
} ) ;
329
332
}
330
333
334
+ async exportSchema ( className , all ) {
335
+ try {
336
+ this . showNote ( 'Exporting schema...' ) ;
337
+ this . setState ( { showExportSchemaDialog : false } ) ;
338
+ let schema = [ ] ;
339
+ if ( all ) {
340
+ schema = await Parse . Schema . all ( ) ;
341
+ } else {
342
+ schema = await new Parse . Schema ( className ) . get ( ) ;
343
+ }
344
+ const element = document . createElement ( 'a' ) ;
345
+ const file = new Blob (
346
+ [
347
+ JSON . stringify (
348
+ schema ,
349
+ null ,
350
+ 2 ,
351
+ ) ,
352
+ ] ,
353
+ { type : 'application/json' }
354
+ ) ;
355
+ element . href = URL . createObjectURL ( file ) ;
356
+ element . download = `${ all ? 'schema' : className } .json` ;
357
+ document . body . appendChild ( element ) ; // Required for this to work in FireFox
358
+ element . click ( ) ;
359
+ document . body . removeChild ( element ) ;
360
+ } catch ( msg ) {
361
+ this . showNote ( msg , true ) ;
362
+ }
363
+ }
364
+
331
365
newColumn ( payload , required ) {
332
366
return this . props . schema . dispatch ( ActionTypes . ADD_COLUMN , payload )
333
367
. then ( ( ) => {
@@ -1091,6 +1125,7 @@ class Browser extends DashboardView {
1091
1125
this . state . showRemoveColumnDialog ||
1092
1126
this . state . showDropClassDialog ||
1093
1127
this . state . showExportDialog ||
1128
+ this . state . showExportSchema ||
1094
1129
this . state . rowsToDelete ||
1095
1130
this . state . showAttachRowsDialog ||
1096
1131
this . state . showAttachSelectedRowsDialog ||
@@ -1251,6 +1286,12 @@ class Browser extends DashboardView {
1251
1286
} ) ;
1252
1287
}
1253
1288
1289
+ showExportSchemaDialog ( ) {
1290
+ this . setState ( {
1291
+ showExportSchemaDialog : true
1292
+ } )
1293
+ }
1294
+
1254
1295
cancelExportSelectedRows ( ) {
1255
1296
this . setState ( {
1256
1297
rowsToExport : null
@@ -1605,6 +1646,7 @@ class Browser extends DashboardView {
1605
1646
onEditSelectedRow = { this . showEditRowDialog }
1606
1647
onEditPermissions = { this . onDialogToggle }
1607
1648
onExportSelectedRows = { this . showExportSelectedRowsDialog }
1649
+ onExportSchema = { this . showExportSchemaDialog }
1608
1650
1609
1651
onSaveNewRow = { this . saveNewRow }
1610
1652
onShowPointerKey = { this . showPointerKeyDialog }
@@ -1719,6 +1761,14 @@ class Browser extends DashboardView {
1719
1761
onCancel = { ( ) => this . setState ( { showExportDialog : false } ) }
1720
1762
onConfirm = { ( ) => this . exportClass ( className ) } />
1721
1763
) ;
1764
+ } else if ( this . state . showExportSchemaDialog ) {
1765
+ extras = (
1766
+ < ExportSchemaDialog
1767
+ className = { className }
1768
+ schema = { this . props . schema . data . get ( 'classes' ) }
1769
+ onCancel = { ( ) => this . setState ( { showExportSchemaDialog : false } ) }
1770
+ onConfirm = { ( ...args ) => this . exportSchema ( ...args ) } />
1771
+ ) ;
1722
1772
} else if ( this . state . showAttachRowsDialog ) {
1723
1773
extras = (
1724
1774
< AttachRowsDialog
0 commit comments