-
Notifications
You must be signed in to change notification settings - Fork 196
feat: add course import page [FC-0112] #2580
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
Changes from 1 commit
ca3c068
868084d
9a97f25
262754c
42a31b0
85834d1
f17820b
b843763
0878749
cab000a
ab24e7c
73948ab
fc79cb1
6b3827b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,10 @@ export const libraryAuthoringQueryKeys = { | |
| } | ||
| return ['hierarchy']; | ||
| }, | ||
| migrations: (libraryId: string) => [ | ||
|
ChrisChV marked this conversation as resolved.
Outdated
|
||
| ...libraryAuthoringQueryKeys.contentLibrary(libraryId), | ||
| 'migrations', | ||
|
Contributor
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. Same here. Rename to import. |
||
| ], | ||
| }; | ||
|
|
||
| export const xblockQueryKeys = { | ||
|
|
@@ -951,3 +955,13 @@ export const useContentFromSearchIndex = (contentIds: string[]) => { | |
| skipBlockTypeFetch: true, | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Returns the course migrations which had this library as destination. | ||
| */ | ||
| export const useCourseMigrations = (libraryId: string) => ( | ||
| useQuery({ | ||
| queryKey: libraryAuthoringQueryKeys.migrations(libraryId), | ||
| queryFn: () => api.getCourseMigrations(libraryId), | ||
| }) | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { | ||
| initializeMocks, | ||
| render as testRender, | ||
| screen, | ||
| } from '@src/testUtils'; | ||
|
|
||
| import { LibraryProvider } from '../common/context/LibraryContext'; | ||
| import { | ||
| mockContentLibrary, | ||
| mockGetCourseMigrations, | ||
| } from '../data/api.mocks'; | ||
| import { CourseImportHomePage } from './CourseImportHomePage'; | ||
|
|
||
| initializeMocks(); | ||
|
ChrisChV marked this conversation as resolved.
Outdated
|
||
| mockContentLibrary.applyMock(); | ||
| mockGetCourseMigrations.applyMock(); | ||
|
|
||
| const mockNavigate = jest.fn(); | ||
| jest.mock('react-router-dom', () => ({ | ||
| ...jest.requireActual('react-router-dom'), | ||
| useNavigate: () => mockNavigate, | ||
| })); | ||
|
|
||
| const render = (libraryId: string) => ( | ||
| testRender( | ||
| <CourseImportHomePage />, | ||
| { | ||
| extraWrapper: ({ children }: { children: React.ReactNode }) => ( | ||
| <LibraryProvider libraryId={libraryId}> | ||
| {children} | ||
| </LibraryProvider> | ||
| ), | ||
| path: '/libraries/:libraryId/import-course', | ||
| params: { libraryId }, | ||
| }, | ||
| ) | ||
| ); | ||
|
|
||
| describe('<CourseImportHomePage>', () => { | ||
| it('should render the library course import home page', async () => { | ||
| render(mockGetCourseMigrations.libraryId); | ||
| expect(await screen.findByRole('heading', { name: /Tools.*Import/ })).toBeInTheDocument(); // Header | ||
| expect(screen.getByRole('heading', { name: 'Previous Imports' })).toBeInTheDocument(); | ||
| expect(screen.queryAllByRole('link', { name: /DemoX 2025 T[0-5]/ })).toHaveLength(4); | ||
|
ChrisChV marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| it('should render the empty state', async () => { | ||
| render(mockGetCourseMigrations.emptyLibraryId); | ||
| expect(await screen.findByRole('heading', { name: /Tools.*Import/ })).toBeInTheDocument(); // Header | ||
| expect(screen.queryByRole('heading', { name: 'Previous Imports' })).not.toBeInTheDocument(); | ||
| expect(screen.queryByText('You have not imported any courses into this library.')).toBeInTheDocument(); | ||
|
ChrisChV marked this conversation as resolved.
Outdated
|
||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,96 @@ | ||||||||
| import { | ||||||||
| Button, | ||||||||
| Card, | ||||||||
| Container, | ||||||||
| Layout, | ||||||||
| Stack, | ||||||||
| } from '@openedx/paragon'; | ||||||||
| import { Add } from '@openedx/paragon/icons'; | ||||||||
| import { Helmet } from 'react-helmet'; | ||||||||
|
|
||||||||
| import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n'; | ||||||||
| import NotFoundAlert from '@src/generic/NotFoundAlert'; | ||||||||
| import Loading from '@src/generic/Loading'; | ||||||||
| import SubHeader from '@src/generic/sub-header/SubHeader'; | ||||||||
| import Header from '@src/header'; | ||||||||
|
|
||||||||
| import { useLibraryContext } from '../common/context/LibraryContext'; | ||||||||
| import { useContentLibrary, useCourseMigrations } from '../data/apiHooks'; | ||||||||
| import { HelpSidebar } from './HelpSidebar'; | ||||||||
| import { MigratedCourseCard } from './MigratedCourseCard'; | ||||||||
| import messages from './messages'; | ||||||||
|
|
||||||||
| const EmptyState = () => ( | ||||||||
| <Container size="md" className="py-6"> | ||||||||
| <Card> | ||||||||
| <Stack direction="horizontal" gap={3} className="my-6 justify-content-center"> | ||||||||
| <FormattedMessage {...messages.emptyStateText} /> | ||||||||
| <Button iconBefore={Add} disabled> | ||||||||
| <FormattedMessage {...messages.emptyStateButtonText} /> | ||||||||
| </Button> | ||||||||
| </Stack> | ||||||||
| </Card> | ||||||||
| </Container> | ||||||||
| ); | ||||||||
|
|
||||||||
| export const CourseImportHomePage = () => { | ||||||||
| const intl = useIntl(); | ||||||||
| const { libraryId } = useLibraryContext(); | ||||||||
| const { data: libraryData } = useContentLibrary(libraryId); | ||||||||
| const { data: courseMigrations } = useCourseMigrations(libraryId); | ||||||||
|
|
||||||||
| if (!courseMigrations) { | ||||||||
| return <Loading />; | ||||||||
| } | ||||||||
|
|
||||||||
| if (!libraryData) { | ||||||||
| return <NotFoundAlert />; | ||||||||
| } | ||||||||
|
|
||||||||
| return ( | ||||||||
| <div className="d-flex"> | ||||||||
| <div className="flex-grow-1"> | ||||||||
| <Helmet> | ||||||||
| <title>{libraryData.title} | {process.env.SITE_NAME}</title> | ||||||||
| </Helmet> | ||||||||
| <Header | ||||||||
| number={libraryData.slug} | ||||||||
| title={libraryData.title} | ||||||||
| org={libraryData.org} | ||||||||
| contextId={libraryId} | ||||||||
| isLibrary | ||||||||
|
Contributor
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. Pass
Suggested change
Contributor
Author
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. Thanks! Fixed here: f17820b |
||||||||
| containerProps={{ | ||||||||
| size: undefined, | ||||||||
| }} | ||||||||
| /> | ||||||||
| <Container className="px-0 mt-4 mb-5 library-authoring-page"> | ||||||||
|
Contributor
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.
Suggested change
Contributor
Author
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. Thanks! Fixed: ab24e7c |
||||||||
| <div className="px-4 bg-light-200 border-bottom"> | ||||||||
| <SubHeader | ||||||||
| title={intl.formatMessage(messages.pageTitle)} | ||||||||
| subtitle={intl.formatMessage(messages.pageSubtitle)} | ||||||||
| hideBorder | ||||||||
| /> | ||||||||
| </div> | ||||||||
| <Layout xs={[{ span: 9 }, { span: 3 }]}> | ||||||||
| <Layout.Element> | ||||||||
| {courseMigrations.length ? ( | ||||||||
| <Stack gap={3} className="pl-4 mt-4"> | ||||||||
| <h3>Previous Imports</h3> | ||||||||
|
ChrisChV marked this conversation as resolved.
Outdated
|
||||||||
| {courseMigrations.map((courseMigration) => ( | ||||||||
| <MigratedCourseCard | ||||||||
| key={courseMigration.source.key} | ||||||||
| courseMigration={courseMigration} | ||||||||
| /> | ||||||||
| ))} | ||||||||
| </Stack> | ||||||||
| ) : (<EmptyState />)} | ||||||||
| </Layout.Element> | ||||||||
| <Layout.Element> | ||||||||
| <HelpSidebar /> | ||||||||
| </Layout.Element> | ||||||||
| </Layout> | ||||||||
| </Container> | ||||||||
| </div> | ||||||||
| </div> | ||||||||
| ); | ||||||||
| }; | ||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||
| import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||||||
| import { Icon, Stack } from '@openedx/paragon'; | ||||||
| import { Question } from '@openedx/paragon/icons'; | ||||||
| import { Paragraph } from '@src/utils'; | ||||||
|
|
||||||
| import messages from './messages'; | ||||||
|
|
||||||
| export const HelpSidebar = () => ( | ||||||
| <div className="course-migration-help pt-3 border-left"> | ||||||
|
Contributor
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.
Suggested change
Contributor
Author
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. Fixed cab000a |
||||||
| <Stack gap={1} direction="horizontal" className="pl-4 h4 text-primary-700"> | ||||||
| <Icon src={Question} /> | ||||||
| <span> | ||||||
| <FormattedMessage {...messages.helpAndSupportTitle} /> | ||||||
| </span> | ||||||
| </Stack> | ||||||
| <hr /> | ||||||
| <Stack className="pl-4 pr-4"> | ||||||
| <Stack> | ||||||
| <span className="h5"> | ||||||
| <FormattedMessage {...messages.helpAndSupportFirstQuestionTitle} /> | ||||||
| </span> | ||||||
| <span className="x-small"> | ||||||
| <FormattedMessage | ||||||
| {...messages.helpAndSupportFirstQuestionBody} | ||||||
| values={{ p: Paragraph }} | ||||||
| /> | ||||||
| </span> | ||||||
| </Stack> | ||||||
| <hr /> | ||||||
| <Stack> | ||||||
| <span className="h5"> | ||||||
| <FormattedMessage {...messages.helpAndSupportSecondQuestionTitle} /> | ||||||
| </span> | ||||||
| <span className="x-small"> | ||||||
| <FormattedMessage | ||||||
| {...messages.helpAndSupportSecondQuestionBody} | ||||||
| values={{ p: Paragraph }} | ||||||
| /> | ||||||
| </span> | ||||||
| </Stack> | ||||||
| <hr /> | ||||||
|
Contributor
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.
Suggested change
Contributor
Author
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. Fixed: cab000a |
||||||
| </Stack> | ||||||
| </div> | ||||||
| ); | ||||||
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.
NIT: rename to indicate import instead of migration