Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/availability blacklisting #1072

Merged
merged 9 commits into from
Apr 8, 2024
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
Adamik10 marked this conversation as resolved.
Show resolved Hide resolved
// 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
2 changes: 2 additions & 0 deletions src/apps/search-header/search-header.entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { withUrls } from "../../core/utils/url";
import SearchHeader from "./search-header";
import GlobalUrlEntryPropsInterface from "../../core/utils/types/global-url-props";
import { GlobalEntryTextProps } from "../../core/storybook/globalTextArgs";
import { GlobalConfigProps } from "../../core/storybook/globalConfigArgs";

export interface SearchHeaderTextProps {
searchHeaderIconAltText?: string;
Expand All @@ -30,6 +31,7 @@ export interface SearchHeaderTextProps {
export interface SearchHeaderEntryProps
extends SearchHeaderTextProps,
GlobalEntryTextProps,
GlobalConfigProps,
GlobalUrlEntryPropsInterface {}

const SearchHeaderEntry: React.FC<SearchHeaderEntryProps> = () => {
Expand Down
8 changes: 4 additions & 4 deletions src/apps/search-header/search-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ const SearchHeader: React.FC = () => {
{
render: t("autosuggestBookCategoryText"),
term: AutosuggestCategory.book,
facet: "materialTypes"
facet: "materialTypesSpecific"
},
{
render: t("autosuggestEbookCategoryText"),
term: AutosuggestCategory.ebook,
facet: "materialTypes"
facet: "materialTypesSpecific"
},
{
render: t("autosuggestFilmCategoryText"),
Expand All @@ -80,7 +80,7 @@ const SearchHeader: React.FC = () => {
{
render: t("autosuggestAudioBookCategoryText"),
term: AutosuggestCategory.audioBook,
facet: "materialTypes"
facet: "materialTypesSpecific"
},
{
render: t("autosuggestMusicCategoryText"),
Expand All @@ -95,7 +95,7 @@ const SearchHeader: React.FC = () => {
{
render: t("autosuggestAnimatedSeriesCategoryText"),
term: AutosuggestCategory.animatedSeries,
facet: "materialTypes"
facet: "materialTypesSpecific"
}
];
// Once we register the item select event the original highlighted index is
Expand Down
4 changes: 1 addition & 3 deletions src/apps/search-result/search-result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ const SearchResult: React.FC<SearchResultProps> = ({ q, pageSize }) => {
useEffect(() => {
addFilterFromUrlParamListener(FacetField.MaterialTypesSpecific);
addFilterFromUrlParamListener(FacetField.WorkTypes);
// We only want to do this once, so we need the dependency array empty
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [addFilterFromUrlParamListener]);

const { data, isLoading } = useSearchWithPaginationQuery({
q: { all: q },
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
2 changes: 1 addition & 1 deletion src/core/utils/types/material-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const enum AutosuggestCategory {
animatedSeries = "tegneserie"
}

export type AutosuggestCategoryFacet = "materialTypes" | "workTypes";
export type AutosuggestCategoryFacet = "materialTypesSpecific" | "workTypes";

export type AutosuggestCategoryList = {
render: string;
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
Loading