Skip to content

Commit

Permalink
Merge pull request #1072 from danskernesdigitalebibliotek/fix/availab…
Browse files Browse the repository at this point in the history
…ility-blacklisting

Fix/availability blacklisting
  • Loading branch information
Adamik10 authored Apr 8, 2024
2 parents 76db22f + 90d9862 commit e6d5cfa
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
29 changes: 21 additions & 8 deletions src/apps/material/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,19 +411,29 @@ export const isParallelReservation = (manifestations: Manifestation[]) =>
hasCorrectAccessType(AccessTypeCode.Physical, manifestations) &&
!isArticle(manifestations);

// Because we need to exclude the branches that are blacklisted, we need to use a custom hook to prevent duplicate code
// Because we need to exclude the branches that are blacklisted, we need to
// use a custom hook to prevent duplicate code
export const getBlacklistedQueryArgs = (
faustIds: FaustId[],
config: UseConfigFunction,
blacklist: "availability" | "pickup"
blacklist: "availability" | "pickup" | "both"
) => {
const configKey =
blacklist === "availability"
? "blacklistedAvailabilityBranchesConfig"
: "blacklistedPickupBranchesConfig";
const blacklistBranches = config(configKey, {
const configKey = {
availability: "blacklistedAvailabilityBranchesConfig",
pickup: "blacklistedPickupBranchesConfig",
both: "blacklistedAvailabilityBranchesConfig"
};
let blacklistBranches = config(configKey[blacklist], {
transformer: "stringToArray"
});
// If we want to blacklist both availability and pickup branches we now add the
// complimentary blacklist
if (blacklist === "both") {
const additionalBlacklistBranches = config(configKey.pickup, {
transformer: "stringToArray"
});
blacklistBranches = blacklistBranches.concat(additionalBlacklistBranches);
}
return {
recordid: faustIds,
...(blacklistBranches ? { exclude: blacklistBranches } : {})
Expand All @@ -442,16 +452,19 @@ export const getAvailability = async ({
export const useGetHoldings = ({
faustIds,
config,
useAvailabilityBlacklist = false,
options
}: {
faustIds: FaustId[];
config: UseConfigFunction;
useAvailabilityBlacklist?: boolean;
options?: {
query?: UseQueryOptions<Awaited<ReturnType<typeof getHoldingsV3>>>;
};
}) => {
const blacklistedBranches = useAvailabilityBlacklist ? "both" : "pickup";
const { data, isLoading, isError } = useGetHoldingsV3(
getBlacklistedQueryArgs(faustIds, config, "pickup"),
getBlacklistedQueryArgs(faustIds, config, blacklistedBranches),
options
);
return { data, isLoading, isError };
Expand Down
22 changes: 20 additions & 2 deletions src/components/find-on-shelf/FindOnShelfModalBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const FindOnShelfModalBody: FC<FindOnShelfModalBodyProps> = ({
);
const { data, isLoading } = useGetHoldings({
faustIds: faustIdArray,
useAvailabilityBlacklist: true,
config
});
const author = creatorsToString(flattenCreators(authors), t);
Expand Down Expand Up @@ -145,7 +146,7 @@ const FindOnShelfModalBody: FC<FindOnShelfModalBodyProps> = ({
}
)
);
// "00" is the ending of beanchIds for branches that are considered main & should
// "00" is the ending of branchIds for branches that are considered main & should
// be shown first independent of whether they're available.
const finalDataMainBranchFirst = finalDataAlphabetical.sort(
(manifestationHolding: ManifestationHoldings) => {
Expand All @@ -154,7 +155,24 @@ const FindOnShelfModalBody: FC<FindOnShelfModalBodyProps> = ({
: 1;
}
);
const finalDataToShow: ManifestationHoldings[] = finalDataMainBranchFirst;
// Due to the way the data is structured and that we need to assemble it from
// two different sources, we need to filter out branches that are blacklisted
// even though this already happened once when fetching one half of the data.
const finalDataFilterOutBlacklistedBranches = finalDataMainBranchFirst.filter(
(libraryBranch: ManifestationHoldings) => {
const blacklistedBranches = config(
"blacklistedAvailabilityBranchesConfig",
{
transformer: "stringToArray"
}
);
return !blacklistedBranches.includes(
libraryBranch[0].holding.branch.branchId
);
}
);
const finalDataToShow: ManifestationHoldings[] =
finalDataFilterOutBlacklistedBranches;

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/material/MaterialHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const MaterialHeader: React.FC<MaterialHeaderProps> = ({
/>
)}
</div>
{/* The CTA nuttons apperently only makes sense on a global work */}
{/* The CTA buttons apparently only make sense on a global work */}
{!isGlobalMaterial && showItem && (
<>
{isPeriodical && (
Expand Down
1 change: 1 addition & 0 deletions src/core/utils/useReservableFromAnotherLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const useReservableFromAnotherLibrary = (
const config = useConfig();
const { data: holdingsData } = useGetHoldings({
faustIds: getAllFaustIds(manifestations),
useAvailabilityBlacklist: true,
config
});

Expand Down

0 comments on commit e6d5cfa

Please sign in to comment.