Skip to content

Commit 0d8b4b5

Browse files
committed
refactor: Updates in CourseLibraries
1 parent 1c0c9f4 commit 0d8b4b5

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

src/CourseAuthoringRoutes.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import {
32
Navigate, Routes, Route, useParams,
43
} from 'react-router-dom';
@@ -62,7 +61,7 @@ const CourseAuthoringRoutes = () => {
6261
/>
6362
<Route
6463
path="libraries"
65-
element={<PageWrap><CourseLibraries courseId={courseId} /></PageWrap>}
64+
element={<PageWrap><CourseLibraries /></PageWrap>}
6665
/>
6766
<Route
6867
path="assets"

src/course-libraries/CourseLibraries.test.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ import {
99
screen,
1010
waitFor,
1111
within,
12-
} from '../testUtils';
13-
import { mockContentSearchConfig } from '../search-manager/data/api.mock';
12+
} from '@src/testUtils';
13+
import { mockContentSearchConfig } from '@src/search-manager/data/api.mock';
14+
import { type ToastActionData } from '@src/generic/toast-context';
1415
import { CourseLibraries } from './CourseLibraries';
1516
import {
1617
mockGetEntityLinks,
1718
mockGetEntityLinksSummaryByDownstreamContext,
1819
mockFetchIndexDocuments,
1920
mockUseLibBlockMetadata,
2021
} from './data/api.mocks';
21-
import { libraryBlockChangesUrl } from '../course-unit/data/api';
22-
import { type ToastActionData } from '../generic/toast-context';
22+
import { libraryBlockChangesUrl } from '@src/course-unit/data/api';
23+
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
2324

2425
mockContentSearchConfig.applyMock();
2526
mockGetEntityLinks.applyMock();
@@ -58,7 +59,11 @@ describe('<CourseLibraries />', () => {
5859

5960
const renderCourseLibrariesPage = async (courseKey?: string) => {
6061
const courseId = courseKey || mockGetEntityLinks.courseKey;
61-
render(<CourseLibraries courseId={courseId} />);
62+
render(
63+
<CourseAuthoringProvider courseId={courseId}>
64+
<CourseLibraries />
65+
</CourseAuthoringProvider>
66+
);
6267
};
6368

6469
it('shows the spinner before the query is complete', async () => {
@@ -176,7 +181,11 @@ describe('<CourseLibraries ReviewTab />', () => {
176181

177182
const renderCourseLibrariesReviewPage = async (courseKey?: string) => {
178183
const courseId = courseKey || mockGetEntityLinks.courseKey;
179-
render(<CourseLibraries courseId={courseId} />);
184+
render(
185+
<CourseAuthoringProvider courseId={courseId}>
186+
<CourseLibraries />
187+
</CourseAuthoringProvider>
188+
);
180189
};
181190

182191
it('shows the spinner before the query is complete', async () => {

src/course-libraries/CourseLibraries.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ import { useStudioHome } from '../studio-home/hooks';
3333
import NewsstandIcon from '../generic/NewsstandIcon';
3434
import ReviewTabContent from './ReviewTabContent';
3535
import { OutOfSyncAlert } from './OutOfSyncAlert';
36-
37-
interface Props {
38-
courseId: string;
39-
}
36+
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
4037

4138
interface LibraryCardProps {
4239
linkSummary: PublishableEntityLinkSummary;
@@ -100,9 +97,9 @@ const LibraryCard = ({ linkSummary }: LibraryCardProps) => {
10097
);
10198
};
10299

103-
export const CourseLibraries: React.FC<Props> = ({ courseId }) => {
100+
export const CourseLibraries = () => {
104101
const intl = useIntl();
105-
const courseDetails = useModel('courseDetails', courseId);
102+
const { courseId, courseDetails } = useCourseAuthoringContext();
106103
const [searchParams] = useSearchParams();
107104
const [tabKey, setTabKey] = useState<CourseLibraryTabs>(
108105
() => searchParams.get('tab') as CourseLibraryTabs,
@@ -189,7 +186,7 @@ export const CourseLibraries: React.FC<Props> = ({ courseId }) => {
189186
<>
190187
<Helmet>
191188
<title>
192-
{getPageHeadTitle(courseDetails?.name, intl.formatMessage(messages.headingTitle))}
189+
{getPageHeadTitle(courseDetails?.name || '', intl.formatMessage(messages.headingTitle))}
193190
</title>
194191
</Helmet>
195192
<Container size="xl" className="px-4 pt-4 mt-3">

0 commit comments

Comments
 (0)