From 8258d2da158b5e758fb7ad1ca60ad2affdf25c57 Mon Sep 17 00:00:00 2001 From: arishta Date: Thu, 28 Nov 2024 15:52:05 +0530 Subject: [PATCH] Fix download button in clinical tab --- .../CopyDownloadControls.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/shared/components/copyDownloadControls/CopyDownloadControls.tsx b/src/shared/components/copyDownloadControls/CopyDownloadControls.tsx index 1de69f70092..e2f4937a29d 100644 --- a/src/shared/components/copyDownloadControls/CopyDownloadControls.tsx +++ b/src/shared/components/copyDownloadControls/CopyDownloadControls.tsx @@ -259,7 +259,25 @@ export class CopyDownloadControls extends React.Component< } public download(text: string) { - fileDownload(text, this.props.downloadFilename); + try { + const jsonData = JSON.parse(text); + if (Array.isArray(jsonData)) { + const headers = Object.keys(jsonData[0]); + + const tsvContent = [ + headers.join('\t'), + ...jsonData.map(row => + headers.map(header => row[header] || '').join('\t') + ), + ].join('\n'); + + fileDownload(tsvContent, this.props.downloadFilename); + return; + } + } catch (error) { + // Fallback to downloading raw text if JSON parsing fails + fileDownload(text, this.props.downloadFilename); + } } @action