Skip to content

Commit d1cda2b

Browse files
committed
fix error on phenopackets JSON download
1 parent 44b17e0 commit d1cda2b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/components/explorer/IndividualPhenopackets.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
import { useEffect } from "react";
2-
3-
import { Divider, Skeleton } from "antd";
2+
import { Divider, Skeleton, Button } from "antd";
3+
import { DownloadOutlined } from "@ant-design/icons";
4+
import { saveAs } from "file-saver";
45

56
import { fetchIndividualPhenopacketsIfNecessary } from "@/modules/metadata/actions";
67
import { individualPropTypesShape } from "@/propTypes";
78

8-
import DownloadButton from "@/components/common/DownloadButton";
99
import JsonView from "@/components/common/JsonView";
10-
import { useService } from "@/modules/services/hooks";
1110
import { useAppDispatch, useAppSelector } from "@/store";
1211

1312
const IndividualPhenopackets = ({ individual }) => {
1413
const dispatch = useAppDispatch();
15-
1614
const { id: individualId } = individual;
1715

18-
const katsuUrl = useService("metadata")?.url ?? "";
19-
const downloadUrl = `${katsuUrl}/api/individuals/${individualId}/phenopackets?attachment=1&format=json`;
20-
2116
const { phenopacketsByIndividualID } = useAppSelector((state) => state.individuals);
2217

2318
const { isFetching, data } = phenopacketsByIndividualID[individualId] ?? {};
@@ -26,12 +21,24 @@ const IndividualPhenopackets = ({ individual }) => {
2621
dispatch(fetchIndividualPhenopacketsIfNecessary(individualId));
2722
}, [dispatch, individualId]);
2823

24+
const handleDownloadFromState = () => {
25+
if (!data) return;
26+
const jsonString = JSON.stringify(data, null, 2);
27+
const blob = new Blob([jsonString], { type: "application/json" });
28+
saveAs(blob, `phenopackets_${individualId}.json`);
29+
};
30+
2931
return (
3032
<>
31-
<DownloadButton uri={downloadUrl} disabled={!katsuUrl}>
33+
<Button
34+
icon={<DownloadOutlined />}
35+
onClick={handleDownloadFromState}
36+
disabled={!data || isFetching}
37+
>
3238
Download JSON
33-
</DownloadButton>
34-
<Divider />
39+
</Button>
40+
41+
<Divider />
3542
{data === undefined || isFetching ? (
3643
<Skeleton title={false} loading={true} />
3744
) : (

0 commit comments

Comments
 (0)