Skip to content

Commit

Permalink
Expand isArticle functionality globally with "new" types
Browse files Browse the repository at this point in the history
Since we have multiple article types we should consider those in the
various places where we have functionality relying on those types.
  • Loading branch information
spaceo committed Aug 3, 2024
1 parent 5c39ba1 commit 9ed98b6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/components/availability-label/helper.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
}
}
});
Expand All @@ -41,7 +38,7 @@ const usePhysicalAvailabilityData = ({
}

// Articles are always available.
if (manifestText === ManifestationMaterialType.article) {
if (isArticle(manifestText)) {
return {
isLoading: false,
isAvailable: true
Expand Down
7 changes: 3 additions & 4 deletions src/components/material/material-buttons/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Access["__typename"]>,
Expand Down Expand Up @@ -57,9 +57,8 @@ export const hasCorrectPartialMaterialType = (
};

export const isArticle = (manifestations: Manifestation[]) => {
return hasCorrectPartialMaterialType(
ManifestationMaterialType.article,
manifestations
return articleTypes.every((type) =>
hasCorrectMaterialType(type, manifestations)
);
};

Expand Down
10 changes: 10 additions & 0 deletions src/core/utils/types/article-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ManifestationMaterialType } from "./material-type";

const articleTypes = [
ManifestationMaterialType.article,
ManifestationMaterialType.paperArticle,
ManifestationMaterialType.onlineArticle,
ManifestationMaterialType.earticle
] as const;

export default articleTypes;

0 comments on commit 9ed98b6

Please sign in to comment.