Skip to content

Commit

Permalink
rename subjectheading and return only values
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Dec 2, 2024
1 parent 155e423 commit 16a38e5
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 101 deletions.
25 changes: 8 additions & 17 deletions src/models/BibDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class BibDetails {
groupedNotes: AnyBibDetail[]
supplementaryContent: LinkedBibDetail
extent: string[]
subjectHeadings: SubjectHeadingDetail
subjectLiteral: BibDetailURL[][]
owner: string[]

constructor(
Expand All @@ -34,7 +34,7 @@ export default class BibDetails {
this.extent = this.buildExtent()
this.owner = this.buildOwner()
// If we can't retreive subject headings from the SHEP API, we'll use the subjectLiteral
this.subjectHeadings =
this.subjectLiteral =
this.buildSubjectHeadings() || this.buildSubjectLiterals()
// these are the actual arrays of details that will be displayed
this.annotatedMarcDetails = this.buildAnnotatedMarcDetails(
Expand Down Expand Up @@ -136,11 +136,10 @@ export default class BibDetails {
]
.map((fieldMapping: FieldMapping): AnyBibDetail => {
let detail: AnyBibDetail
// TODO: standardize detail building by returning array of strings from all instance variables, so the detail can be returned from buildStandardDetail. That way, we won't be maintaining two different locations for labels.
if (fieldMapping.field === "contributorLiteral")
detail = this.buildInternalLinkedDetail(fieldMapping)
else if (fieldMapping.field === "subjectLiteral")
detail = this.subjectHeadings
// else if (fieldMapping.field === "subjectLiteral")
// detail = this.subjectHeadings
else detail = this.buildStandardDetail(fieldMapping)
return detail
})
Expand Down Expand Up @@ -376,21 +375,16 @@ export default class BibDetails {
return this.buildExternalLinkedDetail(convertToSentenceCase(label), values)
}

buildSubjectHeadings(): SubjectHeadingDetail {
buildSubjectHeadings(): BibDetailURL[][] {
if (!this.bib.subjectHeadings) return
const subjectHeadingsUrls = this.bib.subjectHeadings.map((heading) =>
this.flattenSubjectHeadingUrls(heading)
)

return (
subjectHeadingsUrls?.length && {
label: "Subject",
value: subjectHeadingsUrls,
}
)
return subjectHeadingsUrls?.length && subjectHeadingsUrls
}

buildSubjectLiterals(): SubjectHeadingDetail {
buildSubjectLiterals(): BibDetailURL[][] {
if (!this.bib.subjectLiteral) return
const subjectLiteralUrls = this.bib.subjectLiteral.map(
(subject: string) => {
Expand All @@ -412,10 +406,7 @@ export default class BibDetails {
})
}
)
return {
label: "Subject",
value: subjectLiteralUrls,
}
return subjectLiteralUrls
}

constructSubjectLiteralsArray(subject: string) {
Expand Down
162 changes: 78 additions & 84 deletions src/models/modelTests/BibDetails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,96 +73,90 @@ describe("Bib model", () => {
})
describe("subjectHeadings", () => {
it("correctly formats the subjectHeading urls when the subjectHeadings are present in the bib result", () => {
const subjectHeadingsObject = {
label: "Subject",
value: [
[
{
url: "/subject_headings/cf347108-e1f2-4c0f-808a-ac4ace2f0765?label=Cortanze%2C%20G%C3%A9rard%20de",
urlLabel: "Cortanze, Gérard de",
},
{
url: "/subject_headings/74746d11-638b-4cfb-a72a-9a2bd296e6fd?label=Cortanze%2C%20G%C3%A9rard%20de%20--%20Childhood%20and%20youth",
urlLabel: "Childhood and youth",
},
],
[
{
url: "/subject_headings/5fd065df-b4e9-48cb-b13c-ea15f36b96b4?label=Authors%2C%20French",
urlLabel: "Authors, French",
},
{
url: "/subject_headings/e43674a7-5f02-44f1-95cd-dbcc776331b7?label=Authors%2C%20French%20--%2020th%20century",
urlLabel: "20th century",
},
{
url: "/subject_headings/9391bc26-e44c-44ac-98cc-e3800da51926?label=Authors%2C%20French%20--%2020th%20century%20--%20Biography",
urlLabel: "Biography",
},
],
[
{
url: "/subject_headings/3a779ed6-8a07-4d27-80ef-e0c2b10fe78e?label=Autobiographical%20Narrative",
urlLabel: "Autobiographical Narrative",
},
],
const subjectHeadings = [
[
{
url: "/subject_headings/cf347108-e1f2-4c0f-808a-ac4ace2f0765?label=Cortanze%2C%20G%C3%A9rard%20de",
urlLabel: "Cortanze, Gérard de",
},
{
url: "/subject_headings/74746d11-638b-4cfb-a72a-9a2bd296e6fd?label=Cortanze%2C%20G%C3%A9rard%20de%20--%20Childhood%20and%20youth",
urlLabel: "Childhood and youth",
},
],
[
{
url: "/subject_headings/5fd065df-b4e9-48cb-b13c-ea15f36b96b4?label=Authors%2C%20French",
urlLabel: "Authors, French",
},
{
url: "/subject_headings/e43674a7-5f02-44f1-95cd-dbcc776331b7?label=Authors%2C%20French%20--%2020th%20century",
urlLabel: "20th century",
},
{
url: "/subject_headings/9391bc26-e44c-44ac-98cc-e3800da51926?label=Authors%2C%20French%20--%2020th%20century%20--%20Biography",
urlLabel: "Biography",
},
],
[
{
url: "/subject_headings/3a779ed6-8a07-4d27-80ef-e0c2b10fe78e?label=Autobiographical%20Narrative",
urlLabel: "Autobiographical Narrative",
},
],
}
expect(bibWithSubjectHeadingsModel.subjectHeadings).toMatchObject(
subjectHeadingsObject
]
expect(bibWithSubjectHeadingsModel.subjectLiteral).toStrictEqual(
subjectHeadings
)
})
it("falls back to subject literals when subject headings are absent in the bib and correctly formats the urls", () => {
const filterQueryForSubjectLiteral = "/search?filters[subjectLiteral]="
const subjectHeadingsObject = {
label: "Subject",
value: [
[
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Authors, French"
)}`,
urlLabel: "Authors, French",
},
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Authors, French -- 20th century"
)}`,
urlLabel: "20th century",
},
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Authors, French -- 20th century -- Biography"
)}`,
urlLabel: "Biography",
},
],
[
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Autobiographical Narrative"
)}`,
urlLabel: "Autobiographical Narrative",
},
],
[
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Cortanze, Gérard de"
)}`,
urlLabel: "Cortanze, Gérard de",
},
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Cortanze, Gérard de -- Childhood and youth"
)}`,
urlLabel: "Childhood and youth",
},
],
const subjectHeadings = [
[
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Authors, French"
)}`,
urlLabel: "Authors, French",
},
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Authors, French -- 20th century"
)}`,
urlLabel: "20th century",
},
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Authors, French -- 20th century -- Biography"
)}`,
urlLabel: "Biography",
},
],
[
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Autobiographical Narrative"
)}`,
urlLabel: "Autobiographical Narrative",
},
],
[
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Cortanze, Gérard de"
)}`,
urlLabel: "Cortanze, Gérard de",
},
{
url: `${filterQueryForSubjectLiteral}${encodeURI(
"Cortanze, Gérard de -- Childhood and youth"
)}`,
urlLabel: "Childhood and youth",
},
],
}
expect(bibWithNoParallelsModel.subjectHeadings).toMatchObject(
subjectHeadingsObject
]
expect(bibWithNoParallelsModel.subjectLiteral).toStrictEqual(
subjectHeadings
)
})
})
Expand Down

0 comments on commit 16a38e5

Please sign in to comment.