Skip to content

Commit 7a458d4

Browse files
authored
fix: re-add download buttons (#155)
1 parent bc8b011 commit 7a458d4

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/components/item-search.tsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { useEffect, useMemo, useState } from "react";
2-
import { LuPause, LuPlay, LuSearch, LuStepForward, LuX } from "react-icons/lu";
2+
import {
3+
LuDownload,
4+
LuPause,
5+
LuPlay,
6+
LuSearch,
7+
LuStepForward,
8+
LuX,
9+
} from "react-icons/lu";
310
import {
411
Alert,
512
Button,
613
ButtonGroup,
714
createListCollection,
15+
DownloadTrigger,
816
Field,
917
Group,
1018
Heading,
@@ -25,6 +33,7 @@ import type {
2533
StacLink,
2634
TemporalExtent,
2735
} from "stac-ts";
36+
import * as stac_wasm from "stac-wasm";
2837
import { SpatialExtent } from "./extent";
2938
import useStacSearch from "../hooks/stac-search";
3039
import type { BBox2D } from "../types/map";
@@ -175,6 +184,16 @@ function Search({
175184
setItems(items);
176185
}, [items, setItems]);
177186

187+
const downloadJson = () => {
188+
return JSON.stringify(
189+
items ? { type: "FeatureCollection", features: items } : {}
190+
);
191+
};
192+
193+
const downloadStacGeoparquet = () => {
194+
return new Blob(items ? [stac_wasm.stacJsonToParquet(items)] : []);
195+
};
196+
178197
return (
179198
<Stack gap={4}>
180199
<Heading size={"md"}>Search results</Heading>
@@ -230,6 +249,33 @@ function Search({
230249
Clear <LuX />
231250
</Button>
232251
</ButtonGroup>
252+
{items && items.length > 0 && (
253+
<>
254+
<Heading size={"sm"}>Download</Heading>
255+
<ButtonGroup variant={"surface"} size={"xs"}>
256+
<DownloadTrigger
257+
data={downloadJson}
258+
fileName="search.json"
259+
mimeType="application/json"
260+
asChild
261+
>
262+
<Button>
263+
JSON <LuDownload />
264+
</Button>
265+
</DownloadTrigger>
266+
<DownloadTrigger
267+
data={downloadStacGeoparquet}
268+
fileName="search.parquet"
269+
mimeType="application/json"
270+
asChild
271+
>
272+
<Button>
273+
stac-geoparquet <LuDownload />
274+
</Button>
275+
</DownloadTrigger>
276+
</ButtonGroup>
277+
</>
278+
)}
233279
</Stack>
234280
);
235281
}

tests/app.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,21 @@ describe("app", () => {
6464
.element(app.getByRole("heading", { name: "Planet" }))
6565
.toBeVisible();
6666
});
67+
68+
test("renders download buttons", async () => {
69+
window.history.pushState(
70+
{},
71+
"",
72+
"?href=https://stac.eoapi.dev/collections/MAXAR_yellowstone_flooding22"
73+
);
74+
const app = renderApp();
75+
await app.getByRole("button", { name: "Item search" }).click();
76+
await app.getByRole("button", { name: "Search", exact: true }).click();
77+
await expect
78+
.element(app.getByRole("button", { name: "JSON" }))
79+
.toBeVisible();
80+
await expect
81+
.element(app.getByRole("button", { name: "stac-geoparquet" }))
82+
.toBeVisible();
83+
});
6784
});

0 commit comments

Comments
 (0)