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

Feature reservation button fix #1341

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function LocalizationInformation({
>{`${pickupBranch?.postalCode} ${pickupBranch?.city}`}</Text>
</div>
)}

{/* maybe move warning together with warning in order-modal. see bibdk2021-1927 */}
{!isLoadingBranches &&
pickupBranch &&
Expand Down
6 changes: 2 additions & 4 deletions src/components/hooks/useBookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const isMaterialTypesMatch = (
};

/**
* Find the work index where one pid in mostRelevant matches the given materialId
* Find the work index where one pid in manifestations.all matches the given materialId
* OBS: we cannot simply look for matching workIds, since workIds might be changing
* @returns {number} index of work
*/
Expand All @@ -322,9 +322,7 @@ export function findRelevantWorkIdx(
return workByIdsDataRemovedDuplicates?.findIndex((w) => {
const pid = materialId?.replace("work-of:", "");
if (!pid) return -1;
return w?.manifestations?.mostRelevant?.some(
(mostRelevant) => mostRelevant.pid === pid
);
return w?.manifestations?.mostRelevant?.some((m) => m.pid === pid);
});
}

Expand Down
8 changes: 2 additions & 6 deletions src/components/hooks/useWorkAndSelectedPids.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ export function useGetManifestationsForOrderButton(workId, selectedPids) {
const workResponse = useData(workId && workFragments.buttonTxt({ workId }));

const allPids = useMemo(() => {
return workResponse?.data?.work?.manifestations?.mostRelevant?.flatMap(
return workResponse?.data?.work?.manifestations?.all?.flatMap(
(manifestation) => manifestation.pid
);
}, [
workId,
selectedPids,
workResponse?.data?.work?.manifestations?.mostRelevant,
]);
}, [workId, selectedPids, workResponse?.data?.work?.manifestations?.all]);

const manifestationsResponse = useData(
allPids &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ function ColumnOne({ workId, manifestation }) {
);
}

const selectedPids = manifestation?.unit?.manifestations?.map(
({ pid }) => pid
);

return (
<Col
key={"col1" + manifestation?.pid}
Expand All @@ -93,7 +97,7 @@ function ColumnOne({ workId, manifestation }) {
<div className={styles.reservationwrapper}>
<ReservationButtonWrapper
workId={workId}
selectedPids={[manifestation?.pid]}
selectedPids={selectedPids}
singleManifestation={true}
buttonType="secondary"
size="small"
Expand All @@ -110,15 +114,12 @@ function ColumnOne({ workId, manifestation }) {
</div>

<div className={cx(styles.alternativeoptions)}>
<AlternativeOptions
workId={workId}
selectedPids={[manifestation?.pid]}
/>
<AlternativeOptions workId={workId} selectedPids={selectedPids} />
</div>

<div className={styles.localizations_link}>
<LocalizationsLink
selectedPids={[manifestation?.pid]}
selectedPids={selectedPids}
singleManifestation={true}
/>
</div>
Expand All @@ -128,12 +129,7 @@ function ColumnOne({ workId, manifestation }) {
dataCy="link-references"
border={{ bottom: { keepVisible: true } }}
onClick={() =>
openReferencesModal(
modal,
[manifestation?.pid],
workId,
manifestation
)
openReferencesModal(modal, selectedPids, workId, manifestation)
}
>
<Text type="text3" tag="span">
Expand Down
11 changes: 11 additions & 0 deletions src/components/work/overview/bookmarkDropdown/BookmarkDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export function BookMarkMaterialSelector({
(bookmark) =>
bookmark.materialId !== bookmark.workId && bookmark.workId === workId
);

console.log({ addedEditions, manifestations, editions });

const specificEditions =
addedEditions
?.map((addedEdition) => {
Expand Down Expand Up @@ -119,6 +122,14 @@ export function BookMarkMaterialSelector({
};

const onSelect = async (material, workId) => {
console.log("bookmark", {
key: getBookmarkKey(material),
materialId: materialId,
workId: workId,
materialType: formatMaterialTypesToCode(material.materialTypes),
title,
});

await setBookmark({
key: getBookmarkKey(material),
materialId: materialId,
Expand Down
2 changes: 1 addition & 1 deletion src/components/work/reservationbutton/ReservationButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const ReservationButton = ({
modal,
handleOrderFinished = undefined,
}) => {
const physicalCopy = checkPhysicalCopy([access?.[0]])?.[0]; //TODO why do we check all accesses if only one is used in the end?
const physicalCopy = checkPhysicalCopy(access)?.[0]; //TODO why do we check all accesses if only one is used in the end?
const digitalCopy = checkDigitalCopy([access?.[0]])?.[0]; //TODO why do we check all accesses if only one is used in the end?

const noSelectedManifestations = Boolean(isEmpty(access));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ReservationButtonEAudioBook.story = {
],
workTypes: ["LITERATURE"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-lydbog-(net)" + time,
},
Expand Down Expand Up @@ -187,7 +187,7 @@ ReservationButtonGame.story = {
],
workTypes: ["GAME"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-game" + time,
},
Expand Down Expand Up @@ -257,7 +257,7 @@ ReservationButtonDisabled.story = {
],
workTypes: ["LITERATURE"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-disabled" + time,
access: [],
Expand Down Expand Up @@ -322,7 +322,7 @@ ReservationButtonPhysicalBookLoanNotPossible.story = {
],
workTypes: ["LITERATURE"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-bog-loan-not-possible" + time,
},
Expand Down Expand Up @@ -374,7 +374,7 @@ ReservationButtonSlowResponse.story = {
],
workTypes: ["LITERATURE"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-slow-response" + time,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import useUser from "@/components/hooks/useUser";
* @returns {React.ReactElement|null}
*/
function OrderButtonTextBelow({ access, skeleton }) {
const physicalCopy = checkPhysicalCopy([access?.[0]])?.[0];
const physicalCopy = checkPhysicalCopy(access)?.[0];
const digitalCopy = checkDigitalCopy([access?.[0]])?.[0];
const isPeriodicaLike = getAreAccessesPeriodicaLike([access?.[0]])?.[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ EBookButtonTxt.story = {
],
workTypes: ["LITERATURE"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-ebog" + time,
},
Expand Down Expand Up @@ -161,7 +161,7 @@ EAudioBookPhysicalButtonTxt.story = {
],
workTypes: ["LITERATURE"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-physical-audio-book" + time,
},
Expand Down Expand Up @@ -225,7 +225,7 @@ EAudioBookDigitalButtonTxt.story = {
],
workTypes: ["LITERATURE"],
manifestations: {
mostRelevant: [
all: [
{
pid: "some-pid-elydbog" + time,
},
Expand Down
6 changes: 6 additions & 0 deletions src/lib/api/manifestation.fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ const manifestationFragment = `fragment manifestationFragment on Manifestation {
display
type
}
}
unit {
id
manifestations {
pid
}
}
languages {
original {
Expand Down
1 change: 1 addition & 0 deletions src/lib/api/search.fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function hitcount({ q, filters = {} }) {
* @param {Object} filters filters for searching
* @param {Boolean} search_exact
*/

export function all({
q,
limit = 100,
Expand Down
13 changes: 11 additions & 2 deletions src/lib/api/work.fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ export function buttonTxt({ workId }) {
manifestations {
all {
pid
materialTypes {
...materialTypesFragment
}
}
mostRelevant {
pid
Expand Down Expand Up @@ -735,6 +738,12 @@ export function listOfAllManifestations({ workId }) {
}
edition
}
unit {
id
manifestations {
pid
}
}
creators {
...creatorsFragment
}
Expand Down Expand Up @@ -766,7 +775,7 @@ export function orderPageWorkWithManifestations({ workId }) {
}
workTypes
manifestations {
mostRelevant {
all {
...manifestationAccess
...manifestationDetailsForAccessFactory
}
Expand Down Expand Up @@ -807,7 +816,7 @@ export function overviewWork({ workId }) {
}
workTypes
manifestations {
mostRelevant {
mostRelevant {
ownerWork {
workTypes
}
Expand Down