Skip to content

Commit a6b62d2

Browse files
authored
Merge pull request #201 from samvera-labs/patch-fix-rendering-download
Patch fix for the rendering download button
2 parents 45bc31d + 9c902ec commit a6b62d2

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

src/components/Viewer/Viewer/Download.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { render, screen } from "@testing-library/react";
44
import Download from "./Download";
55
import React from "react";
66
import { Vault } from "@iiif/vault";
7+
import noRenderingManifest from "src/fixtures/viewer/rendering/manifest-without-renderings.json";
78
import renderingManifest from "src/fixtures/iiif-cookbook/0046-rendering.json";
89
import renderingMultipleManifest from "src/fixtures/viewer/rendering/manifest-with-renderings.json";
910
import userEvent from "@testing-library/user-event";
@@ -81,4 +82,26 @@ describe("Viewer Download popover component", () => {
8182
screen.getByText("Download the original file (image/tiff)"),
8283
).toBeInTheDocument();
8384
});
85+
86+
it("should not render the download button when no rendering items are present", async () => {
87+
await vault.loadManifest("", noRenderingManifest);
88+
89+
render(
90+
<ViewerProvider
91+
initialState={{
92+
...defaultState,
93+
activeManifest:
94+
"https://iiif.io/api/cookbook/recipe/0046-rendering/manifest.json",
95+
activeCanvas:
96+
"https://iiif.io/api/cookbook/recipe/0046-rendering/canvas/p1",
97+
vault,
98+
}}
99+
>
100+
<Download />
101+
</ViewerProvider>,
102+
);
103+
104+
expect(screen.queryByTestId("download-button")).toBeNull();
105+
expect(screen.queryByTestId("download-content")).toBeNull();
106+
});
84107
});

src/components/Viewer/Viewer/Download.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ import useViewerDownload from "src/hooks/useViewerDownload";
1111

1212
const ViewerDownload = () => {
1313
const { allPages, individualPages } = useViewerDownload();
14+
const showDownloadButton = allPages.length > 0 || individualPages.length > 0;
1415

1516
const handleDownloadClick = (id: RenderingItem["id"]) => {
1617
window.open(id, "_blank");
1718
};
1819

20+
if (!showDownloadButton) {
21+
return null;
22+
}
23+
1924
return (
2025
<Popover>
2126
<DownloadButton data-testid="download-button">
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"@context": "http://iiif.io/api/presentation/3/context.json",
3+
"id": "https://iiif.io/api/cookbook/recipe/0046-rendering/manifest.json",
4+
"type": "Manifest",
5+
"label": {
6+
"en": ["No Rendering properties"]
7+
},
8+
"summary": {
9+
"en": ["Test"]
10+
},
11+
"viewingDirection": "right-to-left",
12+
"items": [
13+
{
14+
"id": "https://iiif.io/api/cookbook/recipe/0046-rendering/canvas/p1",
15+
"type": "Canvas",
16+
"label": {
17+
"en": ["front cover"]
18+
},
19+
"width": 3497,
20+
"height": 4823,
21+
"items": [
22+
{
23+
"id": "https://iiif.io/api/cookbook/recipe/0046-rendering/page/p1/1",
24+
"type": "AnnotationPage",
25+
"items": [
26+
{
27+
"id": "https://iiif.io/api/cookbook/recipe/0046-rendering/annotation/p0001-image",
28+
"type": "Annotation",
29+
"motivation": "painting",
30+
"body": {
31+
"id": "https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_001/full/max/0/default.jpg",
32+
"type": "Image",
33+
"format": "image/jpeg",
34+
"width": 3497,
35+
"height": 4823,
36+
"service": [
37+
{
38+
"id": "https://iiif.io/api/image/3.0/example/reference/4f92cceb12dd53b52433425ce44308c7-ucla_bib1987273_no001_rs_001",
39+
"type": "ImageService3",
40+
"profile": "level1"
41+
}
42+
]
43+
},
44+
"target": "https://iiif.io/api/cookbook/recipe/0046-rendering/canvas/p1"
45+
}
46+
]
47+
}
48+
]
49+
}
50+
]
51+
}

0 commit comments

Comments
 (0)