From 9227afcb4867ad81c8a87fa7afe778fe969de97a Mon Sep 17 00:00:00 2001 From: Olivia Wong Date: Tue, 15 Feb 2022 10:56:23 -0500 Subject: [PATCH 1/6] Cleans up --- src/components/CatalogLink.tsx | 35 ++++ src/components/CustomListBookCard.tsx | 12 +- src/components/CustomListEntries.tsx | 6 +- src/components/CustomListInfo.tsx | 1 + src/components/CustomListSearchResults.tsx | 6 +- src/components/CustomListsSidebar.tsx | 1 + .../CustomListEditorBody.test.js | 184 ++++++++++++++++++ .../CustomListEditorHeader.test.js | 87 +++++++++ .../__tests_jest__/CustomListEntries.test.js | 8 +- .../__tests_jest__/CustomListPage.test.js | 19 +- .../__tests_jest__/CustomLists.test.js | 114 +++++++++++ src/testUtils/testUtils.jsx | 7 +- 12 files changed, 455 insertions(+), 25 deletions(-) create mode 100644 src/components/CatalogLink.tsx create mode 100644 src/components/__tests_jest__/CustomListEditorBody.test.js create mode 100644 src/components/__tests_jest__/CustomListEditorHeader.test.js create mode 100644 src/components/__tests_jest__/CustomLists.test.js diff --git a/src/components/CatalogLink.tsx b/src/components/CatalogLink.tsx new file mode 100644 index 000000000..5b71afe3f --- /dev/null +++ b/src/components/CatalogLink.tsx @@ -0,0 +1,35 @@ +import * as React from "react"; +import { Link } from "react-router"; + +export default function CatalogLink({ url, title, label }) { + const prepareBookUrl = (url: string): string => { + const regexp = new RegExp(document.location.origin + "/(.*)/works/(.*)"); + const match = regexp.exec(url); + if (match) { + const library = match[1]; + const work = match[2]; + return encodeURIComponent(library + "/" + work); + } else { + return url; + } + }; + + const pathFor = (bookUrl: string) => { + let path = "/admin/web"; + path += bookUrl ? `/book/${prepareBookUrl(bookUrl)}` : ""; + return path; + }; + + const finalBookUrl = pathFor(url); + + return ( + + {label} + + ); +} diff --git a/src/components/CustomListBookCard.tsx b/src/components/CustomListBookCard.tsx index 2dc7bb9dc..9385de66a 100644 --- a/src/components/CustomListBookCard.tsx +++ b/src/components/CustomListBookCard.tsx @@ -4,8 +4,8 @@ import { BookData } from "opds-web-client/lib/interfaces"; import GrabIcon from "./icons/GrabIcon"; import TrashIcon from "./icons/TrashIcon"; import AddIcon from "./icons/AddIcon"; +import CatalogLink from "./CatalogLink"; import { Button } from "library-simplified-reusable-components"; -import CatalogLink from "opds-web-client/lib/components/CatalogLink"; import { getMedium, getMediumSVG } from "opds-web-client/lib/utils/book"; export interface Entry extends BookData { @@ -24,7 +24,6 @@ export interface CustomListBookCardProps { export default function CustomListBookCard({ index, typeOfCard, - opdsFeedUrl, book, handleAddEntry, handleDeleteEntry, @@ -53,13 +52,10 @@ export default function CustomListBookCard({
{book.url && ( - View details - + label="View Details" + /> )} {isSearchResult ? (