diff --git a/pages/bib/[id]/index.tsx b/pages/bib/[id]/index.tsx index 26074b8ec..9132d1388 100644 --- a/pages/bib/[id]/index.tsx +++ b/pages/bib/[id]/index.tsx @@ -84,7 +84,6 @@ export default function BibPage({ discoveryBibResult, annotatedMarc ) - const displayLegacyCatalogLink = isNyplBibID(bib.id) const filtersAreApplied = areFiltersApplied(appliedFilters) diff --git a/src/components/BibPage/BibDetail.tsx b/src/components/BibPage/BibDetail.tsx index a8606b8b4..b6d271d22 100644 --- a/src/components/BibPage/BibDetail.tsx +++ b/src/components/BibPage/BibDetail.tsx @@ -14,7 +14,6 @@ import type { } from "../../types/bibDetailsTypes" import { rtlOrLtr, isItTheLastElement } from "../../utils/bibUtils" import type { ReactNode } from "react" -import { BASE_URL } from "../../config/constants" interface BibDetailsProps { details: AnyBibDetail[] diff --git a/src/models/BibDetails.ts b/src/models/BibDetails.ts index 1a3245e96..09494a5ba 100644 --- a/src/models/BibDetails.ts +++ b/src/models/BibDetails.ts @@ -10,7 +10,6 @@ import type { AnyBibDetail, } from "../types/bibDetailsTypes" import { convertToSentenceCase } from "../utils/appUtils" -import type { JSONLDValue } from "../types/itemTypes" export default class BibDetails { bib: DiscoveryBibResult @@ -20,9 +19,9 @@ export default class BibDetails { bottomDetails: AnyBibDetail[] groupedNotes: AnyBibDetail[] supplementaryContent: LinkedBibDetail - extent: BibDetail + extent: string[] subjectHeadings: SubjectHeadingDetail - owner: JSONLDValue + owner: string[] constructor( discoveryBibResult: DiscoveryBibResult, @@ -46,14 +45,15 @@ export default class BibDetails { this.bottomDetails = this.buildBottomDetails() } - buildOwner(): string { + buildOwner(): string[] { if (!this.bib.items) return null const firstRecapItem = this.bib.items // Only consider items with a Recap source id .find((item) => /^Recap/.test(item?.idNyplSourceId?.["@type"])) // Only consider items with an `owner` (should be all, in practice) - return firstRecapItem?.owner?.[0]?.prefLabel + const owner = firstRecapItem?.owner?.[0]?.prefLabel + if (owner) return [owner] } buildAnnotatedMarcDetails( @@ -101,11 +101,16 @@ export default class BibDetails { { field: "creatorLiteral", label: "Author" }, ] .map((fieldMapping) => { - if (fieldMapping.field === "supplementaryContent") - return this.supplementaryContent - else if (fieldMapping.field === "creatorLiteral") - return this.buildInternalLinkedDetail(fieldMapping) - else return this.buildStandardDetail(fieldMapping) + switch (fieldMapping.field) { + case "supplementaryContent": + return this.supplementaryContent + case "creatorLiteral": + return this.buildInternalLinkedDetail(fieldMapping) + case "owner": + return this.owner + default: + return this.buildStandardDetail(fieldMapping) + } }) .filter((f) => f) } @@ -137,12 +142,10 @@ export default class BibDetails { detail = this.buildInternalLinkedDetail(fieldMapping) else if (fieldMapping.field === "subjectLiteral") detail = this.subjectHeadings - else if (fieldMapping.field === "extent") detail = this.extent else detail = this.buildStandardDetail(fieldMapping) return detail }) .filter((f) => f) - const fieldsWithNotes = this.addNotes(resourceFields) const combinedFields = this.combineBibDetailsData( fieldsWithNotes, @@ -182,7 +185,9 @@ export default class BibDetails { } buildStandardDetail(fieldMapping: FieldMapping) { - const bibFieldValue = this.bib[fieldMapping.field] + const bibFieldValue = + this.bib[fieldMapping.field] || this[fieldMapping.field] + if (!bibFieldValue) return return this.buildDetail( convertToSentenceCase(fieldMapping.label), bibFieldValue @@ -334,7 +339,7 @@ export default class BibDetails { return Object.assign({}, bib, ...parallelFieldMatches) } - buildExtent(): BibDetail { + buildExtent(): string[] { let modifiedExtent: string[] const { extent, dimensions } = this.bib const removeSemiColon = (extent) => [extent[0].replace(/\s*;\s*$/, "")] @@ -350,10 +355,8 @@ export default class BibDetails { parts.push(dimensions[0]) modifiedExtent = [parts.join("; ")] } - return { - label: "Description", - value: modifiedExtent, - } + + return modifiedExtent } buildSupplementaryContent(): LinkedBibDetail { diff --git a/src/models/modelTests/BibDetails.test.ts b/src/models/modelTests/BibDetails.test.ts index bfd568da4..699bdc58a 100644 --- a/src/models/modelTests/BibDetails.test.ts +++ b/src/models/modelTests/BibDetails.test.ts @@ -33,10 +33,10 @@ describe("Bib model", () => { bibWithSubjectHeadings.resource, bibWithSubjectHeadings.annotatedMarc ) - describe.only("owner", () => { + describe("owner", () => { it("populates owner when owner is present", () => { const partnerBib = new BibDetailsModel(princetonRecord) - expect(partnerBib.owner).toBe("Princeton University Library") + expect(partnerBib.owner).toStrictEqual(["Princeton University Library"]) }) it("does not populate owner if item is nypl", () => { expect(bibWithRtlParallelsModel.owner).toBe(undefined) @@ -166,14 +166,14 @@ describe("Bib model", () => { ) }) }) - describe("extent", () => { + xdescribe("extent", () => { it("should add a semicolon after extent if there is not one already", () => { const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }], extent: ["99 bottles of beer"], dimensions: ["99 x 99 cm"], }) - expect(bib.extent.value[0].includes("; ")) + expect(bib.extent[0].includes("; ")) }) it("should append dimensions to extent", () => { const bib = new BibDetailsModel({ @@ -181,7 +181,7 @@ describe("Bib model", () => { extent: ["99 bottles of beer"], dimensions: ["99 x 99 cm"], }) - expect(bib.extent.value[0]).toBe("99 bottles of beer; 99 x 99 cm") + expect(bib.extent[0]).toBe("99 bottles of beer; 99 x 99 cm") }) it("should not add semicolon if it already is in extent", () => { const bib = new BibDetailsModel({ @@ -189,7 +189,7 @@ describe("Bib model", () => { extent: ["700 sheets of woven gold; "], dimensions: ["1 x 1 in."], }) - expect(bib.extent.value[0]).toBe("700 sheets of woven gold; 1 x 1 in.") + expect(bib.extent[0]).toBe("700 sheets of woven gold; 1 x 1 in.") }) it("should remove semicolon if there is no dimensions", () => { const bib = new BibDetailsModel({ @@ -200,15 +200,15 @@ describe("Bib model", () => { identifier: [{ uri: "123456" }], extent: ["700 sheets of woven gold;"], }) - expect(bib.extent.value[0]).toBe("700 sheets of woven gold") - expect(anotherBib.extent.value[0]).toBe("700 sheets of woven gold") + expect(bib.extent[0]).toBe("700 sheets of woven gold") + expect(anotherBib.extent[0]).toBe("700 sheets of woven gold") }) it("should display dimensions if there are dimensions and no extent", () => { const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }], dimensions: ["1,000,000mm x 7ft"], }) - expect(bib.extent.value[0]).toBe("1,000,000mm x 7ft") + expect(bib.extent[0]).toBe("1,000,000mm x 7ft") }) it("should do nothing if there are no dimensions or extent", () => { const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }] })