feat(csvexport): improved csv export
Build and Push Docker image / build-and-push (push) Successful in 6m31s Details

This commit is contained in:
Valentin Kolb 2024-06-16 15:42:53 +02:00
parent 63718ae4c0
commit 6a88c1b516
1 changed files with 14 additions and 8 deletions

View File

@ -7,6 +7,8 @@ import {useForm} from "@mantine/form";
import {useEffect} from "react"; import {useEffect} from "react";
import {FormSchema} from "@/components/formUtil/formBuilder/types.ts"; import {FormSchema} from "@/components/formUtil/formBuilder/types.ts";
import {IconDownload} from "@tabler/icons-react"; import {IconDownload} from "@tabler/icons-react";
import {useShowDebug} from "@/components/ShowDebug.tsx";
import {onlyUnique} from "@/lib/util.ts";
const CHARSETS = [ const CHARSETS = [
"utf-8", "ISO-8859-1", "windows-1252", "utf-16be", "utf-16le", "us-ascii" "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 // Fetch all pages
useEffect(() => { useEffect(() => {
if (opened && query.hasNextPage && !query.isFetchingNextPage) { 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 entries = query.data?.pages.flatMap(p => p.items) ?? []
const selectedFields = { const selectedFields = {
questionSchemaFields: formValues.values.questionSchemaFields, questionSchemaFields: formValues.values.questionSchemaFields.filter(onlyUnique),
statusSchemaFields: formValues.values.statusSchemaFields statusSchemaFields: formValues.values.statusSchemaFields.filter(onlyUnique)
} }
// which question and status fields to include in the CSV // which question and status fields to include in the CSV
@ -81,13 +85,13 @@ export default function DownloadDataModal({opened, onClose, lists, event, query}
fields: [ fields: [
...event.defaultEntryQuestionSchema?.fields.filter(f => selectedFields.questionSchemaFields.includes(f.id)) ?? [], ...event.defaultEntryQuestionSchema?.fields.filter(f => selectedFields.questionSchemaFields.includes(f.id)) ?? [],
...lists.flatMap(l => l.entryQuestionSchema?.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 = { const statusSchema = {
fields: [ fields: [
...event.defaultEntryStatusSchema?.fields.filter(f => selectedFields.statusSchemaFields.includes(f.id)) ?? [], ...event.defaultEntryStatusSchema?.fields.filter(f => selectedFields.statusSchemaFields.includes(f.id)) ?? [],
...lists.flatMap(l => l.entryStatusSchema?.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) // assemble the header (first question fields, then status fields)
const header = [ 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), ...questionSchema.fields.map(f => f.label).map(escapeSeparator),
...statusSchema.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 questionData = e.entryQuestionData || {}
const statusData = e.entryStatusData || {} const statusData = e.entryStatusData || {}
return [ 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), ...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) ...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}
> >
<div className={"stack"}> <div className={"stack"}>
<ShowHelp> <ShowHelp>
In der CSV sind automatisch die Felder <em>Person</em>, <em>Person In der CSV sind automatisch die Felder <em>Person</em>, <em>Anmeldezeitpunkt</em>,
ID</em>, <em>Anmeldezeitpunkt</em>, <em>Anmelde-ID</em> und <em>Anmelde-Liste</em> enthalten. Diese und <em>Anmelde-Liste</em> enthalten. Diese
Felder können nicht abgewählt werden. Felder können nicht abgewählt werden.
<br/> <br/>
Um Listen spezifische Daten herunterzuladen, wähle im vorherigen Schritt eine oder mehrere Listen aus. Um Listen spezifische Daten herunterzuladen, wähle im vorherigen Schritt eine oder mehrere Listen aus.