// @flow import * as ICONS from 'constants/icons'; import React from 'react'; import Button from 'component/button'; import Spinner from 'component/spinner'; type Props = { data: any, label: string, tooltip?: string, defaultFileName?: string, filters?: Array, onFetch?: () => void, progressMsg?: string, disabled?: boolean, }; class FileExporter extends React.PureComponent { constructor() { super(); (this: any).handleDownload = this.handleDownload.bind(this); } handleDownload() { const { data, defaultFileName } = this.props; const element = document.createElement('a'); const file = new Blob([data], { type: 'text/plain' }); element.href = URL.createObjectURL(file); element.download = defaultFileName || 'file.txt'; // $FlowFixMe document.body.appendChild(element); element.click(); // $FlowFixMe document.body.removeChild(element); } render() { const { data, label, tooltip, disabled, onFetch, progressMsg } = this.props; if (onFetch) { return ( <> {!progressMsg && (
)} {progressMsg && ( <> {__(progressMsg)} )} ); } else { return (