Skip to content

refactor: remove references of ENABLE_HOME_PAGE_COURSE_API_V2 #1611

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ HOTJAR_APP_ID=''
HOTJAR_VERSION=6
HOTJAR_DEBUG=false
INVITE_STUDENTS_EMAIL_TO=''
ENABLE_HOME_PAGE_COURSE_API_V2=true
ENABLE_CHECKLIST_QUALITY=''
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
# "Multi-level" blocks are unsupported in libraries
Expand Down
1 change: 0 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ HOTJAR_APP_ID=''
HOTJAR_VERSION=6
HOTJAR_DEBUG=true
INVITE_STUDENTS_EMAIL_TO="someone@domain.com"
ENABLE_HOME_PAGE_COURSE_API_V2=true
ENABLE_CHECKLIST_QUALITY=true
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
# "Multi-level" blocks are unsupported in libraries
Expand Down
1 change: 0 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ initialize({
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN: process.env.ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN || 'false',
ENABLE_CERTIFICATE_PAGE: process.env.ENABLE_CERTIFICATE_PAGE || 'false',
ENABLE_TAGGING_TAXONOMY_PAGES: process.env.ENABLE_TAGGING_TAXONOMY_PAGES || 'false',
ENABLE_HOME_PAGE_COURSE_API_V2: process.env.ENABLE_HOME_PAGE_COURSE_API_V2 === 'true',
ENABLE_CHECKLIST_QUALITY: process.env.ENABLE_CHECKLIST_QUALITY || 'true',
ENABLE_GRADING_METHOD_IN_PROBLEMS: process.env.ENABLE_GRADING_METHOD_IN_PROBLEMS === 'true',
LIBRARY_UNSUPPORTED_BLOCKS: (process.env.LIBRARY_UNSUPPORTED_BLOCKS || 'conditional,step-builder,problem-builder').split(','),
Expand Down
2 changes: 0 additions & 2 deletions src/studio-home/StudioHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const StudioHome = () => {
const location = useLocation();
const navigate = useNavigate();

const isPaginationCoursesEnabled = getConfig().ENABLE_HOME_PAGE_COURSE_API_V2;
const {
isLoadingPage,
isFailedLoadingPage,
Expand Down Expand Up @@ -153,7 +152,6 @@ const StudioHome = () => {
showNewCourseContainer={showNewCourseContainer}
onClickNewCourse={() => setShowNewCourseContainer(true)}
isShowProcessing={isShowProcessing && !isFiltered}
isPaginationCoursesEnabled={isPaginationCoursesEnabled}
librariesV1Enabled={librariesV1Enabled}
librariesV2Enabled={librariesV2Enabled}
/>
Expand Down
8 changes: 5 additions & 3 deletions src/studio-home/card-item/CardItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ describe('<CardItem />', () => {
render(<CardItem {...props} />);
const courseTitleLink = screen.getByText(props.displayName);
expect(courseTitleLink).toHaveAttribute('href', `${getConfig().STUDIO_BASE_URL}${props.url}`);
const dropDownMenu = screen.getByRole('button', { name: /course actions/i });
fireEvent.click(dropDownMenu);
const btnReRunCourse = screen.getByText(messages.btnReRunText.defaultMessage);
expect(btnReRunCourse).toHaveAttribute('href', trimSlashes(props.rerunLink));
expect(btnReRunCourse).toHaveAttribute('href', props.rerunLink);
const viewLiveLink = screen.getByText(messages.viewLiveBtnText.defaultMessage);
expect(viewLiveLink).toHaveAttribute('href', props.lmsLink);
});

it('should render correct links for non-library course pagination', () => {
const props = studioHomeMock.archivedCourses[0];
render(<CardItem {...props} isPaginated />);
render(<CardItem {...props} />);
const courseTitleLink = screen.getByText(props.displayName);
expect(courseTitleLink).toHaveAttribute('href', `${getConfig().STUDIO_BASE_URL}${props.url}`);
const dropDownMenu = screen.getByTestId('toggle-dropdown');
const dropDownMenu = screen.getByRole('button', { name: /course actions/i });
fireEvent.click(dropDownMenu);
const btnReRunCourse = screen.getByText(messages.btnReRunText.defaultMessage);
expect(btnReRunCourse).toHaveAttribute('href', `/${trimSlashes(props.rerunLink)}`);
Expand Down
66 changes: 20 additions & 46 deletions src/studio-home/card-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import React from 'react';
import { useSelector } from 'react-redux';
import {
Card,
Hyperlink,
Dropdown,
IconButton,
ActionRow,
} from '@openedx/paragon';
import { MoreHoriz } from '@openedx/paragon/icons';
import { useIntl } from '@edx/frontend-platform/i18n';
Expand All @@ -16,7 +14,6 @@ import { getWaffleFlags } from '../../data/selectors';
import { COURSE_CREATOR_STATES } from '../../constants';
import { getStudioHomeData } from '../data/selectors';
import messages from '../messages';
import { trimSlashes } from './utils';

interface BaseProps {
displayName: string;
Expand All @@ -27,7 +24,6 @@ interface BaseProps {
rerunLink?: string | null;
courseKey?: string;
isLibraries?: boolean;
isPaginated?: boolean;
}
type Props = BaseProps & (
/** If we should open this course/library in this MFE, this is the path to the edit page, e.g. '/course/foo' */
Expand All @@ -51,7 +47,6 @@ const CardItem: React.FC<Props> = ({
run = '',
isLibraries = false,
courseKey = '',
isPaginated = false,
path,
url,
}) => {
Expand Down Expand Up @@ -92,48 +87,27 @@ const CardItem: React.FC<Props> = ({
)}
subtitle={subtitle}
actions={showActions && (
isPaginated ? (
<Dropdown>
<Dropdown.Toggle
as={IconButton}
iconAs={MoreHoriz}
variant="primary"
data-testid="toggle-dropdown"
/>
<Dropdown.Menu>
{isShowRerunLink && (
<Dropdown.Item
as={Link}
to={rerunLink ?? ''}
>
{messages.btnReRunText.defaultMessage}
</Dropdown.Item>
)}
<Dropdown.Item href={lmsLink}>
{intl.formatMessage(messages.viewLiveBtnText)}
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
) : (
<ActionRow>
{isShowRerunLink && (
<Hyperlink
className="small"
destination={trimSlashes(rerunLink ?? '')}
key={`action-row-rerunLink-${courseKey}`}
>
{intl.formatMessage(messages.btnReRunText)}
</Hyperlink>
)}
<Hyperlink
className="small ml-3"
destination={lmsLink ?? ''}
key={`action-row-lmsLink-${courseKey}`}
<Dropdown>
<Dropdown.Toggle
as={IconButton}
iconAs={MoreHoriz}
variant="primary"
aria-label={intl.formatMessage(messages.btnDropDownText)}
/>
<Dropdown.Menu>
{isShowRerunLink && (
<Dropdown.Item
as={Link}
to={rerunLink ?? ''}
>
{intl.formatMessage(messages.viewLiveBtnText)}
</Hyperlink>
</ActionRow>
)
{messages.btnReRunText.defaultMessage}
</Dropdown.Item>
)}
<Dropdown.Item href={lmsLink}>
{intl.formatMessage(messages.viewLiveBtnText)}
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
)}
/>
</Card>
Expand Down
10 changes: 5 additions & 5 deletions src/studio-home/data/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getStudioHomeLibraries,
} from './api';
import {
generateGetStudioCoursesApiResponse,
generateGetStudioCoursesApiResponseV2,
generateGetStudioHomeDataApiResponse,
generateGetStudioHomeLibrariesApiResponse,
} from '../factories/mockApiResponses';
Expand Down Expand Up @@ -50,19 +50,19 @@ describe('studio-home api calls', () => {

it('should get studio courses data', async () => {
const apiLink = `${getApiBaseUrl()}/api/contentstore/v1/home/courses`;
axiosMock.onGet(apiLink).reply(200, generateGetStudioCoursesApiResponse());
axiosMock.onGet(apiLink).reply(200, generateGetStudioCoursesApiResponseV2());
const result = await getStudioHomeCourses('');
const expected = generateGetStudioCoursesApiResponse();
const expected = generateGetStudioCoursesApiResponseV2();

expect(axiosMock.history.get[0].url).toEqual(apiLink);
expect(result).toEqual(expected);
});

it('should get studio courses data v2', async () => {
const apiLink = `${getApiBaseUrl()}/api/contentstore/v2/home/courses`;
axiosMock.onGet(apiLink).reply(200, generateGetStudioCoursesApiResponse());
axiosMock.onGet(apiLink).reply(200, generateGetStudioCoursesApiResponseV2());
const result = await getStudioHomeCoursesV2('');
const expected = generateGetStudioCoursesApiResponse();
const expected = generateGetStudioCoursesApiResponseV2();

expect(axiosMock.history.get[0].url).toEqual(apiLink);
expect(result).toEqual(expected);
Expand Down
24 changes: 15 additions & 9 deletions src/studio-home/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { createSlice } from '@reduxjs/toolkit';

import { RequestStatus } from '../../data/constants';

export const studioHomeCoursesRequestParamsDefault = {
currentPage: 1,
search: '',
order: 'display_name',
archivedOnly: undefined,
activeOnly: undefined,
isFiltered: false,
cleanFilters: false,
};

const slice = createSlice({
name: 'studioHome',
initialState: {
Expand All @@ -17,15 +27,7 @@ const slice = createSlice({
deleteNotificationSavingStatus: '',
},
studioHomeData: {},
studioHomeCoursesRequestParams: {
currentPage: 1,
search: undefined,
order: 'display_name',
archivedOnly: undefined,
activeOnly: undefined,
isFiltered: false,
cleanFilters: false,
},
studioHomeCoursesRequestParams: studioHomeCoursesRequestParamsDefault,
},
reducers: {
updateLoadingStatuses: (state, { payload }) => {
Expand Down Expand Up @@ -59,6 +61,9 @@ const slice = createSlice({
updateStudioHomeCoursesCustomParams: (state, { payload }) => {
Object.assign(state.studioHomeCoursesRequestParams, payload);
},
resetStudioHomeCoursesCustomParams: (state) => {
state.studioHomeCoursesRequestParams = studioHomeCoursesRequestParamsDefault;
},
},
});

Expand All @@ -70,6 +75,7 @@ export const {
fetchCourseDataSuccessV2,
fetchLibraryDataSuccess,
updateStudioHomeCoursesCustomParams,
resetStudioHomeCoursesCustomParams,
} = slice.actions;

export const {
Expand Down
56 changes: 32 additions & 24 deletions src/studio-home/data/slice.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reducer, updateStudioHomeCoursesCustomParams } from './slice';
import { reducer, resetStudioHomeCoursesCustomParams, updateStudioHomeCoursesCustomParams } from './slice';

import { RequestStatus } from '../../data/constants';

Expand All @@ -17,7 +17,7 @@ describe('updateStudioHomeCoursesCustomParams action', () => {
studioHomeData: {},
studioHomeCoursesRequestParams: {
currentPage: 1,
search: undefined,
search: '',
order: 'display_name',
archivedOnly: undefined,
activeOnly: undefined,
Expand All @@ -26,36 +26,44 @@ describe('updateStudioHomeCoursesCustomParams action', () => {
},
};

it('should return the initial state', () => {
const result = reducer(undefined, { type: undefined });
expect(result).toEqual(initialState);
});

it('should update the payload passed in studioHomeCoursesRequestParams', () => {
const newState = {
...initialState,
studioHomeCoursesRequestParams: {
currentPage: 2,
search: 'test',
order: 'display_name',
archivedOnly: true,
activeOnly: true,
isFiltered: true,
cleanFilters: true,
},
};

const payload = {
const modifiedRequestParamsState = {
...initialState,
studioHomeCoursesRequestParams: {
currentPage: 2,
search: 'test',
order: 'display_name',
archivedOnly: true,
activeOnly: true,
isFiltered: true,
cleanFilters: true,
};
},
};

const payload = {
currentPage: 2,
search: 'test',
order: 'display_name',
archivedOnly: true,
activeOnly: true,
isFiltered: true,
cleanFilters: true,
};

it('should return the initial state', () => {
const result = reducer(undefined, { type: undefined });
expect(result).toEqual(initialState);
});

it('should update the payload passed in studioHomeCoursesRequestParams', () => {
const result = reducer(initialState, updateStudioHomeCoursesCustomParams(payload));
expect(result).toEqual(newState);
expect(result).toEqual(modifiedRequestParamsState);
});

it('should reset the studioHomeCoursesRequestParams state to the initial value', () => {
const stateChanged = reducer(initialState, updateStudioHomeCoursesCustomParams(payload));
expect(stateChanged).toEqual(modifiedRequestParamsState);

const stateReset = reducer(stateChanged, resetStudioHomeCoursesCustomParams());
expect(stateReset.studioHomeCoursesRequestParams).toEqual(initialState.studioHomeCoursesRequestParams);
});
});
13 changes: 2 additions & 11 deletions src/studio-home/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import {
getStudioHomeData,
sendRequestForCourseCreator,
handleCourseNotification,
getStudioHomeCourses,
getStudioHomeLibraries,
getStudioHomeCoursesV2,
} from './api';
import {
fetchStudioHomeDataSuccess,
fetchCourseDataSuccess,
updateLoadingStatuses,
updateSavingStatuses,
fetchLibraryDataSuccess,
Expand All @@ -20,7 +18,6 @@ function fetchStudioHomeData(
search,
hasHomeData,
requestParams = {},
isPaginationEnabled = false,
shouldFetchCourses = true,
) {
return async (dispatch) => {
Expand All @@ -39,14 +36,8 @@ function fetchStudioHomeData(
if (shouldFetchCourses) {
dispatch(updateLoadingStatuses({ courseLoadingStatus: RequestStatus.IN_PROGRESS }));
try {
if (isPaginationEnabled) {
const coursesData = await getStudioHomeCoursesV2(search || '', requestParams);
dispatch(fetchCourseDataSuccessV2(coursesData));
} else {
const coursesData = await getStudioHomeCourses(search || '');
dispatch(fetchCourseDataSuccess(coursesData));
}

const coursesData = await getStudioHomeCoursesV2(search || '', requestParams);
dispatch(fetchCourseDataSuccessV2(coursesData));
dispatch(updateLoadingStatuses({ courseLoadingStatus: RequestStatus.SUCCESSFUL }));
} catch (error) {
dispatch(updateLoadingStatuses({ courseLoadingStatus: RequestStatus.FAILED }));
Expand Down
Loading