@@ -21,6 +21,7 @@ import AttachSelectedRowsDialog from 'dashboard/Data/Browser/AttachSel
2121import CloneSelectedRowsDialog from 'dashboard/Data/Browser/CloneSelectedRowsDialog.react' ;
2222import EditRowDialog from 'dashboard/Data/Browser/EditRowDialog.react' ;
2323import ExportSelectedRowsDialog from 'dashboard/Data/Browser/ExportSelectedRowsDialog.react' ;
24+ import ExportSchemaDialog from 'dashboard/Data/Browser/ExportSchemaDialog.react' ;
2425import { List , Map } from 'immutable' ;
2526import Notification from 'dashboard/Data/Browser/Notification.react' ;
2627import Parse from 'parse' ;
@@ -56,6 +57,7 @@ class Browser extends DashboardView {
5657 showRemoveColumnDialog : false ,
5758 showDropClassDialog : false ,
5859 showExportDialog : false ,
60+ showExportSchemaDialog : false ,
5961 showAttachRowsDialog : false ,
6062 showEditRowDialog : false ,
6163 showPointerKeyDialog : false ,
@@ -90,7 +92,7 @@ class Browser extends DashboardView {
9092 requiredColumnFields : [ ] ,
9193
9294 useMasterKey : true ,
93- currentUser : Parse . User . current ( )
95+ currentUser : Parse . User . current ( ) ,
9496 } ;
9597
9698 this . prefetchData = this . prefetchData . bind ( this ) ;
@@ -116,6 +118,7 @@ class Browser extends DashboardView {
116118 this . confirmCloneSelectedRows = this . confirmCloneSelectedRows . bind ( this ) ;
117119 this . cancelCloneSelectedRows = this . cancelCloneSelectedRows . bind ( this ) ;
118120 this . showExportSelectedRowsDialog = this . showExportSelectedRowsDialog . bind ( this ) ;
121+ this . showExportSchemaDialog = this . showExportSchemaDialog . bind ( this ) ;
119122 this . confirmExportSelectedRows = this . confirmExportSelectedRows . bind ( this ) ;
120123 this . cancelExportSelectedRows = this . cancelExportSelectedRows . bind ( this ) ;
121124 this . getClassRelationColumns = this . getClassRelationColumns . bind ( this ) ;
@@ -328,6 +331,37 @@ class Browser extends DashboardView {
328331 } ) ;
329332 }
330333
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+
331365 newColumn ( payload , required ) {
332366 return this . props . schema . dispatch ( ActionTypes . ADD_COLUMN , payload )
333367 . then ( ( ) => {
@@ -1091,6 +1125,7 @@ class Browser extends DashboardView {
10911125 this . state . showRemoveColumnDialog ||
10921126 this . state . showDropClassDialog ||
10931127 this . state . showExportDialog ||
1128+ this . state . showExportSchema ||
10941129 this . state . rowsToDelete ||
10951130 this . state . showAttachRowsDialog ||
10961131 this . state . showAttachSelectedRowsDialog ||
@@ -1251,6 +1286,12 @@ class Browser extends DashboardView {
12511286 } ) ;
12521287 }
12531288
1289+ showExportSchemaDialog ( ) {
1290+ this . setState ( {
1291+ showExportSchemaDialog : true
1292+ } )
1293+ }
1294+
12541295 cancelExportSelectedRows ( ) {
12551296 this . setState ( {
12561297 rowsToExport : null
@@ -1605,6 +1646,7 @@ class Browser extends DashboardView {
16051646 onEditSelectedRow = { this . showEditRowDialog }
16061647 onEditPermissions = { this . onDialogToggle }
16071648 onExportSelectedRows = { this . showExportSelectedRowsDialog }
1649+ onExportSchema = { this . showExportSchemaDialog }
16081650
16091651 onSaveNewRow = { this . saveNewRow }
16101652 onShowPointerKey = { this . showPointerKeyDialog }
@@ -1719,6 +1761,14 @@ class Browser extends DashboardView {
17191761 onCancel = { ( ) => this . setState ( { showExportDialog : false } ) }
17201762 onConfirm = { ( ) => this . exportClass ( className ) } />
17211763 ) ;
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+ ) ;
17221772 } else if ( this . state . showAttachRowsDialog ) {
17231773 extras = (
17241774 < AttachRowsDialog
0 commit comments