-
Notifications
You must be signed in to change notification settings - Fork 0
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
SCC-3776 - Item Table Component #50
Merged
+583
−26
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
53583a5
Initialize item table component
dgcohen 494a832
Restore getActivePage
dgcohen eb90f4b
Refactor item table headings getter function
dgcohen 529ae04
Initialize ItemTableData model
dgcohen b124ffc
Initialize item table data refactor
dgcohen 6776e03
Remove length check on volume
dgcohen 7e4dd90
Merge branch 'main' of github.com:NYPL/research-catalog into SCC-3776…
dgcohen 05b2cd1
Remove getActivePage util
dgcohen ee5c1fc
Render table content
dgcohen 1f4806c
Render table content
dgcohen 50a7e4a
Use tableLayout key in css prop
dgcohen 723fd04
Initialize request buttons
dgcohen 5ed422f
Add closed locations env variable
dgcohen e5046b6
Create separate item table per item on search results
dgcohen 68cbb69
Format environment variables readme
dgcohen 527f32b
Tweak table styles
dgcohen c66f51a
Tweak table styles on mobile
dgcohen 20d8bbf
Render request link data
dgcohen 9ecf936
Render request link data
dgcohen cc19610
Increase bottom margin on buttons
dgcohen e155254
Remove onClick handler comments
dgcohen e488321
Fix isRecap attribute name
dgcohen 77d2419
Add bottom margin to information links
dgcohen 16485d0
Start off site logic
dgcohen 02ac042
Add not available case to information links
dgcohen dc145c0
Rename information links to ItemAvailability
dgcohen ee31a18
Fix issues with DS text components
dgcohen fd05fe0
Add TODO comments
dgcohen d369f98
Refactor closed locations logic
dgcohen 36d0a09
Fix broken SearchResult test
dgcohen 18ad591
Add todo comment to ItemTableData class
dgcohen df4ac1a
Add Todo comment in searchresult
dgcohen 71cda65
Add urls to config
dgcohen 0dd23d2
Add tests for item availability
dgcohen 475c0a0
Replace exact false with regex
dgcohen d8c6fdc
Add test for Item due date
dgcohen f87badb
Add tests for request buttons
dgcohen d10de6d
Use buttondisabled as type when item is not available
dgcohen a5ae2bb
Remove isDisabled link prop from RCLink
dgcohen 27b56f4
Fix dueDate type
dgcohen deaa85f
Merge branch 'SCC-3776/item-table-component' of github.com:NYPL/resea…
dgcohen 08ef887
Merge in main and resolve conflicts
dgcohen 624db28
Create showViewAllItems link helper
dgcohen 417f23a
Change date format in fixture
dgcohen 903a570
Use string for search params issuance
dgcohen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
dgcohen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this still need to be addressed? |
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
NEXT_PUBLIC
indicate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That prefix allows env variables to be used on the client side.