Skip to content

Commit

Permalink
Merge pull request #323 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Production push
  • Loading branch information
adamjarling authored Apr 24, 2024
2 parents 9a401b4 + 90795c0 commit 6da4a35
Show file tree
Hide file tree
Showing 14 changed files with 1,595 additions and 804 deletions.
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

npm run ts-lint-commit-hook
npm run lint
# npm run lint && npm run test:ci
npm run lint && npm run test:ci
25 changes: 24 additions & 1 deletion components/Work/ActionsDialog/Cite.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, screen, within } from "@testing-library/react";

import WorkDialogCite from "@/components/Work/ActionsDialog/Cite";
import { WorkProvider } from "@/context/work-context";
import { sampleWork1 } from "@/mocks/sample-work1";
Expand All @@ -13,17 +14,19 @@ describe("WorkDialogCite", () => {
}
it("renders thumbnail column content", async () => {
setup();

const div = screen.getByTestId("actions-dialog-aside");

expect(within(div).getByAltText(`${sampleWork1.title}`));
expect(within(div).getByText(sampleWork1.work_type as string));
});

it("renders expected metadata content", () => {
const { ark, terms_of_use, title } = sampleWork1;

const metadataValues = [ark, terms_of_use, title];

setup();

const div = screen.getByTestId("metadata");

// <dt>s
Expand All @@ -47,6 +50,26 @@ describe("WorkDialogCite", () => {

it("renders copy links for all metadata", () => {
setup();

expect(screen.getAllByText(/copy/i).length).toEqual(7);
});

it("renders today's date (date accessed) in MLA and APA Formats", () => {
setup();

const div = screen.getByTestId("metadata");
const today = new Date().toDateString();

const apaFormatEl = within(div).getByText(
`University Archives, Northwestern University Libraries. (${today}). Hawking dental products in outdoor market, Cuernavaca, Mexico, Retrieved from http://localhost/items/c16029ff-d027-496a-98b7-6f259395a8f7`,
{ exact: false }
);
const mlaFormatEl = within(div).getByText(
`University Archives, Northwestern University Libraries. "Hawking dental products in outdoor market, Cuernavaca, Mexico", Jim Roberts Photographs, 1968-1972 ${today}. http://localhost/items/c16029ff-d027-496a-98b7-6f259395a8f7`,
{ exact: false }
);

expect(apaFormatEl).toBeVisible();
expect(mlaFormatEl).toBeVisible();
});
});
5 changes: 3 additions & 2 deletions components/Work/ActionsDialog/Cite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ActionsDialogStyled,
Content,
} from "@/components/Work/ActionsDialog/ActionsDialog.styled";

import ActionsDialogAside from "@/components/Work/ActionsDialog/Aside";
import CopyText from "@/components/Shared/CopyText";
import { DefinitionListWrapper } from "@/components/Shared/DefinitionList.styled";
Expand Down Expand Up @@ -30,9 +31,9 @@ const WorkDialogCite: React.FC = () => {
const dateObj: Date = new Date(create_date);
const formattedDate = dateObj.toDateString();
const itemLink = `${window.location.origin}/items/${id}`;
const apaFormat = `${library_unit}, ${nul}. (${formattedDate}). ${title}, Retrieved from ${itemLink}`;
const apaFormat = `${library_unit}, ${nul}. (${today}). ${title}, Retrieved from ${itemLink}`;
const chicagoTurabianFormat = `${library_unit}, ${nul}. "${title}", ${collection_title} Accessed ${today}. ${itemLink}`;
const mlaFormat = `${library_unit}, ${nul}. "${title}", ${collection_title} ${formattedDate}. ${window.location.origin}/items/${id}`;
const mlaFormat = `${library_unit}, ${nul}. "${title}", ${collection_title} ${today}. ${window.location.origin}/items/${id}`;
const wikiCitation = `<ref name=NUL>{{cite web | url=${itemLink} | title= ${title} (${formattedDate}) }} |author=Digital Collections, ${nul} |accessdate=${today} |publisher=${nul}, ${library_unit}}}</ref>`;

const metadata = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,52 @@ const ShareURLActions = styled(EmbedHTMLActionRow, {
},
});

const EmbedResourcesWrapper = styled("div", {
paddingBottom: "$gr3",
});

const AlternateFormatList = styled("ul", {
listStyle: "none",
marginBlockStart: "0px",
paddingInlineStart: "0px",

"> li": {
paddingBottom: "$gr2",
},

"> li > a": {
color: "$black80",
textDecoration: "underline",

"&:hover": {
color: "$black80",
textDecoration: "none",
},
},
});

const PdfLabel = styled("span", {
paddingLeft: "$gr1",
fontSize: "$gr2",
});

export {
AlternateFormatList,
EmbedHTML,
EmbedHTMLActionRow,
EmbedLayoutPreview,
EmbedLayoutPreviewContent,
EmbedLayoutPreviewTitle,
EmbedLayoutPreviewInfoPanel,
EmbedResourcesWrapper,
EmbedViewer,
ItemActions,
ItemContent,
ItemRow,
ItemStyled,
ItemThumbnail,
LayoutImg,
PdfLabel,
ShareURL,
ShareURLActions,
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("DownloadAndShare", () => {
);
expect(screen.getByText("Embed Viewer")).toBeInTheDocument();
expect(screen.getByText(embedWarningText)).toBeInTheDocument();
expect(screen.getByText("Download and Embed Images")).toBeInTheDocument();
expect(screen.getByText("Download and Embed")).toBeInTheDocument();
});

it("renders download but not embed HTML for a private, unpublished work", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import {
ActionsDialogStyled,
Content,
} from "@/components/Work/ActionsDialog/ActionsDialog.styled";
import {
LabeledContentResource,
NULWorkManifest,
} from "@/types/components/works";
import React, { useEffect, useState } from "react";

import ActionsDialogAside from "@/components/Work/ActionsDialog/Aside";
import { Canvas } from "@iiif/presentation-3";
import EmbedImages from "./EmbedImages";
import EmbedResources from "./EmbedResources";
import EmbedViewer from "@/components/Work/ActionsDialog/DownloadAndShare/EmbedViewer";
import IIIFManifest from "./IIIFManifest";
import SharedSocial from "@/components/Shared/Social";
Expand All @@ -22,8 +26,13 @@ const DownloadAndShare: React.FC = () => {
const { workState } = useWorkState();
const { manifest, work } = workState;
const [imageCanvases, setImageCanvases] = useState<Canvas[]>([]);
const [alternateFormatItems, setAlternateFormatItems] = useState<
LabeledContentResource[]
>([]);

const router = useRouter();
const isSharedLinkPage = router.pathname.includes("/shared");

const { isUserLoggedIn, isWorkInstitution, isWorkRestricted } =
useWorkAuth(work);

Expand All @@ -36,7 +45,11 @@ const DownloadAndShare: React.FC = () => {
const imageCanvases = manifest.items.filter(
(item) => getAnnotationBodyType(item) === "Image"
);
const alternateFormatItems = manifest.rendering
? [...manifest.rendering]
: [];
setImageCanvases(imageCanvases);
setAlternateFormatItems(alternateFormatItems);
}
}, [manifest]);

Expand All @@ -62,9 +75,10 @@ const DownloadAndShare: React.FC = () => {
work={work}
/>

{imageCanvases.length > 0 && (
<EmbedImages
manifest={manifest}
{(imageCanvases.length > 0 || alternateFormatItems.length > 0) && (
<EmbedResources
manifest={manifest as NULWorkManifest}
alternateFormatItems={alternateFormatItems}
showEmbedWarning={showEmbedWarning}
work={work}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { render, screen } from "@testing-library/react";

import EmbedResources from "./EmbedResources";
import React from "react";
import { manifest } from "@/mocks/work-page/download-and-share";
import { work1 } from "@/mocks/work-page/work1";

const alternateFormatItems = manifest.rendering ? [...manifest.rendering] : [];

describe("EmbedResources", () => {
it("should render the Download and Embed section with standard images ", () => {
render(
<EmbedResources
manifest={manifest}
alternateFormatItems={[]}
showEmbedWarning={false}
work={work1}
/>
);
expect(
screen.getByRole("heading", { name: "Download and Embed" })
).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Images" })).toBeInTheDocument();

const downloadEmbedItems = screen.getByTestId("download-embed-items");

expect(downloadEmbedItems).toHaveTextContent(
"BFMF_B06_F12_006_022n_am.tif"
);
expect(downloadEmbedItems).toHaveTextContent("Download JPG");
expect(downloadEmbedItems).toHaveTextContent("Embed HTML");
expect(downloadEmbedItems).toHaveTextContent("Copy IIIF");

// Alternate Formats should not be rendered
expect(
screen.queryByRole("heading", { name: "Alternate Formats" })
).toBeNull();
});

it("should render the Download and Embed section with alternate formats. It should also include 'pdf' in the link if it's a PDF mime/type", () => {
render(
<EmbedResources
manifest={manifest}
alternateFormatItems={alternateFormatItems}
showEmbedWarning={false}
work={work1}
/>
);

expect(
screen.getByRole("heading", { name: "Alternate Formats" })
).toBeInTheDocument();
expect(screen.getByRole("link", { name: "Test PDF (pdf)" })).toBeVisible();
expect(screen.getByRole("link", { name: "Transcript XYZ" })).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { Canvas, IIIFExternalWebResource } from "@iiif/presentation-3";
import {
AlternateFormatList,
EmbedHTML,
EmbedHTMLActionRow,
EmbedResourcesWrapper,
ItemActions,
ItemContent,
ItemRow,
ItemStyled,
ItemThumbnail,
PdfLabel,
} from "@/components/Work/ActionsDialog/DownloadAndShare/DownloadAndShare.styled";
import type { Canvas, IIIFExternalWebResource } from "@iiif/presentation-3";
import { Label, Thumbnail } from "@samvera/clover-iiif/primitives";
import {
getAnnotationBodyType,
Expand All @@ -19,22 +22,25 @@ import Announcement from "@/components/Shared/Announcement";
import CopyText from "@/components/Shared/CopyText";
import Heading from "@/components/Heading/Heading";
import IIIFLogo from "@/components/Shared/SVG/IIIF";
import type { Manifest } from "@iiif/presentation-3";
import { NULWorkManifest } from "@/types/components/works";
import React from "react";
import SimpleSelect from "@/components/Shared/SimpleSelect.styled";
import { StyledCopyText } from "@/components/Shared/CopyText.styled";
import type { Work } from "@nulib/dcapi-types";
import { embedWarningMessage } from "./DownloadAndShare";
import { useRouter } from "next/router";
import useWorkAuth from "@/hooks/useWorkAuth";

interface EmbedImagesProps {
manifest: Manifest;
interface EmbedResourcesProps {
manifest: NULWorkManifest;
alternateFormatItems: NULWorkManifest["rendering"];
showEmbedWarning: boolean;
work: Work;
}

const EmbedImages: React.FC<EmbedImagesProps> = ({
const EmbedResources: React.FC<EmbedResourcesProps> = ({
manifest,
alternateFormatItems,
showEmbedWarning,
work,
}) => {
Expand All @@ -53,8 +59,8 @@ const EmbedImages: React.FC<EmbedImagesProps> = ({
}, [manifest]);

return (
<>
<Heading as="h3">Download and Embed Images</Heading>
<EmbedResourcesWrapper>
<Heading as="h3">Download and Embed</Heading>

{isWorkRestricted && !isSharedLinkPage && (
<Announcement>
Expand All @@ -63,21 +69,45 @@ const EmbedImages: React.FC<EmbedImagesProps> = ({
)}

{(!isWorkRestricted || isSharedLinkPage) && (
<div data-testid="download-embed-items">
{imageCanvases.map((item) => (
<Item
item={item}
key={item.id}
showEmbedWarning={showEmbedWarning}
/>
))}
</div>
<>
{alternateFormatItems && alternateFormatItems.length > 0 && (
<>
<Heading as="h4">Alternate Formats</Heading>
<AlternateFormatList>
{alternateFormatItems.map((item) => (
<li key={item.id}>
{item.label && (
<a href={item.id} target="_blank" rel="noreferrer">
<Label label={item.label} as="span" />
{/* @ts-ignore */}
{item.format?.includes("application/pdf") && (
<PdfLabel>(pdf)</PdfLabel>
)}
</a>
)}
</li>
))}
</AlternateFormatList>
</>
)}

<Heading as="h4">Images</Heading>
<div data-testid="download-embed-items">
{imageCanvases.map((item) => (
<Item
item={item}
key={item.id}
showEmbedWarning={showEmbedWarning}
/>
))}
</div>
</>
)}
</>
</EmbedResourcesWrapper>
);
};

export default EmbedImages;
export default EmbedResources;

interface ItemProps {
item: Canvas;
Expand Down Expand Up @@ -142,7 +172,7 @@ const Item: React.FC<ItemProps> = ({ item, showEmbedWarning }) => {
}" />`;

const handleDownloadClick = async (
e: React.SyntheticEvent<HTMLAnchorElement>
e: React.SyntheticEvent<HTMLButtonElement>
) => {
e.preventDefault();

Expand Down Expand Up @@ -179,9 +209,9 @@ const Item: React.FC<ItemProps> = ({ item, showEmbedWarning }) => {
{item.label && <Label label={item.label} as="span" />}
<ItemActions>
<li>
<a onClick={handleDownloadClick} href="#">
<StyledCopyText onClick={handleDownloadClick}>
Download JPG
</a>
</StyledCopyText>
</li>
<li>
<a
Expand Down
Loading

0 comments on commit 6da4a35

Please sign in to comment.