Skip to content

Learning Resource cards, list view #1054

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 29 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ee148e8
Card updated default and hover states
jonkafton Jun 7, 2024
5ee44aa
Base list card components
jonkafton Jun 7, 2024
4e121e6
List card styles
jonkafton Jun 7, 2024
e99c822
Learning format and border separator
jonkafton Jun 7, 2024
6b8ea5f
Use embedly URLs for images
jonkafton Jun 10, 2024
92cb00d
Styles for mobile
jonkafton Jun 10, 2024
306341c
Loading view and buttons styling
jonkafton Jun 10, 2024
df34b35
List card stories
jonkafton Jun 10, 2024
a93a06d
Remove size
jonkafton Jun 10, 2024
025c05f
Style lint fixes
jonkafton Jun 10, 2024
db72030
Pass href to navigate instead of open drawer. Add list count for lear…
jonkafton Jun 11, 2024
bc8aeb4
Position buttons absolute and outside of Link container
jonkafton Jun 11, 2024
dfdb7f7
Merge branch 'main' into 4365-list-cards
jonkafton Jun 11, 2024
4173aeb
Positioning and set class on wrapper
jonkafton Jun 11, 2024
92fc7b0
Test fixes
jonkafton Jun 11, 2024
9a60a84
Merge branch 'main' into 4365-list-cards
jonkafton Jun 12, 2024
0d815e2
Reinstate non link card variant. Update tests
jonkafton Jun 12, 2024
246a66e
Style lint fix
jonkafton Jun 12, 2024
646cc43
Default image for list cards
jonkafton Jun 12, 2024
7645b4c
Provide actions buttons to search items
jonkafton Jun 12, 2024
cb85dc2
Position actions dependent on image
jonkafton Jun 12, 2024
8ec7f53
Merge branch 'main' into 4365-list-cards
jonkafton Jun 12, 2024
4797c2e
Test for list variant
jonkafton Jun 13, 2024
41103a0
Relative API base path for local
jonkafton Jun 14, 2024
0da8dc8
Use TruncatedText for title
jonkafton Jun 14, 2024
08f303b
Hook to provide open drawer href to list component
jonkafton Jun 14, 2024
0277156
Replace breakpoint hook with css
jonkafton Jun 14, 2024
dde11d3
Fix test (bad css). Apply drawer href hook to Cards
jonkafton Jun 14, 2024
913218f
Merge branch 'main' into 4365-list-cards
jonkafton Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontends/api/src/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import axiosInstance from "./axios"

const BASE_PATH = process.env.MITOPEN_AXIOS_BASE_PATH?.replace(/\/+$/, "") ?? ""

const learningResourcesApi = new LearningResourcesApi(
undefined,
BASE_PATH,
Expand Down
2 changes: 1 addition & 1 deletion frontends/mit-open/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const config = {
PUBLIC_URL: process.env.PUBLIC_URL || "",
EMBEDLY_KEY: process.env.EMBEDLY_KEY || "",
APP_SETTINGS: {
embedlyKey: "fake-embedly-key",
embedlyKey: process.env.EMBEDLY_KEY || "",
},
}),
}
Expand Down
2 changes: 1 addition & 1 deletion frontends/mit-open/.storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<link rel="stylesheet" href="https://use.typekit.net/lbk1xay.css" />
<script>
window.APP_SETTINGS = {
embedlyKey: 'fake-embedly-key',
embedlyKey: null,
}
</script>
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* TODO: This has been replaced by the ol-components LearningResourceCard
* It is still in use by the LearningPathDetailsPage -> ListDetails -> ItemsListing
* though can be removed (and adjacent LearningResourceCardTemplate) once
* the sorting functionality has been refactored across
*/
import React, { useCallback } from "react"
import * as NiceModal from "@ebay/nice-modal-react"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,14 @@ const useOpenLearningResourceDrawer = () => {
return openLearningResourceDrawer
}

const useResourceDrawerHref = () => {
const [search] = useSearchParams()

return (id: number) => {
search.set(RESOURCE_DRAWER_QUERY_PARAM, id.toString())
return `?${search.toString()}`
}
}

export default LearningResourceDrawer
export { useOpenLearningResourceDrawer }
export { useOpenLearningResourceDrawer, useResourceDrawerHref }
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ import {
AddToLearningPathDialog,
AddToUserListDialog,
} from "../Dialogs/AddToListDialog"
import { useOpenLearningResourceDrawer } from "../LearningResourceDrawer/LearningResourceDrawer"

const LearningResourceCardStyled = styled(LearningResourceCard)({
boxShadow: "none",
":hover": {
boxShadow:
"0 2px 4px 0 rgb(37 38 43 / 10%), 0 2px 4px 0 rgb(37 38 43 / 10%)",
},
})
import { useResourceDrawerHref } from "../LearningResourceDrawer/LearningResourceDrawer"

const StyledCarousel = styled(Carousel)({
/**
Expand Down Expand Up @@ -272,6 +264,7 @@ const ResourceCarousel: React.FC<ResourceCarouselProps> = ({
const { data: user } = useUserMe()
const [tab, setTab] = React.useState("0")
const [ref, setRef] = React.useState<HTMLDivElement | null>(null)
const getDrawerHref = useResourceDrawerHref()

const showAddToLearningPathDialog =
user?.is_authenticated && user?.is_learning_path_editor
Expand All @@ -286,8 +279,6 @@ const ResourceCarousel: React.FC<ResourceCarouselProps> = ({
}
: null

const openLRDrawer = useOpenLearningResourceDrawer()

return (
<MobileOverflow className={className}>
<TabContext value={tab}>
Expand All @@ -314,21 +305,21 @@ const ResourceCarousel: React.FC<ResourceCarouselProps> = ({
<StyledCarousel arrowsContainer={ref}>
{isLoading || childrenLoading
? Array.from({ length: 6 }).map((_, index) => (
<LearningResourceCardStyled
<LearningResourceCard
isLoading
key={index}
resource={null}
{...tabConfig.cardProps}
/>
))
: resources.map((resource) => (
<LearningResourceCardStyled
<LearningResourceCard
key={resource.id}
resource={resource}
{...tabConfig.cardProps}
href={getDrawerHref(resource.id)}
onAddToLearningPathClick={showAddToLearningPathDialog}
onAddToUserListClick={showAddToUserListDialog}
onActivate={() => openLRDrawer(resource.id)}
/>
))}
</StyledCarousel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ import {
MuiCard,
CardContent,
PlainList,
Skeleton,
Container,
Typography,
Button,
SimpleSelect,
truncateText,
css,
LearningResourceListCard,
} from "ol-components"

import TuneIcon from "@mui/icons-material/Tune"

import * as NiceModal from "@ebay/nice-modal-react"
import {
LearningResourcesSearchApiLearningResourcesSearchRetrieveRequest as LRSearchRequest,
ResourceTypeEnum,
} from "api"
import { useLearningResourcesSearch } from "api/hooks/learningResources"

import { GridColumn, GridContainer } from "@/components/GridLayout/GridLayout"
import {
AvailableFacets,
Expand All @@ -33,13 +31,16 @@ import type {
BooleanFacets,
FacetManifest,
} from "@mitodl/course-search-utils"
import LearningResourceCard from "@/page-components/LearningResourceCard/LearningResourceCard"
import _ from "lodash"

import { ResourceTypeTabs } from "./ResourceTypeTabs"
import ProfessionalToggle from "./ProfessionalToggle"

import type { TabConfig } from "./ResourceTypeTabs"
import { useUserMe } from "api/hooks/user"
import {
AddToLearningPathDialog,
AddToUserListDialog,
} from "../Dialogs/AddToListDialog"
import { useResourceDrawerHref } from "@/page-components/LearningResourceDrawer/LearningResourceDrawer"

export const StyledDropdown = styled(SimpleSelect)`
margin: 8px;
Expand Down Expand Up @@ -201,10 +202,7 @@ export const FacetsTitleContainer = styled.div`
const PaginationContainer = styled.div`
display: flex;
justify-content: end;
`

const StyledSkeleton = styled(Skeleton)`
border-radius: 4px;
margin-top: 16px;
`

const PAGE_SIZE = 10
Expand Down Expand Up @@ -293,6 +291,24 @@ const SearchDisplay: React.FC<SearchDisplayProps> = ({
},
{ keepPreviousData: true },
)

const { data: user } = useUserMe()

const getDrawerHref = useResourceDrawerHref()

const showAddToLearningPathDialog =
user?.is_authenticated && user?.is_learning_path_editor
? (resourceId: number) => {
NiceModal.show(AddToLearningPathDialog, { resourceId })
}
: null

const showAddToUserListDialog = user?.is_authenticated
? (resourceId: number) => {
NiceModal.show(AddToUserListDialog, { resourceId })
}
: null

return (
<Container>
<GridContainer>
Expand Down Expand Up @@ -357,17 +373,19 @@ const SearchDisplay: React.FC<SearchDisplayProps> = ({
.fill(null)
.map((a, index) => (
<li key={index}>
<StyledSkeleton variant="rectangular" height={162} />
<LearningResourceListCard isLoading={isLoading} />
</li>
))}
</PlainList>
) : data && data.count > 0 ? (
<PlainList itemSpacing={3}>
{data.results.map((resource) => (
<li key={resource.id}>
<LearningResourceCard
variant="row-reverse"
<LearningResourceListCard
resource={resource}
href={getDrawerHref(resource.id)}
onAddToLearningPathClick={showAddToLearningPathDialog}
onAddToUserListClick={showAddToUserListDialog}
/>
</li>
))}
Expand Down
45 changes: 24 additions & 21 deletions frontends/mit-open/src/pages/HomePage/NewsEventsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Grid,
useMuiBreakpointAtLeast,
Card,
CardLinkContainer,
} from "ol-components"
import {
useNewsEventsList,
Expand Down Expand Up @@ -81,7 +80,6 @@ const StoryCard = styled(Card)<{ mobile: boolean }>`
display: flex;
flex-direction: column;
flex-shrink: 0;
overflow: hidden;
${({ mobile }) => (mobile ? "width: 274px" : "")}
`

Expand All @@ -105,15 +103,18 @@ const MobileEvents = styled(Events)`
padding: 0 16px;
`

const EventCard = styled(CardLinkContainer)`
const EventCard = styled(Card)`
display: flex;
align-items: center;
gap: 16px;
flex: 1 0 0;
align-self: stretch;
padding: 16px;
justify-content: space-between;
overflow: visible;

> a {
padding: 16px;
}
`

const EventDate = styled.div`
Expand Down Expand Up @@ -173,7 +174,7 @@ const Story: React.FC<{ item: NewsFeedItem; mobile: boolean }> = ({
mobile,
}) => {
return (
<StoryCard mobile={mobile} href={item.url} link>
<StoryCard mobile={mobile} href={item.url}>
<Card.Image src={item.image?.url} alt={item.image?.alt} />
<Card.Title>{item.title}</Card.Title>
<Card.Footer>
Expand Down Expand Up @@ -208,22 +209,24 @@ const NewsEventsSection: React.FC = () => {
const EventCards =
events!.results?.map((item) => (
<EventCard key={item.id} href={item.url}>
<EventDate>
<EventDay>
{formatDate(
(item as EventFeedItem).event_details?.event_datetime,
"D",
)}
</EventDay>
<EventMonth>
{formatDate(
(item as EventFeedItem).event_details?.event_datetime,
"MMM",
)}
</EventMonth>
</EventDate>
<EventTitle>{item.title}</EventTitle>
<Chevron />
<Card.Content>
<EventDate>
<EventDay>
{formatDate(
(item as EventFeedItem).event_details?.event_datetime,
"D",
)}
</EventDay>
<EventMonth>
{formatDate(
(item as EventFeedItem).event_details?.event_datetime,
"MMM",
)}
</EventMonth>
</EventDate>
<EventTitle>{item.title}</EventTitle>
<Chevron />
</Card.Content>
</EventCard>
)) || []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,16 @@ import React from "react"
import { faker } from "@faker-js/faker/locale/en"
import { factories, urls } from "api/test-utils"
import { manageListDialogs } from "@/page-components/ManageListDialogs/ManageListDialogs"
import LearningResourceCardTemplate from "@/page-components/LearningResourceCardTemplate/LearningResourceCardTemplate"
import LearningPathListingPage from "./LearningPathListingPage"
import {
screen,
renderWithProviders,
setMockResponse,
user,
expectProps,
waitFor,
} from "../../test-utils"
import type { User } from "../../types/settings"

jest.mock(
"../../page-components/LearningResourceCardTemplate/LearningResourceCardTemplate",
() => {
const actual = jest.requireActual(
"../../page-components/LearningResourceCardTemplate/LearningResourceCardTemplate",
)
return {
__esModule: true,
...actual,
default: jest.fn(actual.default),
}
},
)
const spyLRCardTemplate = jest.mocked(LearningResourceCardTemplate)

/**
* Set up the mock API responses for lists pages.
*/
Expand Down Expand Up @@ -67,10 +50,6 @@ describe("LearningPathListingPage", () => {
// for sanity
expect(headings.length).toBeGreaterThan(0)
expect(titles.length).toBe(headings.length)

paths.results.forEach((resource) => {
expectProps(spyLRCardTemplate, { resource })
})
})

it.each([
Expand Down
Loading
Loading