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

Refactor button reservable from another library #797

115 changes: 59 additions & 56 deletions cypress/fixtures/material/open-order/fbi-api.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"data": {
"work": {
"workId": "work-of:870970-basis:135721719",
"workId": "work-of:870970-basis:44926407",
"titles": {
"full": [
"Restyle & restitch for little ones : 30 simple projects from preloved clothes"
"Duchess of Death : the unauthorized biography of Agatha Christie"
],
"original": []
},
"abstract": [
"30 sewing projects for creating stylish baby clothes, from newborns to two-year-olds, including trousers, dresses, sweaters, mittens, rompers and socks. The projects are accompanied by colourful, full-size patterns to help you make the most of your repurposed clothing."
"Summary: Utilizing over 5,000 previously unpublished letters, notes, and documents, the author tells how Christie's life was \"as full of romance, travel, wealth, and scandal as any mystery Christie ever crafted.\" -- from publisher description."
],
"creators": [
{
"display": "Linnea Larsson",
"display": "Richard Hack",
"__typename": "Person"
}
],
"series": [],
"seriesMembers": [],
"workYear": null,
"genreAndForm": ["snitmønstre", "vejledninger"],
"genreAndForm": ["biografier", "bibliografier"],
"manifestations": {
"all": [
{
"pid": "870970-basis:135721719",
"genreAndForm": ["snitmønstre", "vejledninger"],
"pid": "870970-basis:44926407",
"genreAndForm": ["biografier"],
"source": ["Bibliotekskatalog"],
"languages": {
"main": [
Expand All @@ -36,7 +36,7 @@
]
},
"titles": {
"main": ["Restyle & restitch for little ones"],
"main": ["Duchess of Death"],
"original": []
},
"fictionNonfiction": {
Expand All @@ -50,21 +50,21 @@
],
"creators": [
{
"display": "Linnea Larsson",
"display": "Richard Hack",
"__typename": "Person"
}
],
"publisher": ["Search"],
"publisher": ["JR Books"],
"identifiers": [
{
"value": "9781800921191"
"value": "9781906779832"
}
],
"contributors": [],
"edition": {
"summary": "2023",
"summary": "1. edition, 2010",
"publicationYear": {
"display": "2023"
"display": "2010"
}
},
"dateFirstEdition": null,
Expand All @@ -73,7 +73,7 @@
},
"physicalDescriptions": [
{
"numberOfPages": 124,
"numberOfPages": 325,
"playingTime": null
}
],
Expand All @@ -89,19 +89,19 @@
}
],
"shelfmark": {
"postfix": "Larsson",
"shelfmark": "64.62"
"postfix": "Hack",
"shelfmark": "99.4 Christie, Agatha"
},
"workYear": null,
"catalogueCodes": {
"nationalBibliography": [],
"otherCatalogues": ["OVE202314"]
"otherCatalogues": ["OVE999999"]
}
}
],
"latest": {
"pid": "870970-basis:135721719",
"genreAndForm": ["snitmønstre", "vejledninger"],
"pid": "870970-basis:44926407",
"genreAndForm": ["biografier"],
"source": ["Bibliotekskatalog"],
"languages": {
"main": [
Expand All @@ -112,7 +112,7 @@
]
},
"titles": {
"main": ["Restyle & restitch for little ones"],
"main": ["Duchess of Death"],
"original": []
},
"fictionNonfiction": {
Expand All @@ -126,21 +126,21 @@
],
"creators": [
{
"display": "Linnea Larsson",
"display": "Richard Hack",
"__typename": "Person"
}
],
"publisher": ["Search"],
"publisher": ["JR Books"],
"identifiers": [
{
"value": "9781800921191"
"value": "9781906779832"
}
],
"contributors": [],
"edition": {
"summary": "2023",
"summary": "1. edition, 2010",
"publicationYear": {
"display": "2023"
"display": "2010"
}
},
"dateFirstEdition": null,
Expand All @@ -149,7 +149,7 @@
},
"physicalDescriptions": [
{
"numberOfPages": 124,
"numberOfPages": 325,
"playingTime": null
}
],
Expand All @@ -165,18 +165,18 @@
}
],
"shelfmark": {
"postfix": "Larsson",
"shelfmark": "64.62"
"postfix": "Hack",
"shelfmark": "99.4 Christie, Agatha"
},
"workYear": null,
"catalogueCodes": {
"nationalBibliography": [],
"otherCatalogues": ["OVE202314"]
"otherCatalogues": ["OVE999999"]
}
},
"bestRepresentation": {
"pid": "870970-basis:135721719",
"genreAndForm": ["snitmønstre", "vejledninger"],
"pid": "870970-basis:44926407",
"genreAndForm": ["biografier"],
"source": ["Bibliotekskatalog"],
"languages": {
"main": [
Expand All @@ -187,7 +187,7 @@
]
},
"titles": {
"main": ["Restyle & restitch for little ones"],
"main": ["Duchess of Death"],
"original": []
},
"fictionNonfiction": {
Expand All @@ -201,21 +201,21 @@
],
"creators": [
{
"display": "Linnea Larsson",
"display": "Richard Hack",
"__typename": "Person"
}
],
"publisher": ["Search"],
"publisher": ["JR Books"],
"identifiers": [
{
"value": "9781800921191"
"value": "9781906779832"
}
],
"contributors": [],
"edition": {
"summary": "2023",
"summary": "1. edition, 2010",
"publicationYear": {
"display": "2023"
"display": "2010"
}
},
"dateFirstEdition": null,
Expand All @@ -224,7 +224,7 @@
},
"physicalDescriptions": [
{
"numberOfPages": 124,
"numberOfPages": 325,
"playingTime": null
}
],
Expand All @@ -240,13 +240,13 @@
}
],
"shelfmark": {
"postfix": "Larsson",
"shelfmark": "64.62"
"postfix": "Hack",
"shelfmark": "99.4 Christie, Agatha"
},
"workYear": null,
"catalogueCodes": {
"nationalBibliography": [],
"otherCatalogues": ["OVE202314"]
"otherCatalogues": ["OVE999999"]
}
}
},
Expand All @@ -264,42 +264,45 @@
"subjects": {
"all": [
{
"display": "syning"
"display": "forfattere"
},
{
"display": "børnetøj"
"display": "kriminalforfattere"
},
{
"display": "genbrug"
"display": "England"
},
{
"display": "genbrugstøj"
"display": "Authors, English -- 20th century -- Biography"
},
{
"display": "tekstiler"
"display": "Detective and mystery stories -- Authorship"
},
{
"display": "upcycling"
"display": "Agatha Christie (1890-1976)"
},
{
"display": "Agatha Christie"
},
{
"display": "1900-tallet"
}
],
"dbcVerified": [
{
"display": "syning"
},
{
"display": "børnetøj"
"display": "forfattere"
},
{
"display": "genbrug"
"display": "kriminalforfattere"
},
{
"display": "genbrugstøj"
"display": "England"
},
{
"display": "tekstiler"
"display": "Agatha Christie"
},
{
"display": "upcycling"
"display": "1900-tallet"
}
]
},
Expand All @@ -308,7 +311,7 @@
"code": "NONFICTION"
},
"dk5MainEntry": {
"display": "64.62 Syning af børnetøj"
"display": "99.4 Christie, Agatha"
},
"relations": {
"hasReview": [],
Expand Down
7 changes: 1 addition & 6 deletions src/apps/material/material.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,6 @@ export default {
defaultValue: "Order from another library:",
control: { type: "text" }
},
openOrderResponseIsReservedForYouText: {
name: "Reservation Success Title",
defaultValue: "is ordered to your library",
control: { type: "text" }
},
openOrderAuthenticationErrorText: {
name: "Open order authentication error text",
defaultValue: "Authentication error occurred",
Expand Down Expand Up @@ -975,5 +970,5 @@ Underverden.args = {

export const overbygningsMatriale = Template.bind({});
overbygningsMatriale.args = {
wid: "work-of:870970-basis:135721719"
wid: "work-of:870970-basis:44926407"
};
1 change: 0 additions & 1 deletion src/apps/material/material.entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ interface MaterialEntryTextProps {
openOrderOrsErrorText: string;
openOrderOwnedOwnCatalogueText: string;
openOrderOwnedWrongMediumtypeText: string;
openOrderResponseIsReservedForYouText: string;
openOrderResponseTitleText: string;
openOrderServiceUnavailableText: string;
openOrderStatusOwnedAcceptedText: string;
Expand Down
21 changes: 20 additions & 1 deletion src/components/material/material-buttons/MaterialButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as React from "react";
import { FC } from "react";
import { AccessTypeCode } from "../../../core/dbc-gateway/generated/graphql";
import { getAllFaustIds } from "../../../core/utils/helpers/general";
import {
getAllFaustIds,
getManifestationType
} from "../../../core/utils/helpers/general";
import { ButtonSize } from "../../../core/utils/types/button";
import { Manifestation } from "../../../core/utils/types/entities";
import { hasCorrectAccess, hasCorrectAccessType, isArticle } from "./helper";
import { WorkId } from "../../../core/utils/types/ids";
import MaterialButtonsOnline from "./online/MaterialButtonsOnline";
import MaterialButtonsFindOnShelf from "./physical/MaterialButtonsFindOnShelf";
import MaterialButtonsPhysical from "./physical/MaterialButtonsPhysical";
import MaterialButtonReservableFromAnotherLibrary from "./physical/MaterialButtonReservableFromAnotherLibrary";
import useReservableFromAnotherLibrary from "../../../core/utils/useReservableFromAnotherLibrary";

export interface MaterialButtonsProps {
manifestations: Manifestation[];
Expand All @@ -29,6 +34,20 @@ const MaterialButtons: FC<MaterialButtonsProps> = ({
// We don't want to show physical buttons/find on shelf for articles because
// articles appear as a part of journal/periodical publications and can't be
// physically loaned for themseleves.

const reservablePidsFromAnotherLibrary =
useReservableFromAnotherLibrary(manifestations);

if (reservablePidsFromAnotherLibrary.length > 0) {
return (
<MaterialButtonReservableFromAnotherLibrary
size={size}
manifestationMaterialType={getManifestationType(manifestations)}
faustIds={faustIds}
/>
);
}

return (
<>
{hasCorrectAccessType(AccessTypeCode.Physical, manifestations) &&
Expand Down
Loading
Loading