Skip to content

Commit

Permalink
Use functions to get filesnames
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt committed Dec 10, 2024
1 parent e2f683b commit bd5de35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/client/src/pages/detail/detailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ const DetailHeader = ({
history.push("/");
};

const getFileName = (name: string) => {
return name.replace(/\s/g, "_");
};
const handleJsonExport = () => {
const jsonString = JSON.stringify([borehole], null, 2);
downloadData(jsonString, borehole.name.replace(/\s/g, "_"), "application/json");
downloadData(jsonString, getFileName(borehole.name), "application/json");
};

const handleCSVExport = async () => {
const csvData = await exportCSVBorehole([borehole.id]);
downloadData(csvData, borehole.name.replace(/\s/g, "_"), "text/csv");
downloadData(csvData, getFileName(borehole.name), "text/csv");
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ const BottomBarContainer = ({
setIsBusy(false);
};

const getBulkExportFilename = (suffix: string) => {
return `bulkexport_${new Date().toISOString().split("T")[0]}.${suffix}`;
};

const handleExportMultipleJson = async () => {
const paginatedResponse = await getAllBoreholes(selectionModel, 1, selectionModel.length);
const jsonString = JSON.stringify(paginatedResponse.boreholes, null, 2);
downloadData(jsonString, `bulkexport_${new Date().toISOString().split("T")[0]}.json`, "application/json");
downloadData(jsonString, getBulkExportFilename("json"), "application/json");
};

const handleExportMultipleCsv = async () => {
const csvData = await exportCSVBorehole(selectionModel.slice(0, 100));
downloadData(csvData, `bulkexport_${new Date().toISOString().split("T")[0]}.csv`, "text/csv");
downloadData(csvData, getBulkExportFilename("csv"), "text/csv");
};

const showPromptExportMoreThan100 = (callback: () => void) => {
Expand Down

0 comments on commit bd5de35

Please sign in to comment.