-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from NYPL/SCC-3776/item-table-component
SCC-3776 - Item Table Component
- Loading branch information
Showing
27 changed files
with
583 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
PLATFORM_API_CLIENT_ID=[secret] | ||
PLATFORM_API_CLIENT_SECRET=[secret] | ||
NYPL_HEADER_URL=https://ds-header.nypl.org | ||
NYPL_HEADER_URL=https://ds-header.nypl.org | ||
NEXT_PUBLIC_CLOSED_LOCATIONS="" | ||
NEXT_PUBLIC_RECAP_CLOSED_LOCATIONS="" | ||
NEXT_PUBLIC_NON_RECAP_CLOSED_LOCATIONS="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from "react" | ||
import { render, screen } from "@testing-library/react" | ||
import ItemAvailability from "./ItemAvailability" | ||
import Item from "../../models/Item" | ||
import SearchResultsBib from "../../models/SearchResultsBib" | ||
import { | ||
itemNYPLReCAP, | ||
itemPhysicallyRequestable, | ||
itemAvailableOnsite, | ||
itemUnavailable, | ||
} from "../../../__test__/fixtures/itemFixtures" | ||
import { searchResultPhysicalItems } from "../../../__test__/fixtures/searchResultPhysicalItems" | ||
|
||
const parentBib = new SearchResultsBib(searchResultPhysicalItems) | ||
|
||
describe("ItemAvailability", () => { | ||
it("renders the correct link when item is available, is reCAP, and does not have an aeon url", async () => { | ||
const item = new Item(itemNYPLReCAP, parentBib) | ||
render(<ItemAvailability item={item} />) | ||
expect( | ||
screen.getByRole("link", { | ||
name: "How do I pick up this item and when will it be ready?", | ||
}) | ||
).toHaveAttribute( | ||
"href", | ||
"https://www.nypl.org/help/request-research-materials" | ||
) | ||
}) | ||
it("renders the correct text when item is available, has an aeon url, and has a location endpoint", async () => { | ||
const item = new Item(itemPhysicallyRequestable, parentBib) | ||
render(<ItemAvailability item={item} />) | ||
expect(screen.getByText("Available by appointment")).toBeInTheDocument() | ||
expect( | ||
screen.getByRole("link", { | ||
name: "Schwarzman Building - Main Reading Room 315", | ||
}) | ||
).toHaveAttribute("href", "https://www.nypl.org/locations/schwarzman") | ||
}) | ||
it("renders the correct text for an available onsite item", async () => { | ||
const item = new Item(itemAvailableOnsite, parentBib) | ||
render(<ItemAvailability item={item} />) | ||
expect(screen.getByText("Available")).toBeInTheDocument() | ||
expect( | ||
screen.getByText("- Can be used on site. Please visit", { exact: false }) | ||
).toBeInTheDocument() | ||
expect( | ||
screen.getByRole("link", { | ||
name: "New York Public Library - Schwarzman Building M2", | ||
}) | ||
).toHaveAttribute("href", "https://www.nypl.org/locations/schwarzman") | ||
expect( | ||
screen.getByText("to submit a request in person.", { exact: false }) | ||
).toBeInTheDocument() | ||
}) | ||
it("renders the correct text for unavailable items", async () => { | ||
const item = new Item(itemUnavailable, parentBib) | ||
render(<ItemAvailability item={item} />) | ||
expect(screen.getByText("Not available")).toBeInTheDocument() | ||
expect(screen.getByText("- Please", { exact: false })).toBeInTheDocument() | ||
screen.getByRole("button", { | ||
name: "contact a librarian", | ||
}) | ||
expect( | ||
screen.getByText("for assistance.", { exact: false }) | ||
).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Text, Link, Button, Box } from "@nypl/design-system-react-components" | ||
|
||
import { appConfig } from "../../config/config" | ||
import type Item from "../../models/Item" | ||
|
||
interface ItemAvailabilityProps { | ||
item: Item | ||
} | ||
|
||
/** | ||
* The ItemAvailability component appears below the Item table and displays | ||
* info about an item's availability. | ||
* TODO: Add Feedback box, Due date, Available font styles | ||
*/ | ||
const ItemAvailability = ({ item }: ItemAvailabilityProps) => { | ||
// TODO: Move this logic into a getter function in the Item class that returns an availability status key | ||
// and replace this nested If with a simple switch statement | ||
if (item.isAvailable) { | ||
if (item.isReCAP && !item.aeonUrl) { | ||
// Available ReCAP item | ||
return ( | ||
<Link | ||
href={appConfig.externalUrls.researchMaterialsHelp} | ||
target="_blank" | ||
fontSize="sm" | ||
> | ||
How do I pick up this item and when will it be ready? | ||
</Link> | ||
) | ||
} else if (item.aeonUrl && item.location?.endpoint) { | ||
return ( | ||
<Text> | ||
<Box as="span" color="ui.success.primary"> | ||
Available by appointment | ||
</Box> | ||
{!item.isReCAP ? ( | ||
<> | ||
{" at "} | ||
<Link | ||
href={`${appConfig.externalUrls.locations}${item.location.endpoint}`} | ||
target="_blank" | ||
> | ||
{item.location.prefLabel} | ||
</Link> | ||
</> | ||
) : null} | ||
</Text> | ||
) | ||
} else { | ||
// Available Onsite item | ||
const locationShort = item.location.prefLabel.split("-")[0] | ||
return ( | ||
<Text> | ||
<Box as="span" color="ui.success.primary"> | ||
Available | ||
</Box> | ||
{" - Can be used on site. Please visit "} | ||
<Link | ||
href={`${appConfig.externalUrls.locations}${item.location.endpoint}`} | ||
target="_blank" | ||
> | ||
{`New York Public Library - ${locationShort}`} | ||
</Link> | ||
{" to submit a request in person."} | ||
</Text> | ||
) | ||
} | ||
} else { | ||
// Not available | ||
return ( | ||
<Text> | ||
<Box as="span" color="ui.warning.primary"> | ||
Not available | ||
</Box> | ||
{item.dueDate && ` - In use until ${item.dueDate}`} | ||
{" - Please "} | ||
<Button | ||
id="contact-librarian" | ||
buttonType="link" | ||
sx={{ display: "inline", fontWeight: "inherit", fontSize: "inherit" }} | ||
onClick={() => { | ||
console.log("TODO: Trigger Feedback box") | ||
}} | ||
> | ||
contact a librarian | ||
</Button> | ||
{" for assistance."} | ||
</Text> | ||
) | ||
} | ||
} | ||
|
||
export default ItemAvailability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Box, Table } from "@nypl/design-system-react-components" | ||
|
||
import type ItemTableData from "../../models/ItemTableData" | ||
import RequestButtons from "./RequestButtons" | ||
import ItemAvailability from "./ItemAvailability" | ||
|
||
interface ItemTableProps { | ||
itemTableData: ItemTableData | ||
} | ||
|
||
/** | ||
* The ItemTable displays item details, the RequestButtons | ||
*/ | ||
const ItemTable = ({ itemTableData }: ItemTableProps) => { | ||
return ( | ||
<> | ||
<Table | ||
columnHeaders={itemTableData.tableHeadings} | ||
tableData={itemTableData.tableData} | ||
mb="s" | ||
// TODO: These styles approximate those of the old app. | ||
// Design will VQA the component with the DS defaults, but leaving this for reference. | ||
// sx={{ | ||
// tableLayout: "fixed", | ||
// width: "full", | ||
// tr: { border: "0 !important", padding: 0 }, | ||
// "th, td, th > span, td > span": { | ||
// paddingTop: "xs", | ||
// paddingBottom: "xs", | ||
// }, | ||
// }} | ||
/> | ||
{!itemTableData.isBibPage && ( | ||
<Box mb="s"> | ||
<RequestButtons item={itemTableData.items[0]} /> | ||
<ItemAvailability item={itemTableData.items[0]} /> | ||
</Box> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default ItemTable |
Oops, something went wrong.