diff --git a/src/components/availability-label/helper.ts b/src/components/availability-label/helper.ts index e9e3cb06ce..420dca62d3 100644 --- a/src/components/availability-label/helper.ts +++ b/src/components/availability-label/helper.ts @@ -1,5 +1,6 @@ import clsx from "clsx"; import { AccessTypeCode } from "../../core/dbc-gateway/generated/graphql"; +import articleTypes from "../../core/utils/types/article-types"; type GetParrentAvailabilityLabelClassProps = { selected?: boolean; @@ -9,6 +10,9 @@ type GetParrentAvailabilityLabelClassProps = { export const isOnline = (accessTypes: AccessTypeCode[]): boolean => accessTypes?.includes(AccessTypeCode.Online) ?? false; +export const isArticle = (manifestText: string): boolean => + articleTypes.some((type) => manifestText.toLowerCase() === type); + export const getParentAvailabilityLabelClass = ({ selected, cursorPointer diff --git a/src/components/availability-label/usePhysicalAvailabilityData.ts b/src/components/availability-label/usePhysicalAvailabilityData.ts index abc9e7d98b..4244945e8d 100644 --- a/src/components/availability-label/usePhysicalAvailabilityData.ts +++ b/src/components/availability-label/usePhysicalAvailabilityData.ts @@ -1,7 +1,7 @@ import { useConfig } from "../../core/utils/config"; import { FaustId } from "../../core/utils/types/ids"; import useGetAvailability from "../../core/utils/useGetAvailability"; -import { ManifestationMaterialType } from "../../core/utils/types/material-type"; +import { isArticle } from "./helper"; const usePhysicalAvailabilityData = ({ enabled, @@ -22,10 +22,7 @@ const usePhysicalAvailabilityData = ({ // FBS / useGetAvailabilityV3 is responsible for handling availability // for physical items. This will be the majority of all materials so we // use this for everything except materials that are explicitly online. - enabled: - enabled && - faustIds !== null && - manifestText !== ManifestationMaterialType.article + enabled: enabled && faustIds !== null && !isArticle(manifestText) } } }); @@ -41,7 +38,7 @@ const usePhysicalAvailabilityData = ({ } // Articles are always available. - if (manifestText === ManifestationMaterialType.article) { + if (isArticle(manifestText)) { return { isLoading: false, isAvailable: true diff --git a/src/components/material/material-buttons/helper.ts b/src/components/material/material-buttons/helper.ts index a13d8b2a0a..866799e2b8 100644 --- a/src/components/material/material-buttons/helper.ts +++ b/src/components/material/material-buttons/helper.ts @@ -4,7 +4,7 @@ import { AccessTypeCode } from "../../../core/dbc-gateway/generated/graphql"; import { Manifestation } from "../../../core/utils/types/entities"; -import { ManifestationMaterialType } from "../../../core/utils/types/material-type"; +import articleTypes from "../../../core/utils/types/article-types"; export const hasCorrectAccess = ( desiredAccess: NonNullable, @@ -57,9 +57,8 @@ export const hasCorrectPartialMaterialType = ( }; export const isArticle = (manifestations: Manifestation[]) => { - return hasCorrectPartialMaterialType( - ManifestationMaterialType.article, - manifestations + return articleTypes.every((type) => + hasCorrectMaterialType(type, manifestations) ); }; diff --git a/src/core/utils/types/article-types.ts b/src/core/utils/types/article-types.ts new file mode 100644 index 0000000000..bd679466c5 --- /dev/null +++ b/src/core/utils/types/article-types.ts @@ -0,0 +1,10 @@ +import { ManifestationMaterialType } from "./material-type"; + +const articleTypes = [ + ManifestationMaterialType.article, + ManifestationMaterialType.paperArticle, + ManifestationMaterialType.onlineArticle, + ManifestationMaterialType.earticle +] as const; + +export default articleTypes;