@@ -27,6 +27,7 @@ import {
2727 type SchemaFormat ,
2828 type ExportStatus ,
2929 trackSchemaExportFailed ,
30+ downloadSchema ,
3031} from '../stores/schema-export-reducer' ;
3132
3233const loaderStyles = css ( {
@@ -87,21 +88,18 @@ const ExportSchemaModal: React.FunctionComponent<{
8788 onChangeSchemaExportFormat : ( format : SchemaFormat ) => Promise < void > ;
8889 onClose : ( ) => void ;
8990 onExportedSchemaCopied : ( ) => void ;
90- onExportedSchema : ( ) => void ;
91- onSchemaExportFailed : ( stage : string ) => void ;
91+ onSchemaDownload : ( ) => void ;
9292} > = ( {
9393 errorMessage,
9494 exportStatus,
9595 isOpen,
9696 exportFormat,
9797 exportedSchema,
98- filename,
9998 onCancelSchemaExport,
10099 onChangeSchemaExportFormat,
101100 onClose,
102101 onExportedSchemaCopied,
103- onExportedSchema,
104- onSchemaExportFailed,
102+ onSchemaDownload,
105103} ) => {
106104 const onFormatOptionSelected = useCallback (
107105 ( event : ChangeEvent < HTMLInputElement > ) => {
@@ -112,25 +110,6 @@ const ExportSchemaModal: React.FunctionComponent<{
112110 [ onChangeSchemaExportFormat ]
113111 ) ;
114112
115- const handleSchemaDownload = useCallback ( ( ) => {
116- try {
117- if ( ! exportedSchema ) return ;
118- const blob = new Blob ( [ exportedSchema ] , {
119- type : 'application/json' ,
120- } ) ;
121- const url = window . URL . createObjectURL ( blob ) ;
122- const link = document . createElement ( 'a' ) ;
123- link . href = url ;
124- link . download = filename || 'export.json' ;
125- link . click ( ) ;
126- window . URL . revokeObjectURL ( url ) ;
127- onExportedSchema ( ) ;
128- } catch ( error ) {
129- onSchemaExportFailed ( 'download button clicked' ) ;
130- throw error ;
131- }
132- } , [ exportedSchema , filename , onSchemaExportFailed , onExportedSchema ] ) ;
133-
134113 return (
135114 < Modal open = { isOpen } setOpen = { onClose } >
136115 < ModalHeader title = "Export Schema" />
@@ -209,7 +188,7 @@ const ExportSchemaModal: React.FunctionComponent<{
209188 isLoading = { exportStatus === 'inprogress' }
210189 loadingIndicator = { < SpinLoader /> }
211190 disabled = { ! exportedSchema }
212- onClick = { handleSchemaDownload }
191+ onClick = { onSchemaDownload }
213192 data-testid = "schema-export-download-button"
214193 >
215194 Export
@@ -235,5 +214,6 @@ export default connect(
235214 onCancelSchemaExport : cancelExportSchema ,
236215 onChangeSchemaExportFormat : changeExportSchemaFormat ,
237216 onClose : closeExportSchema ,
217+ onSchemaDownload : downloadSchema ,
238218 }
239219) ( ExportSchemaModal ) ;
0 commit comments