From 62eec37a1d872288bec616b5e568ff359eeadcd8 Mon Sep 17 00:00:00 2001 From: Saksham Arora Date: Wed, 10 Jul 2024 17:37:03 +0200 Subject: [PATCH] overriden: DocumentItemBody: Render call number for blank shelf --- .../DocumentDetails/DocumentItemBody.js | 36 ++++++++++++++----- ui/src/overridden/utils.js | 19 ++++------ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ui/src/overridden/frontsite/Document/DocumentDetails/DocumentItemBody.js b/ui/src/overridden/frontsite/Document/DocumentDetails/DocumentItemBody.js index 13ceb6ed..8008491a 100644 --- a/ui/src/overridden/frontsite/Document/DocumentDetails/DocumentItemBody.js +++ b/ui/src/overridden/frontsite/Document/DocumentDetails/DocumentItemBody.js @@ -1,30 +1,48 @@ +import React from "react"; import { DocumentItemBody, invenioConfig, + InfoPopup, } from "@inveniosoftware/react-invenio-app-ils"; import _get from "lodash/get"; +import _isEmpty from "lodash/isEmpty"; import { parametrize } from "react-overridable"; import { renderCallNumber, shelfLinkComponent } from "../../../utils"; function renderShelflink(item, documentDetails) { const itemStatus = _get(item, "circulation.state"); - // If item is on loan, don't hyperlink the shelf - const cannotCirculate = - invenioConfig.CIRCULATION.loanActiveStates.includes(itemStatus); - const itemOnShelf = ["CAN_CIRCULATE", "FOR_REFERENCE_ONLY"].includes( + // If item is not on loan, hyperlink the shelf + const canCirculateItem = + !invenioConfig.CIRCULATION.loanActiveStates.includes(itemStatus); + const itemIsOnShelf = ["CAN_CIRCULATE", "FOR_REFERENCE_ONLY"].includes( _get(item, "status") ); const shelfNumber = _get(item, "shelf"); const title = _get(documentDetails, "metadata.title"); - const callNumber = renderCallNumber(item); + var callNumber = renderCallNumber(item); const itemShelf = - cannotCirculate && itemOnShelf - ? shelfNumber - : shelfLinkComponent(shelfNumber, title, callNumber); - return itemShelf; + canCirculateItem && itemIsOnShelf && !_isEmpty(shelfNumber) + ? shelfLinkComponent(shelfNumber, title, callNumber) + : shelfNumber; + + if (_isEmpty(shelfNumber)) { + // If shelfNumber is empty, show info popup regardless of availability + callNumber = ( + + {" "} + {callNumber} + + ); + } + + return ( + <> + {itemShelf} {callNumber} + + ); } export const DocumentItemBodyTable = parametrize(DocumentItemBody, { diff --git a/ui/src/overridden/utils.js b/ui/src/overridden/utils.js index 5126e74a..31a8b223 100644 --- a/ui/src/overridden/utils.js +++ b/ui/src/overridden/utils.js @@ -1,5 +1,5 @@ import React from "react"; -import { InfoPopup, invenioConfig } from "@inveniosoftware/react-invenio-app-ils"; +import { invenioConfig } from "@inveniosoftware/react-invenio-app-ils"; import { Icon } from "semantic-ui-react"; import _get from "lodash/get"; @@ -47,18 +47,11 @@ export const shelfLinkComponent = ( const linkToShelf = shelfLink(shelfNumber, { popupContent: { "Title": title, "Call number": callNumber }, }); - return shelfNumber ? ( - <> - - - {shelfNumber} - {" "} - {callNumber} - - ) : ( - - {callNumber} - + return ( + + + {shelfNumber} + ); };