Skip to content

Commit 8441add

Browse files
committed
filename
1 parent 1a1018f commit 8441add

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

packages/compass-schema/src/components/export-schema-modal.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const ExportSchemaModal: React.FunctionComponent<{
8383
exportFormat: SchemaFormat;
8484
exportedSchema?: string;
8585
blobToDownload?: Blob;
86+
filename?: string;
8687
onCancelSchemaExport: () => void;
8788
onChangeSchemaExportFormat: (format: SchemaFormat) => Promise<void>;
8889
onClose: () => void;
@@ -95,6 +96,7 @@ const ExportSchemaModal: React.FunctionComponent<{
9596
exportFormat,
9697
exportedSchema,
9798
blobToDownload,
99+
filename,
98100
onCancelSchemaExport,
99101
onChangeSchemaExportFormat,
100102
onClose,
@@ -188,11 +190,7 @@ const ExportSchemaModal: React.FunctionComponent<{
188190
<Button onClick={onClose} variant="default">
189191
Cancel
190192
</Button>
191-
<Link
192-
download="export.json" // TODO
193-
href={downloadUrl}
194-
onClick={onExportedSchema}
195-
>
193+
<Link download={filename} href={downloadUrl} onClick={onExportedSchema}>
196194
<Button
197195
variant="primary"
198196
isLoading={!downloadUrl}
@@ -214,6 +212,7 @@ export default connect(
214212
isOpen: state.schemaExport.isOpen,
215213
exportedSchema: state.schemaExport.exportedSchema,
216214
blobToDownload: state.schemaExport.blobToDownload,
215+
filename: state.schemaExport.filename,
217216
}),
218217
{
219218
onExportedSchemaCopied: trackSchemaExported,

packages/compass-schema/src/stores/schema-export-reducer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type SchemaExportState = {
2828
errorMessage?: string;
2929
exportStatus: ExportStatus;
3030
blobToDownload?: Blob;
31+
filename?: string;
3132
};
3233

3334
const defaultSchemaFormat: SchemaFormat = 'standardJSON';
@@ -110,6 +111,7 @@ export type ChangeExportSchemaFormatCompletedAction = {
110111
export type schemaDownloadReadyAction = {
111112
type: SchemaExportActions.schemaDownloadReady;
112113
blob: Blob;
114+
filename: string;
113115
};
114116

115117
export const cancelExportSchema = (): SchemaThunkAction<
@@ -209,7 +211,7 @@ export const trackSchemaExported = (): SchemaThunkAction<void> => {
209211
};
210212

211213
const prepareDownload = (): SchemaThunkAction<void> => {
212-
return (dispatch, getState, { track, connectionInfoRef }) => {
214+
return (dispatch, getState, { track, connectionInfoRef, namespace }) => {
213215
let stage = 'initial';
214216
const { exportedSchema, exportFormat } = getState().schemaExport;
215217

@@ -223,7 +225,12 @@ const prepareDownload = (): SchemaThunkAction<void> => {
223225
const blob = new Blob([exportedSchema || ''], {
224226
type: 'application/json',
225227
});
226-
dispatch({ type: SchemaExportActions.schemaDownloadReady, blob });
228+
const filename = `schema-${exportFormat}-${namespace}.json`;
229+
dispatch({
230+
type: SchemaExportActions.schemaDownloadReady,
231+
blob,
232+
filename,
233+
});
227234
} catch (error) {
228235
track(
229236
'Schema Export Download Failed',
@@ -452,6 +459,7 @@ export const schemaExportReducer: Reducer<SchemaExportState, Action> = (
452459
return {
453460
...state,
454461
blobToDownload: action.blob,
462+
filename: action.filename,
455463
};
456464
}
457465

0 commit comments

Comments
 (0)