Skip to content

Commit 6c979ad

Browse files
authored
Merge pull request #286 from nulib/3903-mirador-warning
Update message for opening a work in Mirador for authenticated Works
2 parents d268812 + 2ad5846 commit 6c979ad

File tree

6 files changed

+1278
-787
lines changed

6 files changed

+1278
-787
lines changed

components/Shared/Announcement.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CSS } from "@stitches/react/types/css-util";
12
import React from "react";
23
import { maxWidths } from "@/styles/containers";
34
import { styled } from "@/stitches.config";
@@ -40,6 +41,7 @@ const ContentWrapper = styled("div", {
4041

4142
interface AnnouncementProps {
4243
children: React.ReactNode;
44+
css?: CSS;
4345
}
4446

4547
const Announcement: React.FC<AnnouncementProps> = ({

components/Work/ActionsDialog/DownloadAndShare.styled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const ShareURL = styled(EmbedHTML, {
120120
const ShareURLActions = styled(EmbedHTMLActionRow, {
121121
marginTop: "$gr3",
122122

123-
"> a, > button": {
123+
"> a, > button, > span": {
124124
marginLeft: "$gr3",
125125
color: "$black50",
126126
fontSize: "$gr3",

components/Work/ActionsDialog/DownloadAndShare.test.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import {
33
mockPrivateUnpublishedWorkManifest,
44
} from "@/mocks/private-unpublished-work";
55
import { render, screen } from "@testing-library/react";
6+
import {
7+
samplePublicWork,
8+
samplePublicWorkManifest,
9+
} from "@/mocks/sample-public-work";
610

711
import DownloadAndShare from "./DownloadAndShare";
12+
import { Work } from "@nulib/dcapi-types";
813
import { WorkProvider } from "@/context/work-context";
914
import mockRouter from "next-router-mock";
1015
import userEvent from "@testing-library/user-event";
@@ -72,4 +77,73 @@ describe("DownloadAndShare", () => {
7277
await user.click(screen.getAllByText("Embed HTML")[1]);
7378
expect(screen.getAllByText(embedWarningText)).toHaveLength(3);
7479
});
80+
81+
it("renders a link for Mirador without a warning message", () => {
82+
mockRouter.setCurrentUrl("/items/8163f95b-cd40-4210-a7ff-e25b7b39c8d6");
83+
84+
render(
85+
<WorkProvider
86+
initialState={{
87+
// @ts-ignore
88+
manifest: samplePublicWorkManifest,
89+
work: samplePublicWork,
90+
}}
91+
>
92+
<DownloadAndShare />
93+
</WorkProvider>
94+
);
95+
96+
expect(screen.queryByTestId("mirador-announcement")).toBeNull();
97+
expect(screen.getByText("View in Mirador")).toHaveAttribute("href");
98+
});
99+
100+
it("renders no Mirador link and a warning message for an Institution and Private Work", async () => {
101+
mockRouter.setCurrentUrl("/items/8163f95b-cd40-4210-a7ff-e25b7b39c8d6");
102+
103+
// Institution Work
104+
let work = {
105+
...samplePublicWork,
106+
visibility: "Institution" as Work["visibility"],
107+
};
108+
109+
const { rerender } = render(
110+
<WorkProvider
111+
initialState={{
112+
// @ts-ignore
113+
manifest: samplePublicWorkManifest,
114+
work,
115+
}}
116+
>
117+
<DownloadAndShare />
118+
</WorkProvider>
119+
);
120+
121+
expect(
122+
await screen.findByTestId("mirador-announcement")
123+
).toBeInTheDocument();
124+
expect(screen.getByText("View in Mirador")).not.toHaveAttribute("href");
125+
126+
// Private Work
127+
work = {
128+
...samplePublicWork,
129+
visibility: "Private" as Work["visibility"],
130+
};
131+
132+
rerender(
133+
<WorkProvider
134+
initialState={{
135+
// @ts-ignore
136+
manifest: samplePublicWorkManifest,
137+
work,
138+
}}
139+
>
140+
<DownloadAndShare />
141+
</WorkProvider>
142+
);
143+
144+
expect(
145+
await screen.findByTestId("mirador-announcement")
146+
).toBeInTheDocument();
147+
expect(screen.getByText("View in Mirador")).not.toHaveAttribute("href");
148+
});
75149
});

components/Work/ActionsDialog/DownloadAndShare.tsx

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import {
1515
ShareURL,
1616
ShareURLActions,
1717
} from "@/components/Work/ActionsDialog/DownloadAndShare.styled";
18-
1918
import { Label, Thumbnail } from "@samvera/nectar-iiif";
2019
import React, { useEffect, useState } from "react";
2120
import {
2221
getAnnotationBodyType,
2322
getInfoResponse,
2423
} from "@/lib/iiif/manifest-helpers";
2524
import { makeBlob, mimicDownload } from "@samvera/image-downloader";
25+
2626
import ActionsDialogAside from "@/components/Work/ActionsDialog/Aside";
2727
import Announcement from "@/components/Shared/Announcement";
2828
import CopyText from "@/components/Shared/CopyText";
@@ -37,13 +37,32 @@ import { useWorkState } from "@/context/work-context";
3737
const embedWarningMessage =
3838
"Embed is not available for works restricted to the Northwestern University community";
3939

40+
function MiradorLink({
41+
showWarning,
42+
manifestId,
43+
}: {
44+
showWarning: boolean;
45+
manifestId: string;
46+
}) {
47+
return showWarning ? (
48+
<span>View in Mirador</span>
49+
) : (
50+
<a
51+
href={`https://projectmirador.org/embed/?iiif-content=${manifestId}`}
52+
target="_blank"
53+
>
54+
View in Mirador
55+
</a>
56+
);
57+
}
58+
4059
const DownloadAndShare: React.FC = () => {
4160
const { workState } = useWorkState();
4261
const { manifest, work } = workState;
4362
const [imageCanvases, setImageCanvases] = useState<Canvas[]>([]);
4463
const router = useRouter();
4564
const isSharedLinkPage = router.pathname.includes("/shared");
46-
const { isUserLoggedIn, isWorkInstitution, isWorkRestricted } =
65+
const { isUserLoggedIn, isWorkInstitution, isWorkPrivate, isWorkRestricted } =
4766
useWorkAuth(work);
4867

4968
const showEmbedWarning = Boolean(
@@ -98,13 +117,22 @@ const DownloadAndShare: React.FC = () => {
98117
<a href="https://iiif.io/get-started/why-iiif/" target="_blank">
99118
What is IIIF?
100119
</a>
101-
<a
102-
href={`https://projectmirador.org/embed/?iiif-content=${manifest.id}`}
103-
target="_blank"
104-
>
105-
View in Mirador
106-
</a>
120+
<MiradorLink
121+
showWarning={isWorkInstitution || isWorkPrivate}
122+
manifestId={manifest.id}
123+
/>
107124
</ShareURLActions>
125+
{(isWorkInstitution || isWorkPrivate) && (
126+
<Announcement
127+
css={{
128+
marginTop: "1rem",
129+
}}
130+
data-testid="mirador-announcement"
131+
>
132+
Opening in external tools like Mirador is not supported for works
133+
that require authentication.
134+
</Announcement>
135+
)}
108136
</ShareURL>
109137
</>
110138
)}

0 commit comments

Comments
 (0)