Skip to content

Commit

Permalink
Fix bug where CSV exports were using only the first exported messages…
Browse files Browse the repository at this point in the history
… columns, instead of any future columns that could be present
  • Loading branch information
prathercc committed Jul 30, 2024
1 parent 8730852 commit 8044e34
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/features/export/export-slice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,21 @@ const _exportCsv = async ({
entityName,
currentPage,
}: ExportHtmlProps) => {
const csvData: unknown[] = messages.map((m) => flatten(m));
const csvKeys: string[] = [];
const csvData: Object[] = messages.map((m) => {
const flattenedMessage: Object = flatten(m);
Object.keys(flattenedMessage).forEach((mKey) => {
if (!csvKeys.some((csvKey) => csvKey === mKey)) {
csvKeys.push(mKey);
}
});
return flattenedMessage;
});

await exportUtils.addToZip(
Papa.unparse(csvData),
Papa.unparse(csvData, {
columns: ["id", ...csvKeys.filter((k) => k !== "id").sort()],
}),
`${entityMainDirectory}/${getSafeExportName(
entityName
)}_page_${currentPage}.csv`
Expand Down

0 comments on commit 8044e34

Please sign in to comment.