refactor: Migrate courseExport from redux store to React Query (#2908)
This commit is contained in:
@@ -32,6 +32,7 @@ import { CourseLibraries } from './course-libraries';
|
|||||||
import { IframeProvider } from './generic/hooks/context/iFrameContext';
|
import { IframeProvider } from './generic/hooks/context/iFrameContext';
|
||||||
import { CourseAuthoringProvider } from './CourseAuthoringContext';
|
import { CourseAuthoringProvider } from './CourseAuthoringContext';
|
||||||
import { CourseImportProvider } from './import-page/CourseImportContext';
|
import { CourseImportProvider } from './import-page/CourseImportContext';
|
||||||
|
import { CourseExportProvider } from './export-page/CourseExportContext';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* As of this writing, these routes are mounted at a path prefixed with the following:
|
* As of this writing, these routes are mounted at a path prefixed with the following:
|
||||||
@@ -152,7 +153,13 @@ const CourseAuthoringRoutes = () => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="export"
|
path="export"
|
||||||
element={<PageWrap><CourseExportPage /></PageWrap>}
|
element={(
|
||||||
|
<PageWrap>
|
||||||
|
<CourseExportProvider>
|
||||||
|
<CourseExportPage />
|
||||||
|
</CourseExportProvider>
|
||||||
|
</PageWrap>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="optimizer"
|
path="optimizer"
|
||||||
|
|||||||
155
src/export-page/CourseExportContext.tsx
Normal file
155
src/export-page/CourseExportContext.tsx
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
import {
|
||||||
|
createContext,
|
||||||
|
useContext,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
import moment from 'moment';
|
||||||
|
import Cookies from 'universal-cookie';
|
||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
|
||||||
|
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
|
||||||
|
|
||||||
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
|
import { useExportStatus, useInvalidateExportStatus, useStartCourseExporting } from './data/apiHooks';
|
||||||
|
import { EXPORT_STAGES, LAST_EXPORT_COOKIE_NAME } from './data/constants';
|
||||||
|
import messages from './messages';
|
||||||
|
import { setExportCookie } from './utils';
|
||||||
|
|
||||||
|
export type CourseExportContextData = {
|
||||||
|
currentStage: number;
|
||||||
|
exportTriggered: boolean;
|
||||||
|
fetchExportErrorMessage?: string;
|
||||||
|
errorUnitUrl?: string;
|
||||||
|
anyRequestInProgress: boolean;
|
||||||
|
anyRequestFailed: boolean;
|
||||||
|
isLoadingDenied: boolean;
|
||||||
|
successDate?: number;
|
||||||
|
handleStartExportingCourse: () => void;
|
||||||
|
downloadPath?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Course Export Context.
|
||||||
|
* Always available when we're in the context of the Course Export Page.
|
||||||
|
*
|
||||||
|
* Get this using `useCourseExportContext()`
|
||||||
|
*/
|
||||||
|
const CourseExportContext = createContext<CourseExportContextData | undefined>(undefined);
|
||||||
|
|
||||||
|
type CourseExportProviderProps = {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CourseExportProvider = ({ children }: CourseExportProviderProps) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const { courseId } = useCourseAuthoringContext();
|
||||||
|
const cookies = new Cookies();
|
||||||
|
|
||||||
|
const [isStopFetching, setStopFetching] = useState(false);
|
||||||
|
const [exportTriggered, setExportTriggered] = useState(false);
|
||||||
|
const [successDate, setSuccessDate] = useState<number>();
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
setStopFetching(false);
|
||||||
|
setExportTriggered(false);
|
||||||
|
setSuccessDate(undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: exportStatus,
|
||||||
|
isPending: isPendingExportStatus,
|
||||||
|
isError: isErrorExportStatus,
|
||||||
|
failureReason: exportStatusError,
|
||||||
|
} = useExportStatus(courseId, isStopFetching, exportTriggered);
|
||||||
|
const exportMutation = useStartCourseExporting(courseId);
|
||||||
|
const invalidateExportStatus = useInvalidateExportStatus(courseId);
|
||||||
|
|
||||||
|
const currentStage = exportStatus?.exportStatus ?? 0;
|
||||||
|
const anyRequestInProgress = exportMutation.isPending || isPendingExportStatus;
|
||||||
|
const anyRequestFailed = exportMutation.isError || isErrorExportStatus;
|
||||||
|
const isLoadingDenied = exportStatusError?.response?.status === 403;
|
||||||
|
|
||||||
|
let fetchExportErrorMessage: string | undefined;
|
||||||
|
let errorUnitUrl;
|
||||||
|
if (exportStatus?.exportError) {
|
||||||
|
fetchExportErrorMessage = exportStatus.exportError.rawErrorMsg ?? intl.formatMessage(messages.unknownError);
|
||||||
|
errorUnitUrl = exportStatus.exportError.editUnitUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
let downloadPath;
|
||||||
|
if (exportStatus?.exportOutput) {
|
||||||
|
downloadPath = exportStatus.exportOutput;
|
||||||
|
if (downloadPath.startsWith('/')) {
|
||||||
|
downloadPath = `${getConfig().STUDIO_BASE_URL}${downloadPath}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On mount, restore export state from the cookie set by a previous session,
|
||||||
|
// so the stepper remains visible if the user navigates away and comes back.
|
||||||
|
useEffect(() => {
|
||||||
|
const cookieData = cookies.get(LAST_EXPORT_COOKIE_NAME);
|
||||||
|
if (cookieData) {
|
||||||
|
setExportTriggered(true);
|
||||||
|
setSuccessDate(cookieData.date);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Stop fetching the export status once the process has reached a terminal state:
|
||||||
|
// successful completion, a network/request failure, or an application-level export error.
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentStage === EXPORT_STAGES.SUCCESS || anyRequestFailed || fetchExportErrorMessage) {
|
||||||
|
setStopFetching(true);
|
||||||
|
}
|
||||||
|
}, [currentStage, anyRequestFailed, fetchExportErrorMessage]);
|
||||||
|
|
||||||
|
const handleStartExportingCourse = async () => {
|
||||||
|
reset();
|
||||||
|
invalidateExportStatus();
|
||||||
|
setExportTriggered(true);
|
||||||
|
await exportMutation.mutateAsync();
|
||||||
|
const momentDate = moment().valueOf();
|
||||||
|
setExportCookie(momentDate);
|
||||||
|
setSuccessDate(momentDate);
|
||||||
|
};
|
||||||
|
|
||||||
|
const context = useMemo<CourseExportContextData>(() => ({
|
||||||
|
currentStage,
|
||||||
|
exportTriggered,
|
||||||
|
fetchExportErrorMessage,
|
||||||
|
errorUnitUrl,
|
||||||
|
anyRequestFailed,
|
||||||
|
isLoadingDenied,
|
||||||
|
anyRequestInProgress,
|
||||||
|
successDate,
|
||||||
|
handleStartExportingCourse,
|
||||||
|
downloadPath,
|
||||||
|
}), [
|
||||||
|
currentStage,
|
||||||
|
exportTriggered,
|
||||||
|
fetchExportErrorMessage,
|
||||||
|
errorUnitUrl,
|
||||||
|
anyRequestFailed,
|
||||||
|
isLoadingDenied,
|
||||||
|
anyRequestInProgress,
|
||||||
|
successDate,
|
||||||
|
handleStartExportingCourse,
|
||||||
|
downloadPath,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CourseExportContext.Provider value={context}>
|
||||||
|
{children}
|
||||||
|
</CourseExportContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useCourseExportContext(): CourseExportContextData {
|
||||||
|
const ctx = useContext(CourseExportContext);
|
||||||
|
if (ctx === undefined) {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
throw new Error('useCourseExportContext() was used in a component without a <CourseExportProvider> ancestor.');
|
||||||
|
}
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import userEvent from '@testing-library/user-event';
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import Cookies from 'universal-cookie';
|
import Cookies from 'universal-cookie';
|
||||||
@@ -6,11 +7,10 @@ import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
|
|||||||
import { getCourseDetailsUrl } from '@src/data/api';
|
import { getCourseDetailsUrl } from '@src/data/api';
|
||||||
import {
|
import {
|
||||||
initializeMocks,
|
initializeMocks,
|
||||||
fireEvent,
|
|
||||||
render,
|
render,
|
||||||
|
screen,
|
||||||
waitFor,
|
waitFor,
|
||||||
} from '../testUtils';
|
} from '@src/testUtils';
|
||||||
import { RequestStatus } from '../data/constants';
|
|
||||||
import stepperMessages from './export-stepper/messages';
|
import stepperMessages from './export-stepper/messages';
|
||||||
import modalErrorMessages from './export-modal-error/messages';
|
import modalErrorMessages from './export-modal-error/messages';
|
||||||
import { getExportStatusApiUrl, postExportCourseApiUrl } from './data/api';
|
import { getExportStatusApiUrl, postExportCourseApiUrl } from './data/api';
|
||||||
@@ -18,8 +18,8 @@ import { EXPORT_STAGES } from './data/constants';
|
|||||||
import { exportPageMock } from './__mocks__';
|
import { exportPageMock } from './__mocks__';
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
import CourseExportPage from './CourseExportPage';
|
import CourseExportPage from './CourseExportPage';
|
||||||
|
import { CourseExportProvider } from './CourseExportContext';
|
||||||
|
|
||||||
let store;
|
|
||||||
let axiosMock;
|
let axiosMock;
|
||||||
let cookies;
|
let cookies;
|
||||||
const courseId = '123';
|
const courseId = '123';
|
||||||
@@ -35,7 +35,9 @@ jest.mock('universal-cookie', () => {
|
|||||||
|
|
||||||
const renderComponent = () => render(
|
const renderComponent = () => render(
|
||||||
<CourseAuthoringProvider courseId={courseId}>
|
<CourseAuthoringProvider courseId={courseId}>
|
||||||
<CourseExportPage />
|
<CourseExportProvider>
|
||||||
|
<CourseExportPage />
|
||||||
|
</CourseExportProvider>
|
||||||
</CourseAuthoringProvider>,
|
</CourseAuthoringProvider>,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -46,17 +48,20 @@ describe('<CourseExportPage />', () => {
|
|||||||
username: 'username',
|
username: 'username',
|
||||||
};
|
};
|
||||||
const mocks = initializeMocks({ user });
|
const mocks = initializeMocks({ user });
|
||||||
store = mocks.reduxStore;
|
|
||||||
axiosMock = mocks.axiosMock;
|
axiosMock = mocks.axiosMock;
|
||||||
axiosMock
|
axiosMock
|
||||||
.onGet(postExportCourseApiUrl(courseId))
|
.onPost(postExportCourseApiUrl(courseId))
|
||||||
.reply(200, exportPageMock);
|
.reply(200, exportPageMock);
|
||||||
axiosMock
|
axiosMock
|
||||||
.onGet(getCourseDetailsUrl(courseId, user.username))
|
.onGet(getCourseDetailsUrl(courseId, user.username))
|
||||||
.reply(200, { courseId, name: courseName });
|
.reply(200, { courseId, name: courseName });
|
||||||
|
axiosMock
|
||||||
|
.onGet(getExportStatusApiUrl(courseId))
|
||||||
|
.reply(200, { exportStatus: EXPORT_STAGES.PREPARING });
|
||||||
cookies = new Cookies();
|
cookies = new Cookies();
|
||||||
cookies.get.mockReturnValue(null);
|
cookies.get.mockReturnValue(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render page title correctly', async () => {
|
it('should render page title correctly', async () => {
|
||||||
renderComponent();
|
renderComponent();
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
@@ -66,95 +71,96 @@ describe('<CourseExportPage />', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render without errors', async () => {
|
it('should render without errors', async () => {
|
||||||
const { getByText } = renderComponent();
|
renderComponent();
|
||||||
await waitFor(() => {
|
expect(await screen.findByText(messages.headingSubtitle.defaultMessage)).toBeInTheDocument();
|
||||||
expect(getByText(messages.headingSubtitle.defaultMessage)).toBeInTheDocument();
|
const exportPageElement = screen.getByText(messages.headingTitle.defaultMessage, {
|
||||||
const exportPageElement = getByText(messages.headingTitle.defaultMessage, {
|
selector: 'h2.sub-header-title',
|
||||||
selector: 'h2.sub-header-title',
|
|
||||||
});
|
|
||||||
expect(exportPageElement).toBeInTheDocument();
|
|
||||||
expect(getByText(messages.titleUnderButton.defaultMessage)).toBeInTheDocument();
|
|
||||||
expect(getByText(messages.description2.defaultMessage)).toBeInTheDocument();
|
|
||||||
expect(getByText(messages.buttonTitle.defaultMessage)).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
expect(exportPageElement).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(messages.titleUnderButton.defaultMessage)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(messages.description2.defaultMessage)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(messages.buttonTitle.defaultMessage)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should start exporting on click', async () => {
|
it('should start exporting on click', async () => {
|
||||||
const { getByText, container } = renderComponent();
|
const user = userEvent.setup();
|
||||||
const button = container.querySelector('.btn-primary');
|
const { container } = renderComponent();
|
||||||
fireEvent.click(button);
|
const button = container.querySelector('.btn-primary')!;
|
||||||
expect(getByText(stepperMessages.stepperPreparingDescription.defaultMessage)).toBeInTheDocument();
|
await user.click(button);
|
||||||
|
expect(screen.getByText(stepperMessages.stepperPreparingDescription.defaultMessage)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show modal error', async () => {
|
it('should show modal error', async () => {
|
||||||
axiosMock
|
axiosMock
|
||||||
.onGet(getExportStatusApiUrl(courseId))
|
.onGet(getExportStatusApiUrl(courseId))
|
||||||
.reply(200, { exportStatus: EXPORT_STAGES.EXPORTING, exportError: { rawErrorMsg: 'test error', editUnitUrl: 'http://test-url.test' } });
|
.reply(200, { exportStatus: EXPORT_STAGES.EXPORTING, exportError: { rawErrorMsg: 'test error', editUnitUrl: 'http://test-url.test' } });
|
||||||
const { getByText, queryByText, container } = renderComponent();
|
const user = userEvent.setup();
|
||||||
const startExportButton = container.querySelector('.btn-primary');
|
const { container } = renderComponent();
|
||||||
fireEvent.click(startExportButton);
|
const startExportButton = container.querySelector('.btn-primary')!;
|
||||||
|
await user.click(startExportButton);
|
||||||
// eslint-disable-next-line no-promise-executor-return
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
await new Promise((r) => setTimeout(r, 3500));
|
await new Promise((r) => setTimeout(r, 3500));
|
||||||
expect(getByText(/There has been a failure to export to XML at least one component. It is recommended that you go to the edit page and repair the error before attempting another export. Please check that all components on the page are valid and do not display any error messages. The raw error message is: test error/i));
|
expect(screen.getByText(/There has been a failure to export to XML at least one component. It is recommended that you go to the edit page and repair the error before attempting another export. Please check that all components on the page are valid and do not display any error messages. The raw error message is: test error/i));
|
||||||
const closeModalWindowButton = getByText('Return to export');
|
const closeModalWindowButton = screen.getByText('Return to export');
|
||||||
fireEvent.click(closeModalWindowButton);
|
await user.click(closeModalWindowButton);
|
||||||
expect(queryByText(modalErrorMessages.errorCancelButtonUnit.defaultMessage)).not.toBeInTheDocument();
|
expect(screen.queryByText(modalErrorMessages.errorCancelButtonUnit.defaultMessage)).not.toBeInTheDocument();
|
||||||
fireEvent.click(closeModalWindowButton);
|
await user.click(closeModalWindowButton);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch status without clicking when cookies has', async () => {
|
it('should fetch status without clicking when cookies has', async () => {
|
||||||
cookies.get.mockReturnValue({ date: 1679787000 });
|
cookies.get.mockReturnValue({ date: 1679787000 });
|
||||||
const { getByText } = renderComponent();
|
renderComponent();
|
||||||
expect(getByText(stepperMessages.stepperPreparingDescription.defaultMessage)).toBeInTheDocument();
|
expect(screen.getByText(stepperMessages.stepperPreparingDescription.defaultMessage)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show download path for relative path', async () => {
|
it('should show download path for relative path', async () => {
|
||||||
axiosMock
|
axiosMock
|
||||||
.onGet(getExportStatusApiUrl(courseId))
|
.onGet(getExportStatusApiUrl(courseId))
|
||||||
.reply(200, { exportStatus: EXPORT_STAGES.SUCCESS, exportOutput: '/test-download-path.test' });
|
.reply(200, { exportStatus: EXPORT_STAGES.SUCCESS, exportOutput: '/test-download-path.test' });
|
||||||
const { getByText, container } = renderComponent();
|
const user = userEvent.setup();
|
||||||
const startExportButton = container.querySelector('.btn-primary');
|
const { container } = renderComponent();
|
||||||
fireEvent.click(startExportButton);
|
const startExportButton = container.querySelector('.btn-primary')!;
|
||||||
await waitFor(() => {
|
await user.click(startExportButton);
|
||||||
const downloadButton = getByText(stepperMessages.downloadCourseButtonTitle.defaultMessage);
|
const downloadButton = screen.getByText(stepperMessages.downloadCourseButtonTitle.defaultMessage);
|
||||||
expect(downloadButton).toBeInTheDocument();
|
expect(downloadButton).toBeInTheDocument();
|
||||||
expect(downloadButton.getAttribute('href')).toEqual(`${getConfig().STUDIO_BASE_URL}/test-download-path.test`);
|
expect(downloadButton.getAttribute('href')).toEqual(`${getConfig().STUDIO_BASE_URL}/test-download-path.test`);
|
||||||
}, { timeout: 4_000 });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show download path for absolute path', async () => {
|
it('should show download path for absolute path', async () => {
|
||||||
axiosMock
|
axiosMock
|
||||||
.onGet(getExportStatusApiUrl(courseId))
|
.onGet(getExportStatusApiUrl(courseId))
|
||||||
.reply(200, { exportStatus: EXPORT_STAGES.SUCCESS, exportOutput: 'http://test-download-path.test' });
|
.reply(200, { exportStatus: EXPORT_STAGES.SUCCESS, exportOutput: 'http://test-download-path.test' });
|
||||||
const { getByText, container } = renderComponent();
|
const user = userEvent.setup();
|
||||||
const startExportButton = container.querySelector('.btn-primary');
|
const { container } = renderComponent();
|
||||||
fireEvent.click(startExportButton);
|
const startExportButton = container.querySelector('.btn-primary')!;
|
||||||
await waitFor(() => {
|
await user.click(startExportButton);
|
||||||
const downloadButton = getByText(stepperMessages.downloadCourseButtonTitle.defaultMessage);
|
const downloadButton = screen.getByText(stepperMessages.downloadCourseButtonTitle.defaultMessage);
|
||||||
expect(downloadButton).toBeInTheDocument();
|
expect(downloadButton).toBeInTheDocument();
|
||||||
expect(downloadButton.getAttribute('href')).toEqual('http://test-download-path.test');
|
expect(downloadButton.getAttribute('href')).toEqual('http://test-download-path.test');
|
||||||
}, { timeout: 4_000 });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays an alert and sets status to DENIED when API responds with 403', async () => {
|
it('displays an alert and sets status to DENIED when API responds with 403', async () => {
|
||||||
axiosMock
|
axiosMock
|
||||||
.onGet(getExportStatusApiUrl(courseId))
|
.onGet(getExportStatusApiUrl(courseId))
|
||||||
.reply(403);
|
.reply(403);
|
||||||
const { getByRole, container } = renderComponent();
|
const user = userEvent.setup();
|
||||||
const startExportButton = container.querySelector('.btn-primary');
|
const { container } = renderComponent();
|
||||||
fireEvent.click(startExportButton);
|
const startExportButton = container.querySelector('.btn-primary')!;
|
||||||
await waitFor(() => {
|
await user.click(startExportButton);
|
||||||
expect(getByRole('alert')).toBeInTheDocument();
|
expect(screen.getByRole('alert')).toBeInTheDocument();
|
||||||
}, { timeout: 4_000 });
|
|
||||||
const { loadingStatus } = store.getState().courseExport;
|
|
||||||
expect(loadingStatus).toEqual(RequestStatus.DENIED);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets loading status to FAILED upon receiving a 404 response from the API', async () => {
|
it('does not show a connection error alert upon receiving a 404 response from the API', async () => {
|
||||||
axiosMock
|
axiosMock
|
||||||
.onGet(getExportStatusApiUrl(courseId))
|
.onGet(getExportStatusApiUrl(courseId))
|
||||||
.reply(404);
|
.reply(404);
|
||||||
|
const user = userEvent.setup();
|
||||||
const { container } = renderComponent();
|
const { container } = renderComponent();
|
||||||
const startExportButton = container.querySelector('.btn-primary');
|
const startExportButton = container.querySelector('.btn-primary')!;
|
||||||
fireEvent.click(startExportButton);
|
await user.click(startExportButton);
|
||||||
await waitFor(() => {
|
expect(screen.getByText(stepperMessages.stepperPreparingDescription.defaultMessage)).toBeInTheDocument();
|
||||||
const { loadingStatus } = store.getState().courseExport;
|
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
||||||
expect(loadingStatus).toEqual(RequestStatus.FAILED);
|
|
||||||
}, { timeout: 4_000 });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,54 +1,38 @@
|
|||||||
import React, { useEffect } from 'react';
|
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
import {
|
import {
|
||||||
Container, Layout, Button, Card,
|
Container, Layout, Button, Card,
|
||||||
} from '@openedx/paragon';
|
} from '@openedx/paragon';
|
||||||
import { ArrowCircleDown as ArrowCircleDownIcon } from '@openedx/paragon/icons';
|
import { ArrowCircleDown as ArrowCircleDownIcon } from '@openedx/paragon/icons';
|
||||||
import Cookies from 'universal-cookie';
|
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
|
|
||||||
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
|
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
|
||||||
import InternetConnectionAlert from '../generic/internet-connection-alert';
|
import InternetConnectionAlert from '@src/generic/internet-connection-alert';
|
||||||
import ConnectionErrorAlert from '../generic/ConnectionErrorAlert';
|
import ConnectionErrorAlert from '@src/generic/ConnectionErrorAlert';
|
||||||
import SubHeader from '../generic/sub-header/SubHeader';
|
import SubHeader from '@src/generic/sub-header/SubHeader';
|
||||||
import { RequestStatus } from '../data/constants';
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
import ExportSidebar from './export-sidebar/ExportSidebar';
|
import ExportSidebar from './export-sidebar/ExportSidebar';
|
||||||
import {
|
import { EXPORT_STAGES } from './data/constants';
|
||||||
getCurrentStage, getError, getExportTriggered, getLoadingStatus, getSavingStatus,
|
|
||||||
} from './data/selectors';
|
|
||||||
import { startExportingCourse } from './data/thunks';
|
|
||||||
import { EXPORT_STAGES, LAST_EXPORT_COOKIE_NAME } from './data/constants';
|
|
||||||
import { updateExportTriggered, updateSavingStatus, updateSuccessDate } from './data/slice';
|
|
||||||
import ExportModalError from './export-modal-error/ExportModalError';
|
import ExportModalError from './export-modal-error/ExportModalError';
|
||||||
import ExportFooter from './export-footer/ExportFooter';
|
import ExportFooter from './export-footer/ExportFooter';
|
||||||
import ExportStepper from './export-stepper/ExportStepper';
|
import ExportStepper from './export-stepper/ExportStepper';
|
||||||
|
import { useCourseExportContext } from './CourseExportContext';
|
||||||
|
|
||||||
const CourseExportPage = () => {
|
const CourseExportPage = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const dispatch = useDispatch();
|
const { courseDetails } = useCourseAuthoringContext();
|
||||||
const exportTriggered = useSelector(getExportTriggered);
|
const {
|
||||||
const { courseId, courseDetails } = useCourseAuthoringContext();
|
currentStage,
|
||||||
const currentStage = useSelector(getCurrentStage);
|
exportTriggered,
|
||||||
const { msg: errorMessage } = useSelector(getError);
|
fetchExportErrorMessage,
|
||||||
const loadingStatus = useSelector(getLoadingStatus);
|
anyRequestFailed,
|
||||||
const savingStatus = useSelector(getSavingStatus);
|
isLoadingDenied,
|
||||||
const cookies = new Cookies();
|
anyRequestInProgress,
|
||||||
const isShowExportButton = !exportTriggered || errorMessage || currentStage === EXPORT_STAGES.SUCCESS;
|
handleStartExportingCourse,
|
||||||
const anyRequestFailed = savingStatus === RequestStatus.FAILED || loadingStatus === RequestStatus.FAILED;
|
} = useCourseExportContext();
|
||||||
const isLoadingDenied = loadingStatus === RequestStatus.DENIED;
|
|
||||||
const anyRequestInProgress = savingStatus === RequestStatus.PENDING || loadingStatus === RequestStatus.IN_PROGRESS;
|
|
||||||
|
|
||||||
useEffect(() => {
|
const isShowExportButton = !exportTriggered || fetchExportErrorMessage || currentStage === EXPORT_STAGES.SUCCESS;
|
||||||
const cookieData = cookies.get(LAST_EXPORT_COOKIE_NAME);
|
|
||||||
if (cookieData) {
|
|
||||||
dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL }));
|
|
||||||
dispatch(updateExportTriggered(true));
|
|
||||||
dispatch(updateSuccessDate(cookieData.date));
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (isLoadingDenied) {
|
if (isLoadingDenied) {
|
||||||
return (
|
return (
|
||||||
@@ -97,7 +81,7 @@ const CourseExportPage = () => {
|
|||||||
size="lg"
|
size="lg"
|
||||||
block
|
block
|
||||||
className="mb-4"
|
className="mb-4"
|
||||||
onClick={() => dispatch(startExportingCourse(courseId))}
|
onClick={handleStartExportingCourse}
|
||||||
iconBefore={ArrowCircleDownIcon}
|
iconBefore={ArrowCircleDownIcon}
|
||||||
>
|
>
|
||||||
{intl.formatMessage(messages.buttonTitle)}
|
{intl.formatMessage(messages.buttonTitle)}
|
||||||
@@ -105,16 +89,16 @@ const CourseExportPage = () => {
|
|||||||
</Card.Section>
|
</Card.Section>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
{exportTriggered && <ExportStepper courseId={courseId} />}
|
{exportTriggered && <ExportStepper />}
|
||||||
<ExportFooter />
|
<ExportFooter />
|
||||||
</article>
|
</article>
|
||||||
</Layout.Element>
|
</Layout.Element>
|
||||||
<Layout.Element>
|
<Layout.Element>
|
||||||
<ExportSidebar courseId={courseId} />
|
<ExportSidebar />
|
||||||
</Layout.Element>
|
</Layout.Element>
|
||||||
</Layout>
|
</Layout>
|
||||||
</section>
|
</section>
|
||||||
<ExportModalError courseId={courseId} />
|
<ExportModalError />
|
||||||
</Container>
|
</Container>
|
||||||
<div className="alert-toast">
|
<div className="alert-toast">
|
||||||
<InternetConnectionAlert
|
<InternetConnectionAlert
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
|
|
||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
|
||||||
|
|
||||||
const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL;
|
|
||||||
export const postExportCourseApiUrl = (courseId) => new URL(`export/${courseId}`, getApiBaseUrl()).href;
|
|
||||||
export const getExportStatusApiUrl = (courseId) => new URL(`export_status/${courseId}`, getApiBaseUrl()).href;
|
|
||||||
|
|
||||||
export async function startCourseExporting(courseId) {
|
|
||||||
const { data } = await getAuthenticatedHttpClient()
|
|
||||||
.post(postExportCourseApiUrl(courseId));
|
|
||||||
return camelCaseObject(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getExportStatus(courseId) {
|
|
||||||
const { data } = await getAuthenticatedHttpClient()
|
|
||||||
.get(getExportStatusApiUrl(courseId));
|
|
||||||
return camelCaseObject(data);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import MockAdapter from 'axios-mock-adapter';
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
import { initializeMockApp, getConfig } from '@edx/frontend-platform';
|
import { initializeMocks } from '@src/testUtils';
|
||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
|
||||||
|
|
||||||
import { getExportStatus, postExportCourseApiUrl, startCourseExporting } from './api';
|
import { getExportStatus, postExportCourseApiUrl, startCourseExporting } from './api';
|
||||||
|
|
||||||
@@ -9,15 +8,7 @@ const courseId = 'course-123';
|
|||||||
|
|
||||||
describe('API Functions', () => {
|
describe('API Functions', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
initializeMockApp({
|
({ axiosMock } = initializeMocks());
|
||||||
authenticatedUser: {
|
|
||||||
userId: 3,
|
|
||||||
username: 'abc123',
|
|
||||||
administrator: true,
|
|
||||||
roles: [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
27
src/export-page/data/api.ts
Normal file
27
src/export-page/data/api.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
|
||||||
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
|
|
||||||
|
const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL;
|
||||||
|
export const postExportCourseApiUrl = (courseId: string) => new URL(`export/${courseId}`, getApiBaseUrl()).href;
|
||||||
|
export const getExportStatusApiUrl = (courseId: string) => new URL(`export_status/${courseId}`, getApiBaseUrl()).href;
|
||||||
|
|
||||||
|
export interface ExportStatusData {
|
||||||
|
exportStatus: number;
|
||||||
|
exportOutput?: string; // URL to the exported course file
|
||||||
|
exportError?: {
|
||||||
|
rawErrorMsg?: string;
|
||||||
|
editUnitUrl?: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function startCourseExporting(courseId: string): Promise<ExportStatusData> {
|
||||||
|
const { data } = await getAuthenticatedHttpClient()
|
||||||
|
.post(postExportCourseApiUrl(courseId));
|
||||||
|
return camelCaseObject(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getExportStatus(courseId: string): Promise<ExportStatusData> {
|
||||||
|
const { data } = await getAuthenticatedHttpClient()
|
||||||
|
.get(getExportStatusApiUrl(courseId));
|
||||||
|
return camelCaseObject(data);
|
||||||
|
}
|
||||||
46
src/export-page/data/apiHooks.ts
Normal file
46
src/export-page/data/apiHooks.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
|
import { AxiosError } from 'axios';
|
||||||
|
import {
|
||||||
|
useQueryClient, skipToken, useMutation, useQuery,
|
||||||
|
} from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { getExportStatus, startCourseExporting, type ExportStatusData } from './api';
|
||||||
|
|
||||||
|
export const exportQueryKeys = {
|
||||||
|
all: ['courseExport'],
|
||||||
|
/** Key for the export status of a specific course */
|
||||||
|
exportStatus: (courseId: string) => [...exportQueryKeys.all, courseId],
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a function to invalidate the export status query for a given course.
|
||||||
|
*/
|
||||||
|
export const useInvalidateExportStatus = (courseId: string) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return () => queryClient.removeQueries({ queryKey: exportQueryKeys.exportStatus(courseId) });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a mutation to start exporting a course.
|
||||||
|
*/
|
||||||
|
export const useStartCourseExporting = (courseId: string) => (
|
||||||
|
useMutation({
|
||||||
|
mutationFn: () => startCourseExporting(courseId),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the export status for a given course.
|
||||||
|
* Only fetch while `stopRefetch` is false.
|
||||||
|
*/
|
||||||
|
export const useExportStatus = (
|
||||||
|
courseId: string,
|
||||||
|
stopRefetch: boolean,
|
||||||
|
enabled: boolean,
|
||||||
|
) => (
|
||||||
|
useQuery<ExportStatusData, AxiosError>({
|
||||||
|
queryKey: exportQueryKeys.exportStatus(courseId),
|
||||||
|
queryFn: enabled ? () => getExportStatus(courseId) : skipToken,
|
||||||
|
refetchInterval: (enabled && !stopRefetch) ? 3000 : false,
|
||||||
|
})
|
||||||
|
);
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
export const getExportTriggered = (state) => state.courseExport.exportTriggered;
|
|
||||||
export const getCurrentStage = (state) => state.courseExport.currentStage;
|
|
||||||
export const getDownloadPath = (state) => state.courseExport.downloadPath;
|
|
||||||
export const getSuccessDate = (state) => state.courseExport.successDate;
|
|
||||||
export const getError = (state) => state.courseExport.error;
|
|
||||||
export const getIsErrorModalOpen = (state) => state.courseExport.isErrorModalOpen;
|
|
||||||
export const getLoadingStatus = (state) => state.courseExport.loadingStatus;
|
|
||||||
export const getSavingStatus = (state) => state.courseExport.savingStatus;
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/* eslint-disable no-param-reassign */
|
|
||||||
import { createSlice } from '@reduxjs/toolkit';
|
|
||||||
|
|
||||||
const initialState = {
|
|
||||||
exportTriggered: false,
|
|
||||||
currentStage: 0,
|
|
||||||
error: { msg: null, unitUrl: null },
|
|
||||||
downloadPath: null,
|
|
||||||
successDate: null,
|
|
||||||
isErrorModalOpen: false,
|
|
||||||
loadingStatus: '',
|
|
||||||
savingStatus: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
const slice = createSlice({
|
|
||||||
name: 'exportPage',
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
updateExportTriggered: (state, { payload }) => {
|
|
||||||
state.exportTriggered = payload;
|
|
||||||
},
|
|
||||||
updateCurrentStage: (state, { payload }) => {
|
|
||||||
if (payload >= state.currentStage) {
|
|
||||||
state.currentStage = payload;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updateDownloadPath: (state, { payload }) => {
|
|
||||||
state.downloadPath = payload;
|
|
||||||
},
|
|
||||||
updateSuccessDate: (state, { payload }) => {
|
|
||||||
state.successDate = payload;
|
|
||||||
},
|
|
||||||
updateError: (state, { payload }) => {
|
|
||||||
state.error = payload;
|
|
||||||
},
|
|
||||||
updateIsErrorModalOpen: (state, { payload }) => {
|
|
||||||
state.isErrorModalOpen = payload;
|
|
||||||
},
|
|
||||||
reset: () => initialState,
|
|
||||||
updateLoadingStatus: (state, { payload }) => {
|
|
||||||
state.loadingStatus = payload.status;
|
|
||||||
},
|
|
||||||
updateSavingStatus: (state, { payload }) => {
|
|
||||||
state.savingStatus = payload.status;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const {
|
|
||||||
updateExportTriggered,
|
|
||||||
updateCurrentStage,
|
|
||||||
updateDownloadPath,
|
|
||||||
updateSuccessDate,
|
|
||||||
updateError,
|
|
||||||
updateIsErrorModalOpen,
|
|
||||||
reset,
|
|
||||||
updateLoadingStatus,
|
|
||||||
updateSavingStatus,
|
|
||||||
} = slice.actions;
|
|
||||||
|
|
||||||
export const {
|
|
||||||
reducer,
|
|
||||||
} = slice;
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
import Cookies from 'universal-cookie';
|
|
||||||
import { fetchExportStatus } from './thunks';
|
|
||||||
import * as api from './api';
|
|
||||||
import { EXPORT_STAGES } from './constants';
|
|
||||||
|
|
||||||
jest.mock('universal-cookie', () => jest.fn().mockImplementation(() => ({
|
|
||||||
get: jest.fn().mockImplementation(() => ({ completed: false })),
|
|
||||||
})));
|
|
||||||
|
|
||||||
jest.mock('../utils', () => ({
|
|
||||||
setExportCookie: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('fetchExportStatus thunk', () => {
|
|
||||||
const dispatch = jest.fn();
|
|
||||||
const getState = jest.fn();
|
|
||||||
const courseId = 'course-123';
|
|
||||||
const exportStatus = EXPORT_STAGES.COMPRESSING;
|
|
||||||
const exportOutput = 'export output';
|
|
||||||
const exportError = 'export error';
|
|
||||||
let mockGetExportStatus;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
|
|
||||||
mockGetExportStatus = jest.spyOn(api, 'getExportStatus').mockResolvedValue({
|
|
||||||
exportStatus,
|
|
||||||
exportOutput,
|
|
||||||
exportError,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should dispatch updateCurrentStage with export status', async () => {
|
|
||||||
mockGetExportStatus.mockResolvedValue({
|
|
||||||
exportStatus,
|
|
||||||
exportOutput,
|
|
||||||
exportError,
|
|
||||||
});
|
|
||||||
|
|
||||||
await fetchExportStatus(courseId)(dispatch, getState);
|
|
||||||
|
|
||||||
expect(dispatch).toHaveBeenCalledWith({
|
|
||||||
payload: exportStatus,
|
|
||||||
type: 'exportPage/updateCurrentStage',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should dispatch updateError on export error', async () => {
|
|
||||||
mockGetExportStatus.mockResolvedValue({
|
|
||||||
exportStatus,
|
|
||||||
exportOutput,
|
|
||||||
exportError,
|
|
||||||
});
|
|
||||||
|
|
||||||
await fetchExportStatus(courseId)(dispatch, getState);
|
|
||||||
|
|
||||||
expect(dispatch).toHaveBeenCalledWith({
|
|
||||||
payload: {
|
|
||||||
msg: exportError,
|
|
||||||
unitUrl: null,
|
|
||||||
},
|
|
||||||
type: 'exportPage/updateError',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should dispatch updateIsErrorModalOpen with true if export error', async () => {
|
|
||||||
mockGetExportStatus.mockResolvedValue({
|
|
||||||
exportStatus,
|
|
||||||
exportOutput,
|
|
||||||
exportError,
|
|
||||||
});
|
|
||||||
|
|
||||||
await fetchExportStatus(courseId)(dispatch, getState);
|
|
||||||
|
|
||||||
expect(dispatch).toHaveBeenCalledWith({
|
|
||||||
payload: true,
|
|
||||||
type: 'exportPage/updateIsErrorModalOpen',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not dispatch updateIsErrorModalOpen if no export error', async () => {
|
|
||||||
mockGetExportStatus.mockResolvedValue({
|
|
||||||
exportStatus,
|
|
||||||
exportOutput,
|
|
||||||
exportError: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
await fetchExportStatus(courseId)(dispatch, getState);
|
|
||||||
|
|
||||||
expect(dispatch).not.toHaveBeenCalledWith({
|
|
||||||
payload: false,
|
|
||||||
type: 'exportPage/updateIsErrorModalOpen',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should dispatch updateDownloadPath if there's export output", async () => {
|
|
||||||
mockGetExportStatus.mockResolvedValue({
|
|
||||||
exportStatus,
|
|
||||||
exportOutput,
|
|
||||||
exportError,
|
|
||||||
});
|
|
||||||
|
|
||||||
await fetchExportStatus(courseId)(dispatch, getState);
|
|
||||||
|
|
||||||
expect(dispatch).toHaveBeenCalledWith({
|
|
||||||
payload: exportOutput,
|
|
||||||
type: 'exportPage/updateDownloadPath',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should dispatch updateSuccessDate with current date if export status is success', async () => {
|
|
||||||
mockGetExportStatus.mockResolvedValue({
|
|
||||||
exportStatus:
|
|
||||||
EXPORT_STAGES.SUCCESS,
|
|
||||||
exportOutput,
|
|
||||||
exportError,
|
|
||||||
});
|
|
||||||
|
|
||||||
await fetchExportStatus(courseId)(dispatch, getState);
|
|
||||||
|
|
||||||
expect(dispatch).toHaveBeenCalledWith({
|
|
||||||
payload: expect.any(Number),
|
|
||||||
type: 'exportPage/updateSuccessDate',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not dispatch updateSuccessDate with current date if last-export cookie is already set', async () => {
|
|
||||||
mockGetExportStatus.mockResolvedValue({
|
|
||||||
exportStatus:
|
|
||||||
EXPORT_STAGES.SUCCESS,
|
|
||||||
exportOutput,
|
|
||||||
exportError,
|
|
||||||
});
|
|
||||||
|
|
||||||
Cookies.mockImplementation(() => ({
|
|
||||||
get: jest.fn().mockReturnValueOnce({ completed: true }),
|
|
||||||
}));
|
|
||||||
|
|
||||||
await fetchExportStatus(courseId)(dispatch, getState);
|
|
||||||
|
|
||||||
expect(dispatch).not.toHaveBeenCalledWith({
|
|
||||||
payload: expect.any,
|
|
||||||
type: 'exportPage/updateSuccessDate',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
import Cookies from 'universal-cookie';
|
|
||||||
import moment from 'moment';
|
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
|
||||||
|
|
||||||
import { RequestStatus } from '../../data/constants';
|
|
||||||
import { setExportCookie } from '../utils';
|
|
||||||
import { EXPORT_STAGES, LAST_EXPORT_COOKIE_NAME } from './constants';
|
|
||||||
|
|
||||||
import {
|
|
||||||
startCourseExporting,
|
|
||||||
getExportStatus,
|
|
||||||
} from './api';
|
|
||||||
import {
|
|
||||||
updateExportTriggered,
|
|
||||||
updateCurrentStage,
|
|
||||||
updateDownloadPath,
|
|
||||||
updateSuccessDate,
|
|
||||||
updateError,
|
|
||||||
updateIsErrorModalOpen,
|
|
||||||
reset,
|
|
||||||
updateLoadingStatus,
|
|
||||||
updateSavingStatus,
|
|
||||||
} from './slice';
|
|
||||||
|
|
||||||
function setExportDate({
|
|
||||||
date, exportStatus, exportOutput, dispatch,
|
|
||||||
}) {
|
|
||||||
// If there is no cookie for the last export date, set it now.
|
|
||||||
const cookies = new Cookies();
|
|
||||||
const cookieData = cookies.get(LAST_EXPORT_COOKIE_NAME);
|
|
||||||
if (!cookieData?.completed) {
|
|
||||||
setExportCookie(date, exportStatus === EXPORT_STAGES.SUCCESS);
|
|
||||||
}
|
|
||||||
// If we don't have export date set yet via cookie, set success date to current date.
|
|
||||||
if (exportOutput && !cookieData?.completed) {
|
|
||||||
dispatch(updateSuccessDate(date));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function startExportingCourse(courseId) {
|
|
||||||
return async (dispatch) => {
|
|
||||||
dispatch(updateSavingStatus({ status: RequestStatus.PENDING }));
|
|
||||||
try {
|
|
||||||
dispatch(reset());
|
|
||||||
dispatch(updateExportTriggered(true));
|
|
||||||
const exportData = await startCourseExporting(courseId);
|
|
||||||
dispatch(updateCurrentStage(exportData.exportStatus));
|
|
||||||
setExportCookie(moment().valueOf(), exportData.exportStatus === EXPORT_STAGES.SUCCESS);
|
|
||||||
|
|
||||||
dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL }));
|
|
||||||
return true;
|
|
||||||
} catch {
|
|
||||||
dispatch(updateSavingStatus({ status: RequestStatus.FAILED }));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fetchExportStatus(courseId) {
|
|
||||||
return async (dispatch) => {
|
|
||||||
dispatch(updateLoadingStatus({ status: RequestStatus.IN_PROGRESS }));
|
|
||||||
try {
|
|
||||||
const {
|
|
||||||
exportStatus, exportOutput, exportError,
|
|
||||||
} = await getExportStatus(courseId);
|
|
||||||
dispatch(updateCurrentStage(Math.abs(exportStatus)));
|
|
||||||
|
|
||||||
const date = moment().valueOf();
|
|
||||||
|
|
||||||
setExportDate({
|
|
||||||
date, exportStatus, exportOutput, dispatch,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (exportError) {
|
|
||||||
const errorMessage = exportError.rawErrorMsg || exportError;
|
|
||||||
const errorUnitUrl = exportError.editUnitUrl || null;
|
|
||||||
dispatch(updateError({ msg: errorMessage, unitUrl: errorUnitUrl }));
|
|
||||||
dispatch(updateIsErrorModalOpen(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exportOutput) {
|
|
||||||
if (exportOutput.startsWith('/')) {
|
|
||||||
dispatch(updateDownloadPath(`${getConfig().STUDIO_BASE_URL}${exportOutput}`));
|
|
||||||
} else {
|
|
||||||
dispatch(updateDownloadPath(exportOutput));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch(updateLoadingStatus({ status: RequestStatus.SUCCESSFUL }));
|
|
||||||
return true;
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error.response && error.response.status === 403) {
|
|
||||||
dispatch(updateLoadingStatus({ status: RequestStatus.DENIED }));
|
|
||||||
} else {
|
|
||||||
dispatch(updateLoadingStatus({ courseId, status: RequestStatus.FAILED }));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react';
|
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
import { Layout } from '@openedx/paragon';
|
import { Layout } from '@openedx/paragon';
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { Error as ErrorIcon } from '@openedx/paragon/icons';
|
|
||||||
|
|
||||||
import ModalNotification from '../../generic/modal-notification';
|
|
||||||
import { getError, getIsErrorModalOpen } from '../data/selectors';
|
|
||||||
import { updateIsErrorModalOpen } from '../data/slice';
|
|
||||||
import messages from './messages';
|
|
||||||
|
|
||||||
const ExportModalError = ({
|
|
||||||
courseId,
|
|
||||||
}) => {
|
|
||||||
const intl = useIntl();
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
const isErrorModalOpen = useSelector(getIsErrorModalOpen);
|
|
||||||
const { msg: errorMessage, unitUrl: unitErrorUrl } = useSelector(getError);
|
|
||||||
|
|
||||||
const handleUnitRedirect = () => { window.location.assign(unitErrorUrl); };
|
|
||||||
const handleRedirectCourseHome = () => { window.location.assign(`${getConfig().STUDIO_BASE_URL}/course/${courseId}`); };
|
|
||||||
return (
|
|
||||||
<ModalNotification
|
|
||||||
isOpen={isErrorModalOpen}
|
|
||||||
title={intl.formatMessage(messages.errorTitle)}
|
|
||||||
message={
|
|
||||||
intl.formatMessage(
|
|
||||||
unitErrorUrl
|
|
||||||
? messages.errorDescriptionUnit
|
|
||||||
: messages.errorDescriptionNotUnit,
|
|
||||||
{ errorMessage },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
cancelButtonText={
|
|
||||||
intl.formatMessage(unitErrorUrl ? messages.errorCancelButtonUnit : messages.errorCancelButtonNotUnit)
|
|
||||||
}
|
|
||||||
actionButtonText={
|
|
||||||
intl.formatMessage(unitErrorUrl ? messages.errorActionButtonUnit : messages.errorActionButtonNotUnit)
|
|
||||||
}
|
|
||||||
handleCancel={() => dispatch(updateIsErrorModalOpen(false))}
|
|
||||||
handleAction={unitErrorUrl ? handleUnitRedirect : handleRedirectCourseHome}
|
|
||||||
variant="danger"
|
|
||||||
icon={ErrorIcon}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ExportModalError.propTypes = {
|
|
||||||
courseId: PropTypes.string.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
ExportModalError.defaultProps = {};
|
|
||||||
|
|
||||||
export default ExportModalError;
|
|
||||||
55
src/export-page/export-modal-error/ExportModalError.tsx
Normal file
55
src/export-page/export-modal-error/ExportModalError.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
import { Error as ErrorIcon } from '@openedx/paragon/icons';
|
||||||
|
|
||||||
|
import ModalNotification from '@src/generic/modal-notification';
|
||||||
|
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
|
||||||
|
import messages from './messages';
|
||||||
|
import { useCourseExportContext } from '../CourseExportContext';
|
||||||
|
|
||||||
|
const ExportModalError = () => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const { courseId } = useCourseAuthoringContext();
|
||||||
|
const {
|
||||||
|
fetchExportErrorMessage,
|
||||||
|
errorUnitUrl,
|
||||||
|
} = useCourseExportContext();
|
||||||
|
|
||||||
|
const [isErrorModalOpen, setIsErrorModalOpen] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (fetchExportErrorMessage) {
|
||||||
|
setIsErrorModalOpen(true);
|
||||||
|
}
|
||||||
|
}, [fetchExportErrorMessage]);
|
||||||
|
|
||||||
|
const handleUnitRedirect = () => { window.location.assign(errorUnitUrl ?? ''); };
|
||||||
|
const handleRedirectCourseHome = () => { window.location.assign(`${getConfig().STUDIO_BASE_URL}/course/${courseId}`); };
|
||||||
|
return (
|
||||||
|
<ModalNotification
|
||||||
|
isOpen={isErrorModalOpen}
|
||||||
|
title={intl.formatMessage(messages.errorTitle)}
|
||||||
|
message={
|
||||||
|
intl.formatMessage(
|
||||||
|
errorUnitUrl
|
||||||
|
? messages.errorDescriptionUnit
|
||||||
|
: messages.errorDescriptionNotUnit,
|
||||||
|
{ errorMessage: fetchExportErrorMessage },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
cancelButtonText={
|
||||||
|
intl.formatMessage(errorUnitUrl ? messages.errorCancelButtonUnit : messages.errorCancelButtonNotUnit)
|
||||||
|
}
|
||||||
|
actionButtonText={
|
||||||
|
intl.formatMessage(errorUnitUrl ? messages.errorActionButtonUnit : messages.errorActionButtonNotUnit)
|
||||||
|
}
|
||||||
|
handleCancel={() => setIsErrorModalOpen(false)}
|
||||||
|
handleAction={errorUnitUrl ? handleUnitRedirect : handleRedirectCourseHome}
|
||||||
|
variant="danger"
|
||||||
|
icon={ErrorIcon}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ExportModalError;
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// @ts-check
|
|
||||||
import { initializeMocks, render } from '../../testUtils';
|
|
||||||
import messages from './messages';
|
|
||||||
import ExportSidebar from './ExportSidebar';
|
|
||||||
|
|
||||||
const courseId = 'course-123';
|
|
||||||
|
|
||||||
describe('<ExportSidebar />', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
initializeMocks();
|
|
||||||
});
|
|
||||||
it('render sidebar correctly', () => {
|
|
||||||
const { getByText } = render(<ExportSidebar courseId={courseId} />);
|
|
||||||
expect(getByText(messages.title1.defaultMessage)).toBeInTheDocument();
|
|
||||||
expect(getByText(messages.exportedContentHeading.defaultMessage)).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
27
src/export-page/export-sidebar/ExportSidebar.test.tsx
Normal file
27
src/export-page/export-sidebar/ExportSidebar.test.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { initializeMocks, render, screen } from '@src/testUtils';
|
||||||
|
|
||||||
|
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
|
||||||
|
import messages from './messages';
|
||||||
|
import ExportSidebar from './ExportSidebar';
|
||||||
|
import { CourseExportProvider } from '../CourseExportContext';
|
||||||
|
|
||||||
|
const courseId = 'course-123';
|
||||||
|
|
||||||
|
const renderComponent = () => render(
|
||||||
|
<CourseAuthoringProvider courseId={courseId}>
|
||||||
|
<CourseExportProvider>
|
||||||
|
<ExportSidebar />
|
||||||
|
</CourseExportProvider>
|
||||||
|
</CourseAuthoringProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('<ExportSidebar />', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
initializeMocks();
|
||||||
|
});
|
||||||
|
it('render sidebar correctly', () => {
|
||||||
|
renderComponent();
|
||||||
|
expect(screen.getByText(messages.title1.defaultMessage)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(messages.exportedContentHeading.defaultMessage)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { Hyperlink } from '@openedx/paragon';
|
import { Hyperlink } from '@openedx/paragon';
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
|
||||||
import { HelpSidebar } from '../../generic/help-sidebar';
|
import { HelpSidebar } from '@src/generic/help-sidebar';
|
||||||
import { useHelpUrls } from '../../help-urls/hooks';
|
import { useHelpUrls } from '@src/help-urls/hooks';
|
||||||
|
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
|
||||||
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
const ExportSidebar = ({ courseId }) => {
|
const ExportSidebar = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const { courseId } = useCourseAuthoringContext();
|
||||||
const { exportCourse: exportLearnMoreUrl } = useHelpUrls(['exportCourse']);
|
const { exportCourse: exportLearnMoreUrl } = useHelpUrls(['exportCourse']);
|
||||||
return (
|
return (
|
||||||
<HelpSidebar courseId={courseId}>
|
<HelpSidebar courseId={courseId}>
|
||||||
@@ -33,13 +35,11 @@ const ExportSidebar = ({ courseId }) => {
|
|||||||
<h4 className="help-sidebar-about-title">{intl.formatMessage(messages.openDownloadFile)}</h4>
|
<h4 className="help-sidebar-about-title">{intl.formatMessage(messages.openDownloadFile)}</h4>
|
||||||
<p className="help-sidebar-about-descriptions">{intl.formatMessage(messages.openDownloadFileDescription)}</p>
|
<p className="help-sidebar-about-descriptions">{intl.formatMessage(messages.openDownloadFileDescription)}</p>
|
||||||
<hr />
|
<hr />
|
||||||
<Hyperlink className="small" href={exportLearnMoreUrl} target="_blank" variant="outline-primary">{intl.formatMessage(messages.learnMoreButtonTitle)}</Hyperlink>
|
<Hyperlink className="small" destination={exportLearnMoreUrl} target="_blank">
|
||||||
|
{intl.formatMessage(messages.learnMoreButtonTitle)}
|
||||||
|
</Hyperlink>
|
||||||
</HelpSidebar>
|
</HelpSidebar>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ExportSidebar.propTypes = {
|
|
||||||
courseId: PropTypes.string.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ExportSidebar;
|
export default ExportSidebar;
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { render } from '@testing-library/react';
|
|
||||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
|
||||||
import { initializeMockApp } from '@edx/frontend-platform';
|
|
||||||
import { AppProvider } from '@edx/frontend-platform/react';
|
|
||||||
|
|
||||||
import initializeStore from '../../store';
|
|
||||||
import messages from './messages';
|
|
||||||
import ExportStepper from './ExportStepper';
|
|
||||||
|
|
||||||
const courseId = 'course-123';
|
|
||||||
let store;
|
|
||||||
|
|
||||||
const RootWrapper = () => (
|
|
||||||
<AppProvider store={store}>
|
|
||||||
<IntlProvider locale="en" messages={{}}>
|
|
||||||
<ExportStepper courseId={courseId} />
|
|
||||||
</IntlProvider>
|
|
||||||
</AppProvider>
|
|
||||||
);
|
|
||||||
|
|
||||||
describe('<ExportStepper />', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
initializeMockApp({
|
|
||||||
authenticatedUser: {
|
|
||||||
userId: 3,
|
|
||||||
username: 'abc123',
|
|
||||||
administrator: true,
|
|
||||||
roles: [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
store = initializeStore();
|
|
||||||
});
|
|
||||||
it('render stepper correctly', () => {
|
|
||||||
const { getByText } = render(<RootWrapper />);
|
|
||||||
expect(getByText(messages.stepperHeaderTitle.defaultMessage)).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
27
src/export-page/export-stepper/ExportStepper.test.tsx
Normal file
27
src/export-page/export-stepper/ExportStepper.test.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { render, initializeMocks, screen } from '@src/testUtils';
|
||||||
|
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
|
||||||
|
|
||||||
|
import messages from './messages';
|
||||||
|
import ExportStepper from './ExportStepper';
|
||||||
|
import { CourseExportProvider } from '../CourseExportContext';
|
||||||
|
|
||||||
|
const courseId = 'course-123';
|
||||||
|
|
||||||
|
const renderComponent = () => render(
|
||||||
|
<CourseAuthoringProvider courseId={courseId}>
|
||||||
|
<CourseExportProvider>
|
||||||
|
<ExportStepper />
|
||||||
|
</CourseExportProvider>
|
||||||
|
</CourseAuthoringProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('<ExportStepper />', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
initializeMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('render stepper correctly', () => {
|
||||||
|
renderComponent();
|
||||||
|
expect(screen.getByText(messages.stepperHeaderTitle.defaultMessage)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,42 +1,23 @@
|
|||||||
import React, { useEffect } from 'react';
|
|
||||||
import { FormattedDate, useIntl } from '@edx/frontend-platform/i18n';
|
import { FormattedDate, useIntl } from '@edx/frontend-platform/i18n';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
|
||||||
import { Button } from '@openedx/paragon';
|
import { Button } from '@openedx/paragon';
|
||||||
|
|
||||||
import CourseStepper from '../../generic/course-stepper';
|
import CourseStepper from '@src/generic/course-stepper';
|
||||||
import {
|
|
||||||
getCurrentStage, getDownloadPath, getError, getLoadingStatus, getSuccessDate,
|
|
||||||
} from '../data/selectors';
|
|
||||||
import { fetchExportStatus } from '../data/thunks';
|
|
||||||
import { EXPORT_STAGES } from '../data/constants';
|
import { EXPORT_STAGES } from '../data/constants';
|
||||||
import { RequestStatus } from '../../data/constants';
|
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
import { useCourseExportContext } from '../CourseExportContext';
|
||||||
|
|
||||||
const ExportStepper = ({ courseId }) => {
|
const ExportStepper = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const currentStage = useSelector(getCurrentStage);
|
const {
|
||||||
const downloadPath = useSelector(getDownloadPath);
|
currentStage,
|
||||||
const successDate = useSelector(getSuccessDate);
|
successDate,
|
||||||
const loadingStatus = useSelector(getLoadingStatus);
|
fetchExportErrorMessage,
|
||||||
const { msg: errorMessage } = useSelector(getError);
|
downloadPath,
|
||||||
const dispatch = useDispatch();
|
} = useCourseExportContext();
|
||||||
const isStopFetching = currentStage === EXPORT_STAGES.SUCCESS
|
|
||||||
|| loadingStatus === RequestStatus.FAILED
|
|
||||||
|| errorMessage;
|
|
||||||
|
|
||||||
useEffect(() => {
|
const successTitle = intl.formatMessage(messages.stepperSuccessTitle);
|
||||||
const id = setInterval(() => {
|
let successTitleComponent;
|
||||||
if (isStopFetching) {
|
|
||||||
clearInterval(id);
|
|
||||||
} else {
|
|
||||||
dispatch(fetchExportStatus(courseId));
|
|
||||||
}
|
|
||||||
}, 3000);
|
|
||||||
return () => clearInterval(id);
|
|
||||||
});
|
|
||||||
|
|
||||||
let successTitle = intl.formatMessage(messages.stepperSuccessTitle);
|
|
||||||
const localizedSuccessDate = successDate ? (
|
const localizedSuccessDate = successDate ? (
|
||||||
<FormattedDate
|
<FormattedDate
|
||||||
value={successDate}
|
value={successDate}
|
||||||
@@ -49,12 +30,11 @@ const ExportStepper = ({ courseId }) => {
|
|||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
if (localizedSuccessDate && currentStage === EXPORT_STAGES.SUCCESS) {
|
if (localizedSuccessDate && currentStage === EXPORT_STAGES.SUCCESS) {
|
||||||
const successWithDate = (
|
successTitleComponent = (
|
||||||
<>
|
<>
|
||||||
{successTitle} ({localizedSuccessDate})
|
{successTitle} ({localizedSuccessDate})
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
successTitle = successWithDate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const steps = [
|
const steps = [
|
||||||
@@ -74,6 +54,7 @@ const ExportStepper = ({ courseId }) => {
|
|||||||
title: successTitle,
|
title: successTitle,
|
||||||
description: intl.formatMessage(messages.stepperSuccessDescription),
|
description: intl.formatMessage(messages.stepperSuccessDescription),
|
||||||
key: EXPORT_STAGES.SUCCESS,
|
key: EXPORT_STAGES.SUCCESS,
|
||||||
|
titleComponent: successTitleComponent,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -81,19 +62,18 @@ const ExportStepper = ({ courseId }) => {
|
|||||||
<div>
|
<div>
|
||||||
<h3 className="mt-4">{intl.formatMessage(messages.stepperHeaderTitle)}</h3>
|
<h3 className="mt-4">{intl.formatMessage(messages.stepperHeaderTitle)}</h3>
|
||||||
<CourseStepper
|
<CourseStepper
|
||||||
courseId={courseId}
|
|
||||||
steps={steps}
|
steps={steps}
|
||||||
activeKey={currentStage}
|
activeKey={currentStage}
|
||||||
errorMessage={errorMessage}
|
errorMessage={fetchExportErrorMessage}
|
||||||
hasError={!!errorMessage}
|
hasError={!!fetchExportErrorMessage}
|
||||||
/>
|
/>
|
||||||
{downloadPath && currentStage === EXPORT_STAGES.SUCCESS && <Button className="ml-5.5 mt-n2.5" href={downloadPath} download>{intl.formatMessage(messages.downloadCourseButtonTitle)}</Button>}
|
{downloadPath && currentStage === EXPORT_STAGES.SUCCESS && (
|
||||||
|
<Button className="ml-5.5 mt-n2.5" href={downloadPath}>
|
||||||
|
{intl.formatMessage(messages.downloadCourseButtonTitle)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ExportStepper.propTypes = {
|
|
||||||
courseId: PropTypes.string.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ExportStepper;
|
export default ExportStepper;
|
||||||
@@ -29,6 +29,11 @@ const messages = defineMessages({
|
|||||||
id: 'course-authoring.export.button.title',
|
id: 'course-authoring.export.button.title',
|
||||||
defaultMessage: 'Export course content',
|
defaultMessage: 'Export course content',
|
||||||
},
|
},
|
||||||
|
unknownError: {
|
||||||
|
id: 'course-authoring.export.error.unknown',
|
||||||
|
defaultMessage: 'An unexpected error occurred. Please try again.',
|
||||||
|
description: 'Fallback error message shown when the API returns an error in an unexpected format.',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default messages;
|
export default messages;
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ describe('setExportCookie', () => {
|
|||||||
it('should set the export cookie with the provided date and completed status', () => {
|
it('should set the export cookie with the provided date and completed status', () => {
|
||||||
const cookiesSetMock = jest.spyOn(Cookies.prototype, 'set');
|
const cookiesSetMock = jest.spyOn(Cookies.prototype, 'set');
|
||||||
const date = moment('2023-07-24').valueOf();
|
const date = moment('2023-07-24').valueOf();
|
||||||
const completed = true;
|
setExportCookie(date);
|
||||||
setExportCookie(date, completed);
|
|
||||||
|
|
||||||
expect(cookiesSetMock).toHaveBeenCalledWith(
|
expect(cookiesSetMock).toHaveBeenCalledWith(
|
||||||
LAST_EXPORT_COOKIE_NAME,
|
LAST_EXPORT_COOKIE_NAME,
|
||||||
{ date, completed },
|
{ date },
|
||||||
{ path: '/some-path' },
|
{ path: '/some-path' },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,11 @@ import { LAST_EXPORT_COOKIE_NAME, SUCCESS_DATE_FORMAT } from './data/constants';
|
|||||||
* Sets an export-related cookie with the provided information.
|
* Sets an export-related cookie with the provided information.
|
||||||
*
|
*
|
||||||
* @param date - Date of export (unix timestamp).
|
* @param date - Date of export (unix timestamp).
|
||||||
* @param {boolean} completed - Indicates if export was completed successfully.
|
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
export const setExportCookie = (date: number, completed: boolean): void => {
|
export const setExportCookie = (date: number): void => {
|
||||||
const cookies = new Cookies();
|
const cookies = new Cookies();
|
||||||
cookies.set(LAST_EXPORT_COOKIE_NAME, { date, completed }, { path: window.location.pathname });
|
cookies.set(LAST_EXPORT_COOKIE_NAME, { date }, { path: window.location.pathname });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { reducer as scheduleAndDetailsReducer } from './schedule-and-details/dat
|
|||||||
import { reducer as filesReducer } from './files-and-videos/files-page/data/slice';
|
import { reducer as filesReducer } from './files-and-videos/files-page/data/slice';
|
||||||
import { reducer as CourseUpdatesReducer } from './course-updates/data/slice';
|
import { reducer as CourseUpdatesReducer } from './course-updates/data/slice';
|
||||||
import { reducer as processingNotificationReducer } from './generic/processing-notification/data/slice';
|
import { reducer as processingNotificationReducer } from './generic/processing-notification/data/slice';
|
||||||
import { reducer as courseExportReducer } from './export-page/data/slice';
|
|
||||||
import { reducer as courseOptimizerReducer } from './optimizer-page/data/slice';
|
import { reducer as courseOptimizerReducer } from './optimizer-page/data/slice';
|
||||||
import { reducer as genericReducer } from './generic/data/slice';
|
import { reducer as genericReducer } from './generic/data/slice';
|
||||||
import { reducer as videosReducer } from './files-and-videos/videos-page/data/slice';
|
import { reducer as videosReducer } from './files-and-videos/videos-page/data/slice';
|
||||||
@@ -43,7 +42,6 @@ export interface DeprecatedReduxState {
|
|||||||
live: Record<string, any>;
|
live: Record<string, any>;
|
||||||
courseUpdates: Record<string, any>;
|
courseUpdates: Record<string, any>;
|
||||||
processingNotification: Record<string, any>;
|
processingNotification: Record<string, any>;
|
||||||
courseExport: Record<string, any>;
|
|
||||||
courseOptimizer: Record<string, any>;
|
courseOptimizer: Record<string, any>;
|
||||||
generic: Record<string, any>;
|
generic: Record<string, any>;
|
||||||
videos: Record<string, any>;
|
videos: Record<string, any>;
|
||||||
@@ -74,7 +72,6 @@ export default function initializeStore(preloadedState: Partial<DeprecatedReduxS
|
|||||||
live: liveReducer,
|
live: liveReducer,
|
||||||
courseUpdates: CourseUpdatesReducer,
|
courseUpdates: CourseUpdatesReducer,
|
||||||
processingNotification: processingNotificationReducer,
|
processingNotification: processingNotificationReducer,
|
||||||
courseExport: courseExportReducer,
|
|
||||||
courseOptimizer: courseOptimizerReducer,
|
courseOptimizer: courseOptimizerReducer,
|
||||||
generic: genericReducer,
|
generic: genericReducer,
|
||||||
videos: videosReducer,
|
videos: videosReducer,
|
||||||
|
|||||||
Reference in New Issue
Block a user