-
Notifications
You must be signed in to change notification settings - Fork 3
learning resource drawer v2 run comparison table #1782
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
83e547e
add first draft of run comparison table
gumaerc 2d74e19
hide labels on mobile
gumaerc e1772a4
update differing run table styles
gumaerc cf5578d
add tests
gumaerc b1ed214
display table if location is different
gumaerc 21171ac
move DifferingRunsTable to its own file
gumaerc b084be9
use getDisplayPrice
gumaerc e8565da
fix CTA image z-index issue
gumaerc b14f371
remove errant console.log
gumaerc 7f0e85f
fix location display
gumaerc 205ad11
remove duplicate sort
gumaerc 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
frontends/ol-components/src/components/LearningResourceExpanded/DifferingRunsTable.test.tsx
This file contains hidden or 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,39 @@ | ||
import React from "react" | ||
import { render, screen, within } from "@testing-library/react" | ||
import { courses } from "../LearningResourceCard/testUtils" | ||
import InfoSectionV2 from "./InfoSectionV2" | ||
import { ThemeProvider } from "../ThemeProvider/ThemeProvider" | ||
import { DeliveryEnumDescriptions } from "api" | ||
|
||
describe("Differing runs comparison table", () => { | ||
test("Does not appear if data is the same", () => { | ||
const course = courses.multipleRuns.sameData | ||
render(<InfoSectionV2 resource={course} />, { | ||
wrapper: ThemeProvider, | ||
}) | ||
expect(screen.queryByTestId("differing-runs-table")).toBeNull() | ||
}) | ||
|
||
test("Appears if data is different", () => { | ||
const course = courses.multipleRuns.differentData | ||
render(<InfoSectionV2 resource={course} />, { | ||
wrapper: ThemeProvider, | ||
}) | ||
const differingRunsTable = screen.getByTestId("differing-runs-table") | ||
expect(differingRunsTable).toBeInTheDocument() | ||
const onlineLabels = within(differingRunsTable).getAllByText( | ||
DeliveryEnumDescriptions.online, | ||
) | ||
const inPersonLabels = within(differingRunsTable).getAllByText( | ||
DeliveryEnumDescriptions.in_person, | ||
) | ||
const onlinePriceLabels = within(differingRunsTable).getAllByText("$100") | ||
const inPersonPriceLabels = within(differingRunsTable).getAllByText("$150") | ||
const earthLocationLabels = within(differingRunsTable).getAllByText("Earth") | ||
expect(onlineLabels).toHaveLength(2) | ||
expect(inPersonLabels).toHaveLength(2) | ||
expect(onlinePriceLabels).toHaveLength(2) | ||
expect(inPersonPriceLabels).toHaveLength(2) | ||
expect(earthLocationLabels).toHaveLength(2) | ||
}) | ||
}) |
138 changes: 138 additions & 0 deletions
138
frontends/ol-components/src/components/LearningResourceExpanded/DifferingRunsTable.tsx
This file contains hidden or 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,138 @@ | ||
import React from "react" | ||
import styled from "@emotion/styled" | ||
import { theme } from "../ThemeProvider/ThemeProvider" | ||
import { LearningResource, LearningResourcePrice } from "api" | ||
import { | ||
formatRunDate, | ||
getDisplayPrice, | ||
getRunPrices, | ||
showStartAnytime, | ||
} from "ol-utilities" | ||
|
||
const DifferingRuns = styled.div({ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "flex-start", | ||
alignSelf: "stretch", | ||
borderRadius: "4px", | ||
border: `1px solid ${theme.custom.colors.lightGray2}`, | ||
borderBottom: "none", | ||
}) | ||
|
||
const DifferingRun = styled.div({ | ||
display: "flex", | ||
flexWrap: "wrap", | ||
alignItems: "center", | ||
gap: "16px", | ||
padding: "12px", | ||
alignSelf: "stretch", | ||
borderBottom: `1px solid ${theme.custom.colors.lightGray2}`, | ||
}) | ||
|
||
const DifferingRunHeader = styled.div({ | ||
display: "flex", | ||
alignSelf: "stretch", | ||
alignItems: "center", | ||
flex: "1 0 0", | ||
gap: "16px", | ||
padding: "12px", | ||
color: theme.custom.colors.darkGray2, | ||
backgroundColor: theme.custom.colors.lightGray1, | ||
...theme.typography.subtitle3, | ||
}) | ||
|
||
const DifferingRunData = styled.div({ | ||
display: "flex", | ||
flexShrink: 0, | ||
flex: "1 0 0", | ||
color: theme.custom.colors.darkGray2, | ||
...theme.typography.body3, | ||
}) | ||
|
||
const DifferingRunLabel = styled.strong({ | ||
display: "flex", | ||
flex: "1 0 0", | ||
}) | ||
|
||
const DifferingRunLocation = styled(DifferingRunData)({ | ||
flex: "1 0 100%", | ||
flexDirection: "column", | ||
alignSelf: "stretch", | ||
}) | ||
|
||
const DifferingRunsTable: React.FC<{ resource: LearningResource }> = ({ | ||
resource, | ||
}) => { | ||
if (!resource.runs) { | ||
return null | ||
} | ||
if (resource.runs.length === 1) { | ||
return null | ||
} | ||
const asTaughtIn = resource ? showStartAnytime(resource) : false | ||
const prices: LearningResourcePrice[] = [] | ||
const deliveryMethods = [] | ||
const locations = [] | ||
for (const run of resource.runs) { | ||
if (run.resource_prices) { | ||
run.resource_prices.forEach((price) => { | ||
if (price.amount !== "0") { | ||
prices.push(price) | ||
} | ||
}) | ||
} | ||
if (run.delivery) { | ||
deliveryMethods.push(run.delivery) | ||
} | ||
if (run.location) { | ||
locations.push(run.location) | ||
} | ||
} | ||
const distinctPrices = [...new Set(prices.map((p) => p.amount).flat())] | ||
const distinctDeliveryMethods = [ | ||
...new Set(deliveryMethods.flat().map((dm) => dm?.code)), | ||
] | ||
const distinctLocations = [...new Set(locations.flat().map((l) => l))] | ||
if ( | ||
distinctPrices.length > 1 || | ||
distinctDeliveryMethods.length > 1 || | ||
distinctLocations.length > 1 | ||
) { | ||
return ( | ||
<DifferingRuns data-testid="differing-runs-table"> | ||
<DifferingRunHeader> | ||
<DifferingRunLabel>Date</DifferingRunLabel> | ||
<DifferingRunLabel>Price</DifferingRunLabel> | ||
<DifferingRunLabel>Format</DifferingRunLabel> | ||
</DifferingRunHeader> | ||
{resource.runs.map((run, index) => ( | ||
<DifferingRun key={index}> | ||
<DifferingRunData> | ||
{formatRunDate(run, asTaughtIn)} | ||
</DifferingRunData> | ||
{run.resource_prices && ( | ||
<DifferingRunData> | ||
<span>{getDisplayPrice(getRunPrices(run)["course"])}</span> | ||
</DifferingRunData> | ||
)} | ||
{run.delivery && ( | ||
<DifferingRunData> | ||
<span>{run.delivery?.map((dm) => dm?.name).join(", ")}</span> | ||
</DifferingRunData> | ||
)} | ||
{run.delivery.filter((d) => d.code === "in_person").length > 0 && | ||
run.location && ( | ||
<DifferingRunLocation> | ||
<strong>Location</strong> | ||
<span>{run.location}</span> | ||
</DifferingRunLocation> | ||
)} | ||
</DifferingRun> | ||
))} | ||
</DifferingRuns> | ||
) | ||
} | ||
return null | ||
} | ||
|
||
export default DifferingRunsTable |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -88,6 +88,7 @@ const Image = styled(NextImage)({ | |
borderRadius: "8px", | ||
width: "100%", | ||
objectFit: "cover", | ||
zIndex: -1, | ||
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. Yay 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. 🙃 |
||
}) | ||
|
||
const SkeletonImage = styled(Skeleton)<{ aspect: number }>((aspect) => ({ | ||
|
This file contains hidden or 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
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.
Is
run.delivery
always an array here as there are conditionals on it above?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.
Yea, according to the API spec it should always be an array. I've also seen it return an array with a single element: