From 29818a3ced009fe991af2a7b612f438249838b83 Mon Sep 17 00:00:00 2001 From: NEOLPAR Date: Mon, 18 Jul 2022 09:57:15 +0100 Subject: [PATCH] downloading csv users created through batch --- packages/builder/src/helpers/data/utils.js | 19 ++++++++++++++ .../users/_components/PasswordModal.svelte | 26 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/helpers/data/utils.js b/packages/builder/src/helpers/data/utils.js index 23aeb314a0..647c2be33e 100644 --- a/packages/builder/src/helpers/data/utils.js +++ b/packages/builder/src/helpers/data/utils.js @@ -150,12 +150,31 @@ export function flipHeaderState(headersActivity) { return enabled } +export const parseToCsv = (headers, rows) => { + let csv = headers?.map(key => `"${key}"`)?.join(",") || "" + + for (let row of rows) { + csv = `${csv}\n${headers + .map(header => { + let val = row[header] + val = + typeof val === "object" && !(val instanceof Date) + ? `"${JSON.stringify(val).replace(/"/g, "'")}"` + : `"${val}"` + return val.trim() + }) + .join(",")}` + } + return csv +} + export default { breakQueryString, buildQueryString, fieldsToSchema, flipHeaderState, keyValueToQueryParameters, + parseToCsv, queryParametersToKeyValue, schemaToFields, } diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte index 26318d3dcf..e2995d8a02 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte @@ -1,6 +1,7 @@ -
+