Skip to content

Commit 59c992f

Browse files
chore: run oxfmt
1 parent 83c8307 commit 59c992f

1,630 files changed

Lines changed: 29067 additions & 36323 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/CourseAuthoringContext.tsx

Lines changed: 62 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { getConfig } from '@edx/frontend-platform';
2-
import {
3-
createContext, useContext, useMemo, useState,
4-
} from 'react';
2+
import { createContext, useContext, useMemo, useState } from 'react';
53
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
64
import { useCreateCourseBlock } from '@src/course-outline/data/apiHooks';
75
import { useSelector } from 'react-redux';
@@ -56,35 +54,24 @@ type CourseAuthoringProviderProps = {
5654
courseId: string;
5755
};
5856

59-
export const CourseAuthoringProvider = ({
60-
children,
61-
courseId,
62-
}: CourseAuthoringProviderProps) => {
57+
export const CourseAuthoringProvider = ({ children, courseId }: CourseAuthoringProviderProps) => {
6358
const navigate = useNavigate();
6459
const waffleFlags = useWaffleFlags();
6560
const { data: courseDetails, status: courseDetailStatus } = useCourseDetails(courseId);
6661
const canChangeProviders = getAuthenticatedUser().administrator || new Date(courseDetails?.start ?? 0) > new Date();
6762
const { courseStructure } = useSelector(getOutlineIndexData);
6863
const { id: courseUsageKey } = courseStructure || {};
69-
const [
70-
isUnlinkModalOpen,
71-
currentUnlinkModalData,
72-
openUnlinkModal,
73-
closeUnlinkModal,
74-
] = useToggleWithValue<ModalState>();
75-
const [
76-
isPublishModalOpen,
77-
currentPublishModalData,
78-
openPublishModal,
79-
closePublishModal,
80-
] = useToggleWithValue<ModalState>();
64+
const [isUnlinkModalOpen, currentUnlinkModalData, openUnlinkModal, closeUnlinkModal] =
65+
useToggleWithValue<ModalState>();
66+
const [isPublishModalOpen, currentPublishModalData, openPublishModal, closePublishModal] =
67+
useToggleWithValue<ModalState>();
8168
/**
82-
* This will hold the state of current item that is being operated on,
83-
* For example:
84-
* - the details of container that is being edited.
85-
* - the details of container of which see more dropdown is open.
86-
* It is mostly used in modals which should be soon be replaced with its equivalent in sidebar.
87-
*/
69+
* This will hold the state of current item that is being operated on,
70+
* For example:
71+
* - the details of container that is being edited.
72+
* - the details of container of which see more dropdown is open.
73+
* It is mostly used in modals which should be soon be replaced with its equivalent in sidebar.
74+
*/
8875
const [currentSelection, setCurrentSelection] = useState<SelectionState | undefined>();
8976

9077
const getUnitUrl = (locator: string) => {
@@ -108,65 +95,66 @@ export const CourseAuthoringProvider = ({
10895
}
10996
};
11097
/**
111-
* import a unit block from library and redirect user to this unit page.
112-
*/
98+
* import a unit block from library and redirect user to this unit page.
99+
*/
113100
const handleAddAndOpenUnit = useCreateCourseBlock(courseId, openUnitPage);
114101
const handleAddBlock = useCreateCourseBlock(courseId);
115102

116-
const context = useMemo<CourseAuthoringContextData>(() => ({
117-
courseId,
118-
courseUsageKey,
119-
courseDetails,
120-
courseDetailStatus,
121-
canChangeProviders,
122-
handleAddBlock,
123-
handleAddAndOpenUnit,
124-
getUnitUrl,
125-
openUnitPage,
126-
isUnlinkModalOpen,
127-
openUnlinkModal,
128-
closeUnlinkModal,
129-
currentUnlinkModalData,
130-
isPublishModalOpen,
131-
currentPublishModalData,
132-
openPublishModal,
133-
closePublishModal,
134-
currentSelection,
135-
setCurrentSelection,
136-
}), [
137-
courseId,
138-
courseUsageKey,
139-
courseDetails,
140-
courseDetailStatus,
141-
canChangeProviders,
142-
handleAddBlock,
143-
handleAddAndOpenUnit,
144-
getUnitUrl,
145-
openUnitPage,
146-
isUnlinkModalOpen,
147-
openUnlinkModal,
148-
closeUnlinkModal,
149-
currentUnlinkModalData,
150-
isPublishModalOpen,
151-
currentPublishModalData,
152-
openPublishModal,
153-
closePublishModal,
154-
currentSelection,
155-
setCurrentSelection,
156-
]);
157-
158-
return (
159-
<CourseAuthoringContext.Provider value={context}>
160-
{children}
161-
</CourseAuthoringContext.Provider>
103+
const context = useMemo<CourseAuthoringContextData>(
104+
() => ({
105+
courseId,
106+
courseUsageKey,
107+
courseDetails,
108+
courseDetailStatus,
109+
canChangeProviders,
110+
handleAddBlock,
111+
handleAddAndOpenUnit,
112+
getUnitUrl,
113+
openUnitPage,
114+
isUnlinkModalOpen,
115+
openUnlinkModal,
116+
closeUnlinkModal,
117+
currentUnlinkModalData,
118+
isPublishModalOpen,
119+
currentPublishModalData,
120+
openPublishModal,
121+
closePublishModal,
122+
currentSelection,
123+
setCurrentSelection,
124+
}),
125+
[
126+
courseId,
127+
courseUsageKey,
128+
courseDetails,
129+
courseDetailStatus,
130+
canChangeProviders,
131+
handleAddBlock,
132+
handleAddAndOpenUnit,
133+
getUnitUrl,
134+
openUnitPage,
135+
isUnlinkModalOpen,
136+
openUnlinkModal,
137+
closeUnlinkModal,
138+
currentUnlinkModalData,
139+
isPublishModalOpen,
140+
currentPublishModalData,
141+
openPublishModal,
142+
closePublishModal,
143+
currentSelection,
144+
setCurrentSelection,
145+
],
162146
);
147+
148+
return <CourseAuthoringContext.Provider value={context}>{children}</CourseAuthoringContext.Provider>;
163149
};
164150

165151
export function useCourseAuthoringContext(): CourseAuthoringContextData {
166152
const ctx = useContext(CourseAuthoringContext);
167153
if (ctx === undefined) {
168154
/* istanbul ignore next */
169-
throw new Error('useCourseAuthoringContext() was used in a component without a <CourseAuthoringProvider> ancestor.');
155+
throw new Error(
156+
'useCourseAuthoringContext() was used in a component without a <CourseAuthoringProvider> ancestor.',
157+
);
170158
}
171159
return ctx;
172160
}

src/CourseAuthoringPage.test.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@ jest.mock('react-router-dom', () => ({
1919
let axiosMock;
2020
let store;
2121

22-
const renderComponent = children => render(
23-
<CourseAuthoringProvider courseId={courseId}>
24-
{children}
25-
</CourseAuthoringProvider>,
26-
);
22+
const renderComponent = (children) =>
23+
render(<CourseAuthoringProvider courseId={courseId}>{children}</CourseAuthoringProvider>);
2724

2825
beforeEach(async () => {
2926
const mocks = initializeMocks();
3027
store = mocks.reduxStore;
3128
axiosMock = mocks.axiosMock;
32-
axiosMock
33-
.onGet(getApiWaffleFlagsUrl(courseId))
34-
.reply(200, {});
29+
axiosMock.onGet(getApiWaffleFlagsUrl(courseId)).reply(200, {});
3530
});
3631

3732
describe('Editor Pages Load no header', () => {
@@ -48,8 +43,7 @@ describe('Editor Pages Load no header', () => {
4843
const wrapper = renderComponent(
4944
<CourseAuthoringPage>
5045
<PagesAndResources />
51-
</CourseAuthoringPage>
52-
,
46+
</CourseAuthoringPage>,
5347
);
5448
expect(wrapper.queryByRole('status')).not.toBeInTheDocument();
5549
});
@@ -59,8 +53,7 @@ describe('Editor Pages Load no header', () => {
5953
const wrapper = renderComponent(
6054
<CourseAuthoringPage>
6155
<PagesAndResources />
62-
</CourseAuthoringPage>
63-
,
56+
</CourseAuthoringPage>,
6457
);
6558
expect(wrapper.queryByRole('status')).toBeInTheDocument();
6659
});
@@ -70,16 +63,12 @@ describe('Course authoring page', () => {
7063
const lmsApiBaseUrl = getConfig().LMS_BASE_URL;
7164
const courseDetailApiUrl = `${lmsApiBaseUrl}/api/courses/v1/courses`;
7265
const mockStoreNotFound = async () => {
73-
axiosMock.onGet(
74-
`${courseDetailApiUrl}/${courseId}?username=abc123`,
75-
).reply(404, {
66+
axiosMock.onGet(`${courseDetailApiUrl}/${courseId}?username=abc123`).reply(404, {
7667
response: { status: 404 },
7768
});
7869
};
7970
const mockStoreError = async () => {
80-
axiosMock.onGet(
81-
`${courseDetailApiUrl}/${courseId}?username=abc123`,
82-
).reply(500, {
71+
axiosMock.onGet(`${courseDetailApiUrl}/${courseId}?username=abc123`).reply(500, {
8372
response: { status: 500 },
8473
});
8574
};
@@ -98,8 +87,7 @@ describe('Course authoring page', () => {
9887
const wrapper = renderComponent(
9988
<CourseAuthoringPage>
10089
<div data-testid={contentTestId} />
101-
</CourseAuthoringPage>
102-
,
90+
</CourseAuthoringPage>,
10391
);
10492
expect(await wrapper.findByTestId(contentTestId)).toBeInTheDocument();
10593
expect(wrapper.queryByTestId('notFoundAlert')).not.toBeInTheDocument();
@@ -108,9 +96,7 @@ describe('Course authoring page', () => {
10896
const studioApiBaseUrl = getConfig().STUDIO_BASE_URL;
10997
const courseAppsApiUrl = `${studioApiBaseUrl}/api/course_apps/v1/apps`;
11098

111-
axiosMock.onGet(
112-
`${courseAppsApiUrl}/${courseId}`,
113-
).reply(403);
99+
axiosMock.onGet(`${courseAppsApiUrl}/${courseId}`).reply(403);
114100
await executeThunk(fetchCourseApps(courseId), store.dispatch);
115101
};
116102
test('renders PermissionDeniedAlert when courseAppsApiStatus is DENIED', async () => {

src/CourseAuthoringPage.tsx

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React, { useEffect } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33

4-
import {
5-
useLocation,
6-
} from 'react-router-dom';
4+
import { useLocation } from 'react-router-dom';
75
import { StudioFooterSlot } from '@edx/frontend-component-footer';
86
import Header from './header';
97
import NotFoundAlert from './generic/NotFoundAlert';
@@ -35,34 +33,30 @@ const CourseAuthoringPage = ({ children }: Props) => {
3533
const isEditor = pathname.includes('/editor');
3634

3735
if (courseDetailStatus === RequestStatus.NOT_FOUND && !isEditor) {
38-
return (
39-
<NotFoundAlert />
40-
);
36+
return <NotFoundAlert />;
4137
}
4238
if (courseAppsApiStatus === RequestStatus.DENIED) {
43-
return (
44-
<PermissionDeniedAlert />
45-
);
39+
return <PermissionDeniedAlert />;
4640
}
4741
return (
4842
<div>
4943
{/* While V2 Editors are temporarily served from their own pages
5044
using url pattern containing /editor/,
5145
we shouldn't have the header and footer on these pages.
5246
This functionality will be removed in TNL-9591 */}
53-
{inProgress ? !isEditor && <Loading />
54-
: (!isEditor && (
55-
<Header
56-
number={courseNumber}
57-
org={courseOrg}
58-
title={courseTitle}
59-
contextId={courseId}
60-
containerProps={{
61-
size: 'fluid',
62-
}}
63-
/>
64-
)
65-
)}
47+
{inProgress
48+
? !isEditor && <Loading />
49+
: !isEditor && (
50+
<Header
51+
number={courseNumber}
52+
org={courseOrg}
53+
title={courseTitle}
54+
contextId={courseId}
55+
containerProps={{
56+
size: 'fluid',
57+
}}
58+
/>
59+
)}
6660
{children}
6761
{!inProgress && !isEditor && <StudioFooterSlot />}
6862
</div>

src/CourseAuthoringRoutes.test.tsx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import CourseAuthoringRoutes from './CourseAuthoringRoutes';
22
import { getApiWaffleFlagsUrl } from './data/api';
3-
import {
4-
screen, initializeMocks, render, waitFor,
5-
} from './testUtils';
3+
import { screen, initializeMocks, render, waitFor } from './testUtils';
64

75
const courseId = 'course-v1:edX+TestX+Test_Course';
86
const pagesAndResourcesMockText = 'Pages And Resources';
@@ -53,27 +51,19 @@ describe('<CourseAuthoringRoutes>', () => {
5351
username: 'username',
5452
};
5553
const { axiosMock } = initializeMocks({ user });
56-
axiosMock
57-
.onGet(getApiWaffleFlagsUrl(courseId))
58-
.reply(200, {});
54+
axiosMock.onGet(getApiWaffleFlagsUrl(courseId)).reply(200, {});
5955
});
6056

6157
it('renders the PagesAndResources component when the pages and resources route is active', async () => {
62-
render(
63-
<CourseAuthoringRoutes />,
64-
{ routerProps: { initialEntries: ['/pages-and-resources'] } },
65-
);
58+
render(<CourseAuthoringRoutes />, { routerProps: { initialEntries: ['/pages-and-resources'] } });
6659
await waitFor(() => {
6760
expect(screen.getByText(pagesAndResourcesMockText)).toBeVisible();
6861
expect(mockComponentFn).toHaveBeenCalled();
6962
});
7063
});
7164

7265
it('renders the EditorContainer component when the course editor route is active', async () => {
73-
render(
74-
<CourseAuthoringRoutes />,
75-
{ routerProps: { initialEntries: ['/editor/video/block-id'] } },
76-
);
66+
render(<CourseAuthoringRoutes />, { routerProps: { initialEntries: ['/editor/video/block-id'] } });
7767
await waitFor(() => {
7868
expect(screen.queryByText(editorContainerMockText)).toBeInTheDocument();
7969
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();
@@ -86,10 +76,7 @@ describe('<CourseAuthoringRoutes>', () => {
8676
});
8777

8878
it('renders the VideoSelectorContainer component when the course videos route is active', async () => {
89-
render(
90-
<CourseAuthoringRoutes />,
91-
{ routerProps: { initialEntries: ['/editor/course-videos/block-id'] } },
92-
);
79+
render(<CourseAuthoringRoutes />, { routerProps: { initialEntries: ['/editor/course-videos/block-id'] } });
9380
await waitFor(() => {
9481
expect(screen.queryByText(videoSelectorContainerMockText)).toBeInTheDocument();
9582
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();

0 commit comments

Comments
 (0)