File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 11import { AsyncParser } from '@json2csv/whatwg' ;
2+ import { notifications } from '@mantine/notifications' ;
23import { saveAs } from 'file-saver' ;
34import JSZip from 'jszip' ;
45
@@ -23,12 +24,24 @@ export async function downloadDataAsCSV(id: string, data: TQueryData) {
2324
2425export function downloadDataListAsZip ( idDataList : Array < { id : string ; data : TQueryData } > ) {
2526 const zip = new JSZip ( ) ;
26- idDataList . forEach ( ( { id, data } ) => {
27- zip . file ( `${ id } .csv` , makeCSV ( data ) ) ;
28- } ) ;
29- zip . generateAsync ( { type : 'blob' } ) . then ( ( content ) => {
30- saveAs ( content , 'dashboard_data.zip' ) ;
27+ const promises = idDataList . map ( async ( { id, data } ) => {
28+ const csv = await makeCSV ( data ) ;
29+ zip . file ( `${ id } .csv` , csv ) ;
3130 } ) ;
31+ Promise . all ( promises )
32+ . then ( ( ) => {
33+ zip . generateAsync ( { type : 'blob' } ) . then ( ( content ) => {
34+ saveAs ( content , 'dashboard_data.zip' ) ;
35+ } ) ;
36+ } )
37+ . catch ( ( err ) => {
38+ console . error ( err ) ;
39+ notifications . show ( {
40+ color : 'red' ,
41+ title : 'Failed to download data' ,
42+ message : err . message ,
43+ } ) ;
44+ } ) ;
3245}
3346
3447export function downloadJSON ( name : string , json : string ) {
You can’t perform that action at this time.
0 commit comments