diff --git a/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx b/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx index f2a357b..f1b2d05 100644 --- a/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx +++ b/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx @@ -7,6 +7,8 @@ import {useForm} from "@mantine/form"; import {useEffect} from "react"; import {FormSchema} from "@/components/formUtil/formBuilder/types.ts"; import {IconDownload} from "@tabler/icons-react"; +import {useShowDebug} from "@/components/ShowDebug.tsx"; +import {onlyUnique} from "@/lib/util.ts"; const CHARSETS = [ "utf-8", "ISO-8859-1", "windows-1252", "utf-16be", "utf-16le", "us-ascii" @@ -36,6 +38,8 @@ export default function DownloadDataModal({opened, onClose, lists, event, query} } }) + const {showDebug} = useShowDebug() + // Fetch all pages useEffect(() => { if (opened && query.hasNextPage && !query.isFetchingNextPage) { @@ -72,8 +76,8 @@ export default function DownloadDataModal({opened, onClose, lists, event, query} const entries = query.data?.pages.flatMap(p => p.items) ?? [] const selectedFields = { - questionSchemaFields: formValues.values.questionSchemaFields, - statusSchemaFields: formValues.values.statusSchemaFields + questionSchemaFields: formValues.values.questionSchemaFields.filter(onlyUnique), + statusSchemaFields: formValues.values.statusSchemaFields.filter(onlyUnique) } // which question and status fields to include in the CSV @@ -81,13 +85,13 @@ export default function DownloadDataModal({opened, onClose, lists, event, query} fields: [ ...event.defaultEntryQuestionSchema?.fields.filter(f => selectedFields.questionSchemaFields.includes(f.id)) ?? [], ...lists.flatMap(l => l.entryQuestionSchema?.fields.filter(f => selectedFields.questionSchemaFields.includes(f.id)) ?? []) - ] + ].filter((v, i, arr) => arr.findIndex(t => (t.id === v.id)) === i) } const statusSchema = { fields: [ ...event.defaultEntryStatusSchema?.fields.filter(f => selectedFields.statusSchemaFields.includes(f.id)) ?? [], ...lists.flatMap(l => l.entryStatusSchema?.fields.filter(f => selectedFields.statusSchemaFields.includes(f.id)) ?? []) - ] + ].filter((v, i, arr) => arr.findIndex(t => (t.id === v.id)) === i) } /** @@ -105,7 +109,8 @@ export default function DownloadDataModal({opened, onClose, lists, event, query} // assemble the header (first question fields, then status fields) const header = [ - "Person", "Person ID", "Anmeldezeitpunkt", "Anmelde-ID", "Anmelde-Liste", + ...(showDebug ? ["Person ID", "Eintrags ID"] : []), + "Person", "Anmeldezeitpunkt", "Anmelde-Liste", ...questionSchema.fields.map(f => f.label).map(escapeSeparator), ...statusSchema.fields.map(f => f.label).map(escapeSeparator) ] @@ -115,7 +120,8 @@ export default function DownloadDataModal({opened, onClose, lists, event, query} const questionData = e.entryQuestionData || {} const statusData = e.entryStatusData || {} return [ - e.expand?.user.username ?? "N/A", e.user, e.created, e.id, e.listName, + ...(showDebug ? [e.user, e.id] : []), + e.expand?.user.username ?? "N/A", e.created, e.listName, ...questionSchema.fields.map(f => questionData[f.id]?.value?.toString() ?? "N/A").map(escapeSeparator), ...statusSchema.fields.map(f => statusData[f.id]?.value?.toString() ?? "N/A").map(escapeSeparator) ] @@ -149,8 +155,8 @@ export default function DownloadDataModal({opened, onClose, lists, event, query} >