Skip to content

Commit

Permalink
Add getManifestationLanguageIsoCode helper function to retrieve uniqu…
Browse files Browse the repository at this point in the history
…e language ISO codes
  • Loading branch information
Adamik10 committed Dec 3, 2024
1 parent e644480 commit a8a846e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions components/pages/workPageLayout/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { head, uniqBy } from "lodash"

import {
GeneralMaterialTypeCodeEnum,
IdentifierTypeEnum,
Expand Down Expand Up @@ -74,3 +76,21 @@ export const getIsbnsFromManifestation = (
if (!manifestaion) return []
return manifestaion.identifiers.filter(identifier => identifier.type === IdentifierTypeEnum.Isbn)
}

export const getManifestationLanguageIsoCode = (
manifestation: ManifestationWorkPageFragment | undefined | null
) => {
if (!manifestation) return undefined

const uniqueLanguagesWithIsoCode = uniqBy(manifestation.languages?.main, "isoCode")

// We only want to set the lang attribute if there is only one isoCode
const uniqIsoCode =
uniqueLanguagesWithIsoCode.length === 1 && head(uniqueLanguagesWithIsoCode)?.isoCode

if (uniqIsoCode) {
return uniqIsoCode
}
// if there is no isoCode it return undefined so that the lang attribute is not set
return undefined
}

0 comments on commit a8a846e

Please sign in to comment.