Skip to content

Commit d749317

Browse files
Dynamic file naming
1 parent 97b89be commit d749317

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

frontend/src/components/DownloadButton.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { downloadTabulatedDataAsCSV } from "@/functions/Formatting";
55

66
interface DownloadButtonProps {
77
csvContent: string;
8-
isLoading?: boolean;
8+
fileName: string;
9+
isLoading: boolean;
910
}
1011

11-
const DownloadButton: React.FC<DownloadButtonProps> = ({ csvContent, isLoading }) => {
12+
const DownloadButton: React.FC<DownloadButtonProps> = ({ csvContent, isLoading, fileName }) => {
1213
const handleDownload = () => {
13-
downloadTabulatedDataAsCSV(csvContent);
14+
downloadTabulatedDataAsCSV(csvContent, fileName);
1415
};
1516

1617
return (

frontend/src/functions/Formatting.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ export function convertTabulatedDataToCSVFormat(tabulatedData: TabulatedResultRo
145145

146146
return csvContent;
147147
}
148-
export const downloadTabulatedDataAsCSV = (csvContent: string) => {
148+
export const downloadTabulatedDataAsCSV = (csvContent: string, fileName: string) => {
149149
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
150150
const url = URL.createObjectURL(blob);
151151
const a = document.createElement("a");
152152
a.href = url;
153-
a.download = "downloadedResults.csv";
153+
a.download = fileName;
154154
document.body.appendChild(a);
155155
a.click();
156156
document.body.removeChild(a);

frontend/src/pages/LabResults.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const LabResults: React.FC = () => {
8181
...convertSimulationQueriesResultToTabulatedData(simulationQueryResults.data),
8282
...convertExperimentResultsToTabulatedData(selectedExperiments),
8383
])}
84+
fileName="Labresults.csv"
8485
isLoading={
8586
isLoading || simulationQueryResults.statuses.some((status) => status.status === "pending")
8687
}

frontend/src/pages/Models.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const Models: React.FC = () => {
7676
[`${simulationResults.modelInput.modelId}`]: [simulationResults],
7777
})
7878
])}
79+
fileName="ModelResults.csv"
7980
isLoading={isLoading}
8081
/>
8182
</div>

0 commit comments

Comments
 (0)