Skip to content

Commit

Permalink
Fix download button in clinical tab
Browse files Browse the repository at this point in the history
  • Loading branch information
arishta authored and arishta-dev committed Dec 19, 2024
1 parent cf4524a commit 8258d2d
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8258d2d

Please sign in to comment.