From 993ee4296b3942cc2fcbe378d1b2389cf670ac02 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 3 Dec 2024 12:58:35 +0100 Subject: [PATCH 1/7] Trying to fix exporting to csv --- .../src/components/failedmessages/FailedMessages.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Frontend/src/components/failedmessages/FailedMessages.vue b/src/Frontend/src/components/failedmessages/FailedMessages.vue index 848f8dd1c..931ff81c9 100644 --- a/src/Frontend/src/components/failedmessages/FailedMessages.vue +++ b/src/Frontend/src/components/failedmessages/FailedMessages.vue @@ -137,7 +137,11 @@ function exportSelected() { const keys = Object.keys(array[0]); let result = keys.join("\t") + "\n"; array.forEach((obj) => { - result += keys.map((k) => obj[k]).join(",") + "\n"; + result += keys.map((k) => obj[k] + .map(String) + .map(v => v.replaceAll('"', '""')) + .map(v => `"${v}"`) + ).join(",") + "\n"; }); return result; From 691414f83d929acb1758a33306031e6042c24ad0 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 3 Dec 2024 13:08:29 +0100 Subject: [PATCH 2/7] =?UTF-8?q?Typescript=20+=20formatting=20=F0=9F=A5=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/failedmessages/FailedMessages.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Frontend/src/components/failedmessages/FailedMessages.vue b/src/Frontend/src/components/failedmessages/FailedMessages.vue index 931ff81c9..c8d98199d 100644 --- a/src/Frontend/src/components/failedmessages/FailedMessages.vue +++ b/src/Frontend/src/components/failedmessages/FailedMessages.vue @@ -137,11 +137,15 @@ function exportSelected() { const keys = Object.keys(array[0]); let result = keys.join("\t") + "\n"; array.forEach((obj) => { - result += keys.map((k) => obj[k] - .map(String) - .map(v => v.replaceAll('"', '""')) - .map(v => `"${v}"`) - ).join(",") + "\n"; + result += + keys + .map((k) => + obj[k] + .map(String) + .map((v: string) => v.replaceAll('"', '""')) + .map((v: string) => `"${v}"`) + ) + .join(",") + "\n"; }); return result; From 65e725f7bb15639b1136f284314fb8876fd643c4 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 3 Dec 2024 13:38:38 +0100 Subject: [PATCH 3/7] Resolve map is not a function as that can only be applied to arrays --- .../src/components/failedmessages/FailedMessages.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Frontend/src/components/failedmessages/FailedMessages.vue b/src/Frontend/src/components/failedmessages/FailedMessages.vue index c8d98199d..36949ae01 100644 --- a/src/Frontend/src/components/failedmessages/FailedMessages.vue +++ b/src/Frontend/src/components/failedmessages/FailedMessages.vue @@ -139,12 +139,12 @@ function exportSelected() { array.forEach((obj) => { result += keys - .map((k) => - obj[k] - .map(String) - .map((v: string) => v.replaceAll('"', '""')) - .map((v: string) => `"${v}"`) - ) + .map((k) => { + let v = String(obj[k]); + v = v.replaceAll('"', '""'); // Escape all double quotes + v = `"${v}"`; // Quote all values to deal with CR characters + return v; + }) .join(",") + "\n"; }); From bce30ef5ec3341f3fb184d9605df2a9c321c6ab1 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 3 Dec 2024 13:40:51 +0100 Subject: [PATCH 4/7] Using a constant for the delimiter character --- .../src/components/failedmessages/FailedMessages.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Frontend/src/components/failedmessages/FailedMessages.vue b/src/Frontend/src/components/failedmessages/FailedMessages.vue index 36949ae01..1e0ea7ecb 100644 --- a/src/Frontend/src/components/failedmessages/FailedMessages.vue +++ b/src/Frontend/src/components/failedmessages/FailedMessages.vue @@ -134,8 +134,9 @@ async function retrySelected() { function exportSelected() { // eslint-disable-next-line @typescript-eslint/no-explicit-any function toCSV(array: any[]) { + const delimiter = ','; const keys = Object.keys(array[0]); - let result = keys.join("\t") + "\n"; + let result = keys.join(delimiter) + "\n"; array.forEach((obj) => { result += keys @@ -145,7 +146,7 @@ function exportSelected() { v = `"${v}"`; // Quote all values to deal with CR characters return v; }) - .join(",") + "\n"; + .join(delimiter) + "\n"; }); return result; From d6983b6d761bff27e33ffa3d5f31518539038ab8 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 3 Dec 2024 13:41:02 +0100 Subject: [PATCH 5/7] Remove TODO, as we fixed it :-) --- src/Frontend/src/components/failedmessages/FailedMessages.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Frontend/src/components/failedmessages/FailedMessages.vue b/src/Frontend/src/components/failedmessages/FailedMessages.vue index 1e0ea7ecb..41608ae08 100644 --- a/src/Frontend/src/components/failedmessages/FailedMessages.vue +++ b/src/Frontend/src/components/failedmessages/FailedMessages.vue @@ -129,7 +129,6 @@ async function retrySelected() { selectedMessages.forEach((m) => (m.retryInProgress = true)); } -//TODO: this function doesn't work correctly, since any commas in the exception trace breaks the CSV. //Not attempting to use explicit types correctly since this will need to change eventually anyway function exportSelected() { // eslint-disable-next-line @typescript-eslint/no-explicit-any From de018c9e14fe2836c6a922baa8b8d23b0c5d87ac Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 3 Dec 2024 13:45:03 +0100 Subject: [PATCH 6/7] Obey the formatting rules --- src/Frontend/src/components/failedmessages/FailedMessages.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Frontend/src/components/failedmessages/FailedMessages.vue b/src/Frontend/src/components/failedmessages/FailedMessages.vue index 41608ae08..68011f361 100644 --- a/src/Frontend/src/components/failedmessages/FailedMessages.vue +++ b/src/Frontend/src/components/failedmessages/FailedMessages.vue @@ -133,7 +133,7 @@ async function retrySelected() { function exportSelected() { // eslint-disable-next-line @typescript-eslint/no-explicit-any function toCSV(array: any[]) { - const delimiter = ','; + const delimiter = ","; const keys = Object.keys(array[0]); let result = keys.join(delimiter) + "\n"; array.forEach((obj) => { From 8a6efbcb28d73af8fc3c2f9c4860b2eee80acc0b Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 3 Dec 2024 13:47:15 +0100 Subject: [PATCH 7/7] Only quote if the value contains `"`, `\n` or `,` characters --- src/Frontend/src/components/failedmessages/FailedMessages.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Frontend/src/components/failedmessages/FailedMessages.vue b/src/Frontend/src/components/failedmessages/FailedMessages.vue index 68011f361..be74f60fa 100644 --- a/src/Frontend/src/components/failedmessages/FailedMessages.vue +++ b/src/Frontend/src/components/failedmessages/FailedMessages.vue @@ -142,7 +142,7 @@ function exportSelected() { .map((k) => { let v = String(obj[k]); v = v.replaceAll('"', '""'); // Escape all double quotes - v = `"${v}"`; // Quote all values to deal with CR characters + if (v.search(/([",\n])/g) >= 0) v = `"${v}"`; // Quote all values to deal with CR characters return v; }) .join(delimiter) + "\n";