Skip to content

Commit a8689e8

Browse files
authored
Merge pull request #293 from nulib/deploy/staging
Production push
2 parents 534ccf6 + 6648842 commit a8689e8

File tree

11 files changed

+1137
-719
lines changed

11 files changed

+1137
-719
lines changed

components/Collection/Tabs/Explore.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from "react";
2+
23
import type { GetTopMetadataAggsReturn } from "@/lib/collection-helpers";
34
import RelatedItems from "@/components/Shared/RelatedItems";
45

@@ -18,10 +19,12 @@ const CollectionTabsExplore: React.FC<CollectionTabsExploreProps> = ({
1819
useEffect(() => {
1920
/**
2021
* In the future we could support multiple metadata fields, but for
21-
* now we'll just assume passing in 3 Subject collections to Bloom
22+
* now we'll just assume passing in 3 Subject collections to the Slider
2223
*/
2324
const subject = topMetadata[0];
25+
console.log("subject", subject);
2426

27+
// Build "as=iiif" urls for each subject which will feed into the Slider
2528
setUrls(
2629
subject.value.map((subjectValue) => {
2730
const str = `${url}/search?query=collection.id:"${collectionId}" AND ${

components/Facets/Facets.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FacetExtras, StyledFacets, Width, Wrapper } from "./Facets.styled";
22
import React, { useRef } from "react";
3+
34
import Container from "@/components/Shared/Container";
45
import FacetsFilter from "@/components/Facets/Filter/Filter";
56
import SearchPublicOnlyWorks from "@/components/Search/PublicOnlyWorks";

components/Search/Search.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import React, {
1212
useRef,
1313
useState,
1414
} from "react";
15+
1516
import { ALL_FACETS } from "@/lib/constants/facets-model";
1617
import useQueryParams from "@/hooks/useQueryParams";
1718
import { useRouter } from "next/router";
@@ -34,6 +35,10 @@ const Search: React.FC<SearchProps> = ({ isSearchActive }) => {
3435

3536
/* Guard against searching from a page with dynamic route params */
3637
const facetIds = ALL_FACETS.facets.map((facet) => facet.id);
38+
39+
// Account for the "similar" facet (comes from "View All" in sliders)
40+
facetIds.push("similar");
41+
3742
const urlFacetsKeys = Object.keys(urlFacets);
3843
urlFacetsKeys.forEach((key) => {
3944
if (!facetIds.includes(key)) {

components/Search/Similar.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { render, screen } from "@/test-utils";
2+
3+
import SearchSimilar from "./Similar";
4+
5+
describe("SearchSimilar component", () => {
6+
const mockSetShowSimilar = jest.fn();
7+
const props = {
8+
handleClose: mockSetShowSimilar,
9+
work: {
10+
id: "abc123",
11+
title: "ima source work for similar results",
12+
},
13+
};
14+
15+
it("renders the Work title and a link to the Work page", () => {
16+
render(<SearchSimilar {...props} />);
17+
const title = screen.getByText(/ima source work for similar results/i);
18+
expect(title).toBeInTheDocument();
19+
20+
expect(
21+
screen.getByRole("link", { name: /ima source work for similar results/i })
22+
).toHaveAttribute("href", "/items/abc123");
23+
});
24+
25+
it("renders a close button, which calls a callback fn", () => {
26+
render(<SearchSimilar {...props} />);
27+
const button = screen.getByRole("button", { name: /close/i });
28+
expect(button).toBeInTheDocument();
29+
button.click();
30+
expect(mockSetShowSimilar).toHaveBeenCalledTimes(1);
31+
});
32+
});

components/Search/Similar.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import Announcement from "@/components/Shared/Announcement";
2+
import { IconClear } from "@/components/Shared/SVG/Icons";
3+
import Link from "next/link";
4+
import React from "react";
5+
import { styled } from "@/stitches.config";
6+
7+
interface Props {
8+
handleClose: () => void;
9+
work: {
10+
id: string;
11+
title: string;
12+
};
13+
}
14+
15+
/* eslint sort-keys: 0 */
16+
17+
const SimilarWrapper = styled(Announcement, {
18+
marginBottom: "$gr4",
19+
paddingTop: "$gr1",
20+
paddingBottom: "$gr1",
21+
});
22+
23+
const SimilarStyled = styled("div", {
24+
display: "flex",
25+
justifyContent: "center",
26+
alignItems: "center",
27+
color: "$purple",
28+
position: "relative",
29+
30+
"& button": {
31+
position: "absolute",
32+
right: 0,
33+
background: "transparent",
34+
border: "none",
35+
cursor: "pointer",
36+
37+
"& span": {
38+
display: "none",
39+
},
40+
41+
"& svg": {
42+
width: "$gr3",
43+
height: "$gr3",
44+
},
45+
},
46+
});
47+
48+
const SearchSimilar: React.FC<Props> = ({ handleClose, work }) => {
49+
return (
50+
<SimilarWrapper>
51+
<SimilarStyled>
52+
<p>
53+
You are viewing works similar to{" "}
54+
<Link href={`/items/${work?.id}`}>{work?.title}</Link>
55+
</p>
56+
<button type="button" onClick={handleClose}>
57+
<span>Close</span>
58+
<IconClear />
59+
</button>
60+
</SimilarStyled>
61+
</SimilarWrapper>
62+
);
63+
};
64+
65+
export default SearchSimilar;

components/Work/ActionsDialog/DownloadAndShare.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function MiradorLink({
5050
<a
5151
href={`https://projectmirador.org/embed/?iiif-content=${manifestId}`}
5252
target="_blank"
53+
rel="noreferrer"
5354
>
5455
View in Mirador
5556
</a>
@@ -114,7 +115,11 @@ const DownloadAndShare: React.FC = () => {
114115
textPrompt="Copy Manifest Link"
115116
textToCopy={manifest.id}
116117
/>
117-
<a href="https://iiif.io/get-started/why-iiif/" target="_blank">
118+
<a
119+
href="https://iiif.io/get-started/why-iiif/"
120+
target="_blank"
121+
rel="noreferrer"
122+
>
118123
What is IIIF?
119124
</a>
120125
<MiradorLink

jest.setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Used for __tests__/testing-library.js
22
// Learn more: https://github.com/testing-library/jest-dom
3-
import "@testing-library/jest-dom/extend-expect";
3+
import "@testing-library/jest-dom";
44

55
jest.mock("next/dynamic", () => () => {
66
const DynamicComponent = () => null;

lib/queries/builder.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { buildSearchPart, querySearchTemplate } from "@/lib/queries/search";
2+
23
import { ApiSearchRequestBody } from "@/types/api/request";
34
import { FacetsInstance } from "@/types/components/facets";
45
import { QueryDslQueryContainer } from "@elastic/elasticsearch/api/types";
@@ -16,10 +17,17 @@ type BuildQueryProps = {
1617

1718
export function buildQuery(obj: BuildQueryProps) {
1819
const { aggs, aggsFilterValue, size, term, urlFacets } = obj;
19-
2020
const must: QueryDslQueryContainer[] = [];
21+
2122
if (term) must.push(buildSearchPart(term));
22-
if (Object.keys(urlFacets).length > 0) must.push(addFacetsToQuery(urlFacets));
23+
24+
if (Object.keys(urlFacets).length > 0) {
25+
must.push(addFacetsToQuery(urlFacets));
26+
27+
if (Object.hasOwn(urlFacets, "similar")) {
28+
must.push(addMoreLikeThis(urlFacets));
29+
}
30+
}
2331

2432
return {
2533
...querySearchTemplate,
@@ -42,3 +50,26 @@ export function addFacetsToQuery(urlFacets: UrlFacets) {
4250
},
4351
};
4452
}
53+
54+
function addMoreLikeThis(urlFacets: UrlFacets) {
55+
return {
56+
more_like_this: {
57+
fields: [
58+
"title",
59+
"description",
60+
"subject.label",
61+
"genre.label",
62+
"contributor.label",
63+
"creator.label",
64+
],
65+
like: [
66+
{
67+
_id: urlFacets.similar[0],
68+
},
69+
],
70+
max_query_terms: 10,
71+
min_doc_freq: 1,
72+
min_term_freq: 1,
73+
},
74+
};
75+
}

0 commit comments

Comments
 (0)