Skip to content

Commit

Permalink
Use backup data for showing reservations that don't have proper PID
Browse files Browse the repository at this point in the history
We utilize the ilBibliographicRecord prop on the Reservation type
  • Loading branch information
Adamik10 committed Jun 25, 2024
1 parent 27675fd commit b4c67af
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import ArrowButton from "../../../../components/Buttons/ArrowButton";
import { isDigital } from "../../utils/helpers";
import { listId, ListType } from "../../../../core/utils/types/list-type";
import SelectableMaterialSkeleton from "./selectable-material-skeleton";
import { ILLBibliographicRecord } from "../../../../core/fbs/model";

interface SelectableMaterialProps {
identifier?: string | null;
ilBibliographicRecord?: ILLBibliographicRecord;
disabled?: boolean;
item?: ListType;
onMaterialChecked?: (listItem: ListType) => void;
Expand All @@ -32,6 +34,7 @@ interface SelectableMaterialProps {

const SelectableMaterial: FC<SelectableMaterialProps & MaterialProps> = ({
material,
ilBibliographicRecord,
disabled,
onMaterialChecked,
selected,
Expand All @@ -48,14 +51,24 @@ const SelectableMaterial: FC<SelectableMaterialProps & MaterialProps> = ({
const t = useText();

if (!item) return null;
const {
let {
authorsShort = "",
materialType,
year = "",
title = "",
lang
} = material || {};

// There is a chance material isn't provided, if corresponding reservation PID is
// incorrect (that's unfortunately possible). Then we use ilBibliographicRecord data.
if (!material) {
authorsShort = ilBibliographicRecord?.author || "";
materialType = "";
year = ilBibliographicRecord?.publicationDate || "";
title = ilBibliographicRecord?.title || "";
lang = ilBibliographicRecord?.language || "";
}

// The reason why the handlers are used on multiple containers is because of multiple reasons:
// * We cannot attach them to the li or the list-materials container because it prevents the checkbox from being checked.
// * We cannot make a container for the rest of the content with the handlers because it breaks the flexbox layout.
Expand Down Expand Up @@ -110,9 +123,14 @@ const SelectableMaterial: FC<SelectableMaterialProps & MaterialProps> = ({
tabIndex={0}
>
<div className="list-materials__content-status">
<div className="status-label status-label--outline ">
{materialType}
</div>
{materialType && materialType !== "" && (
<div className="status-label status-label--outline ">
{materialType}
</div>
)}
{(!materialType || materialType === "") && (
<span className="mt-8" />
)}
</div>
{statusBadgeComponentMobile || null}
<p className="list-materials__content__header mt-8" lang={lang || ""}>
Expand Down
8 changes: 6 additions & 2 deletions src/apps/loan-list/materials/utils/material-fetch-hoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { Product } from "../../../../core/publizon/model";
import { BasicDetailsType } from "../../../../core/utils/types/basic-details-type";
import { mapManifestationToBasicDetailsType } from "../../../../core/utils/helpers/list-mapper";
import { ListType } from "../../../../core/utils/types/list-type";
import { ILLBibliographicRecord } from "../../../../core/fbs/model";

export interface MaterialProps {
material?: BasicDetailsType | null;
}

type InputProps = {
ilBibliographicRecord?: ILLBibliographicRecord;
digitalMaterial?: Product | null;
item?: ListType;
};
Expand Down Expand Up @@ -72,15 +74,17 @@ const fetchMaterial =
return FallbackComponent ? <FallbackComponent /> : null;
}

// in cases where the material is not found we return null, else we would load forever
if (!manifestation) return null;
// In cases where the material is not found AND we don't have fallback data
// we return null, else we would load forever.
if (!manifestation && !props.ilBibliographicRecord) return null;

return (
<Component
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...(props as P)}
item={item}
material={material}
ilBibliographicRecord={props.ilBibliographicRecord}
/>
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/GroupModal/GroupModalReservationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import StatusBadge from "../../apps/loan-list/materials/utils/status-badge";
import { ListType } from "../../core/utils/types/list-type";
import { getStatusText } from "../../apps/reservation-list/utils/helpers";
import { ILLBibliographicRecord } from "../../core/fbs/model";

export interface GroupModalReservationsListProps {
materials: ReservationType[];
Expand Down Expand Up @@ -75,9 +76,7 @@ const GroupModalReservationsList: FC<GroupModalReservationsListProps> = ({
const selected = selectedMaterials?.some((selectedMaterial) =>
isEqual(selectedMaterial, material)
);

const statusText: string = getStatusText(material, t);

const statusBadgeComponent = statusText ? (
<StatusBadge
badgeDate={expiryDate}
Expand All @@ -100,6 +99,11 @@ const GroupModalReservationsList: FC<GroupModalReservationsListProps> = ({
disabled={false}
statusMessageComponentMobile={null}
statusMessageComponentDesktop={null}
// material.ilBibliographicRecord is of the ILLBibliographicRecord type,
// we just make it nullable in the code defining ReservationType.
ilBibliographicRecord={
material.ilBibliographicRecord as ILLBibliographicRecord
}
/>
)
);
Expand Down

0 comments on commit b4c67af

Please sign in to comment.