Skip to content

Commit c3627de

Browse files
committed
fix(dashboard): wrong encoding in csv files from Download Data
1 parent 715308d commit c3627de

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

dashboard/src/utils/download.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AsyncParser } from '@json2csv/whatwg';
2+
import { notifications } from '@mantine/notifications';
23
import { saveAs } from 'file-saver';
34
import JSZip from 'jszip';
45

@@ -23,12 +24,24 @@ export async function downloadDataAsCSV(id: string, data: TQueryData) {
2324

2425
export 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

3447
export function downloadJSON(name: string, json: string) {

0 commit comments

Comments
 (0)