From 821f23b03c8f47a493183d1df986fb38ea090370 Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Wed, 8 Nov 2023 14:51:20 +0100 Subject: [PATCH] Move logic for display `MaterialButtonReservableFromAnotherLibrary` If the material only can be reserved on another library, we don't want to show other buttons like `MaterialButtonFindOnShelf` --- .../material-buttons/MaterialButtons.tsx | 21 ++++++++++++++++++- .../physical/MaterialButtonsPhysical.tsx | 16 +------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/components/material/material-buttons/MaterialButtons.tsx b/src/components/material/material-buttons/MaterialButtons.tsx index 2e4ca08645..ceef3e5ffc 100644 --- a/src/components/material/material-buttons/MaterialButtons.tsx +++ b/src/components/material/material-buttons/MaterialButtons.tsx @@ -1,7 +1,11 @@ import * as React from "react"; import { FC } from "react"; import { AccessTypeCode } from "../../../core/dbc-gateway/generated/graphql"; -import { getAllFaustIds } from "../../../core/utils/helpers/general"; +import { + getAllFaustIds, + getManifestationType, + getReservablePidsFromAnotherLibrary +} from "../../../core/utils/helpers/general"; import { ButtonSize } from "../../../core/utils/types/button"; import { Manifestation } from "../../../core/utils/types/entities"; import { hasCorrectAccess, hasCorrectAccessType, isArticle } from "./helper"; @@ -9,6 +13,7 @@ import { WorkId } from "../../../core/utils/types/ids"; import MaterialButtonsOnline from "./online/MaterialButtonsOnline"; import MaterialButtonsFindOnShelf from "./physical/MaterialButtonsFindOnShelf"; import MaterialButtonsPhysical from "./physical/MaterialButtonsPhysical"; +import MaterialButtonReservableFromAnotherLibrary from "./physical/MaterialButtonReservableFromAnotherLibrary"; export interface MaterialButtonsProps { manifestations: Manifestation[]; @@ -29,6 +34,20 @@ const MaterialButtons: FC = ({ // We don't want to show physical buttons/find on shelf for articles because // articles appear as a part of journal/periodical publications and can't be // physically loaned for themseleves. + + const isReservableFromAnotherLibrary = + getReservablePidsFromAnotherLibrary(manifestations).length > 0; + + if (isReservableFromAnotherLibrary) { + return ( + + ); + } + return ( <> {hasCorrectAccessType(AccessTypeCode.Physical, manifestations) && diff --git a/src/components/material/material-buttons/physical/MaterialButtonsPhysical.tsx b/src/components/material/material-buttons/physical/MaterialButtonsPhysical.tsx index f673ca2f6b..bdfec68f0f 100644 --- a/src/components/material/material-buttons/physical/MaterialButtonsPhysical.tsx +++ b/src/components/material/material-buttons/physical/MaterialButtonsPhysical.tsx @@ -1,8 +1,7 @@ import React from "react"; import { getAllFaustIds, - getManifestationType, - getReservablePidsFromAnotherLibrary + getManifestationType } from "../../../../core/utils/helpers/general"; import { isBlocked, usePatronData } from "../../../../core/utils/helpers/user"; import { ButtonSize } from "../../../../core/utils/types/button"; @@ -13,7 +12,6 @@ import MaterialButtonReservePhysical from "./MaterialButtonPhysical"; import MaterialButtonLoading from "../generic/MaterialButtonLoading"; import MaterialButtonDisabled from "../generic/MaterialButtonDisabled"; import { useText } from "../../../../core/utils/text"; -import MaterialButtonReservableFromAnotherLibrary from "./MaterialButtonReservableFromAnotherLibrary"; export interface MaterialButtonsPhysicalProps { manifestations: Manifestation[]; @@ -26,8 +24,6 @@ const MaterialButtonsPhysical: React.FC = ({ size, dataCy = "material-buttons-physical" }) => { - const isReservableFromAnotherLibrary = - getReservablePidsFromAnotherLibrary(manifestations); const t = useText(); const faustIds = getAllFaustIds(manifestations); const { reservableManifestations } = UseReservableManifestations({ @@ -48,16 +44,6 @@ const MaterialButtonsPhysical: React.FC = ({ return ; } - if (isReservableFromAnotherLibrary.length > 0) { - return ( - - ); - } - // We show the reservation button if the user isn't logged in or isn't blocked. // In the former case there there's no way to see if they're blocked, so we // redirect anonymous user to the login page.