Skip to content

Commit

Permalink
overriden: DocumentItemBody: Render call number for blank shelf
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 committed Jul 10, 2024
1 parent 471f240 commit c53be09
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
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 callNumberComponent = <> {callNumber}</>;
if (_isEmpty(shelfNumber) || shelfNumber === "") {
// If shelfNumber is empty, show info popup regardless of availability
callNumberComponent = (
<InfoPopup message="Please request online or ask at the Library desk.">
{" "}
{callNumber}
</InfoPopup>
);
}

const itemShelf =
cannotCirculate && itemOnShelf
? shelfNumber
: shelfLinkComponent(shelfNumber, title, callNumber);
return itemShelf;
canCirculateItem && itemIsOnShelf && !_isEmpty(shelfNumber) && shelfNumber !== ""
? shelfLinkComponent(shelfNumber, title, callNumber)
: shelfNumber;

return (
<>
{itemShelf}
{callNumberComponent}
</>
);
}

export const DocumentItemBodyTable = parametrize(DocumentItemBody, {
Expand Down
19 changes: 6 additions & 13 deletions ui/src/overridden/utils.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -47,18 +47,11 @@ export const shelfLinkComponent = (
const linkToShelf = shelfLink(shelfNumber, {
popupContent: { "Title": title, "Call number": callNumber },
});
return shelfNumber ? (
<>
<a href={linkToShelf} target="_blank" rel="noreferrer">
<Icon name={iconName} />
{shelfNumber}
</a>{" "}
{callNumber}
</>
) : (
<InfoPopup message="Please request online or ask at the Library desk.">
{callNumber}
</InfoPopup>
return (
<a href={linkToShelf} target="_blank" rel="noreferrer">
<Icon name={iconName} />
{shelfNumber}
</a>
);
};

Expand Down

0 comments on commit c53be09

Please sign in to comment.