Skip to content

Commit

Permalink
Update json export (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehats authored Dec 5, 2024
2 parents 44b8f9c + 5eb7fc6 commit 17189aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/client/src/api/borehole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ export const importBoreholes = async (workgroupId: string, combinedFormData: any
export const copyBorehole = async (boreholeId: GridRowSelectionModel, workgroupId: string | null) => {
return await fetchApiV2(`borehole/copy?id=${boreholeId}&workgroupId=${workgroupId}`, "POST");
};

export const getAllBoreholes = async (ids: number[] | GridRowSelectionModel, pageNumber: number, pageSize: number) => {
const idsQuery = ids.map(id => `ids=${id}`).join("&");
return await fetchApiV2(`borehole?${idsQuery}&pageNumber=${pageNumber}&pageSize=${pageSize}`, "GET");
};
2 changes: 1 addition & 1 deletion src/client/src/pages/detail/detailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const DetailHeader = ({
};

const handleExport = () => {
const jsonString = JSON.stringify(borehole, null, 2);
const jsonString = JSON.stringify([borehole], null, 2);
const blob = new Blob([jsonString], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useHistory } from "react-router-dom";
import { GridRowSelectionModel, GridSortDirection, GridSortModel } from "@mui/x-data-grid";
import { deleteBoreholes } from "../../../api-lib";
import { Boreholes, ReduxRootState, User } from "../../../api-lib/ReduxStateInterfaces.ts";
import { copyBorehole } from "../../../api/borehole.ts";
import { copyBorehole, getAllBoreholes } from "../../../api/borehole.ts";
import { OverViewContext } from "../overViewContext.tsx";
import { FilterContext } from "../sidePanelContent/filter/filterContext.tsx";
import { BoreholeTable } from "./boreholeTable.tsx";
Expand Down Expand Up @@ -89,8 +89,8 @@ const BottomBarContainer = ({
};

const onExportMultiple = async () => {
const exportBoreholes = boreholes.data.filter(borehole => selectionModel.includes(borehole.id));
const jsonString = JSON.stringify(exportBoreholes, null, 2);
const paginatedResponse = await getAllBoreholes(selectionModel, 1, selectionModel.length);
const jsonString = JSON.stringify(paginatedResponse.boreholes, null, 2);
const blob = new Blob([jsonString], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
Expand Down

0 comments on commit 17189aa

Please sign in to comment.