Skip to content

Commit

Permalink
fix: [AXIMST-769] Course unit - Added display of error alert (#233)
Browse files Browse the repository at this point in the history
* fix: [AXIMST-769] added display of error alert

* refactor: fixed tests
  • Loading branch information
PKulkoRaccoonGang authored and monteri committed May 3, 2024
1 parent f524a0e commit 6263c24
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const CourseUnit = ({ courseId }) => {
const intl = useIntl();
const {
isLoading,
isLoadingFailed,
sequenceId,
unitTitle,
errorMessage,
Expand Down Expand Up @@ -83,7 +84,7 @@ const CourseUnit = ({ courseId }) => {
return <Loading />;
}

if (sequenceStatus === RequestStatus.FAILED) {
if (isLoadingFailed || sequenceStatus === RequestStatus.FAILED) {
return (
<Container size="xl" className="course-unit px-4 mt-4">
<ConnectionErrorAlert />
Expand Down
6 changes: 3 additions & 3 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ describe('<CourseUnit />', () => {
store = initializeStore();
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock
.onGet(getCourseUnitApiUrl(courseId))
.onGet(getCourseUnitApiUrl(blockId))
.reply(200, courseUnitIndexMock);
await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);
await executeThunk(fetchCourseUnitQuery(blockId), store.dispatch);
axiosMock
.onGet(getCourseSectionVerticalApiUrl(blockId))
.reply(200, courseSectionVerticalMock);
Expand Down Expand Up @@ -1167,7 +1167,7 @@ describe('<CourseUnit />', () => {
.reply(200, { dummy: 'value' });
axiosMock
.onGet(getCourseUnitApiUrl(blockId))
.replyOnce(200, {
.reply(200, {
...courseUnitIndexMock,
visibility_state: UNIT_VISIBILITY_STATES.staffOnly,
has_explicit_staff_lock: true,
Expand Down
5 changes: 5 additions & 0 deletions src/course-unit/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export const getIsLoading = createSelector(
loadingStatus => Object.values(loadingStatus)
.some((status) => status === RequestStatus.IN_PROGRESS),
);
export const getIsLoadingFailed = createSelector(
[getLoadingStatuses],
loadingStatus => Object.values(loadingStatus)
.some((status) => status === RequestStatus.FAILED),
);
7 changes: 0 additions & 7 deletions src/course-unit/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ const slice = createSlice({
courseSectionVerticalLoadingStatus: payload.status,
};
},
updateLoadingCourseXblockStatus: (state, { payload }) => {
state.loadingStatus = {
...state.loadingStatus,
createUnitXblockLoadingStatus: payload.status,
};
},
addNewUnitStatus: (state, { payload }) => {
state.loadingStatus = {
...state.loadingStatus,
Expand Down Expand Up @@ -138,7 +132,6 @@ export const {
updateLoadingCourseSectionVerticalDataStatus,
changeEditTitleFormOpen,
updateQueryPendingStatus,
updateLoadingCourseXblockStatus,
updateCourseVerticalChildren,
updateCourseVerticalChildrenLoadingStatus,
deleteXBlock,
Expand Down
4 changes: 0 additions & 4 deletions src/course-unit/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
fetchSequenceSuccess,
fetchCourseSectionVerticalDataSuccess,
updateLoadingCourseSectionVerticalDataStatus,
updateLoadingCourseXblockStatus,
updateCourseVerticalChildren,
updateCourseVerticalChildrenLoadingStatus,
updateQueryPendingStatus,
Expand Down Expand Up @@ -154,7 +153,6 @@ export function editCourseUnitVisibilityAndData(itemId, type, isVisible, groupAc

export function createNewCourseXBlock(body, callback, blockId) {
return async (dispatch) => {
dispatch(updateLoadingCourseXblockStatus({ status: RequestStatus.IN_PROGRESS }));
dispatch(updateSavingStatus({ status: RequestStatus.PENDING }));

if (body.stagedContent) {
Expand Down Expand Up @@ -182,7 +180,6 @@ export function createNewCourseXBlock(body, callback, blockId) {
const courseVerticalChildrenData = await getCourseVerticalChildren(blockId);
dispatch(updateCourseVerticalChildren(courseVerticalChildrenData));
dispatch(hideProcessingNotification());
dispatch(updateLoadingCourseXblockStatus({ status: RequestStatus.SUCCESSFUL }));
dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL }));
if (callback) {
callback(result);
Expand All @@ -194,7 +191,6 @@ export function createNewCourseXBlock(body, callback, blockId) {
});
} catch (error) {
dispatch(hideProcessingNotification());
dispatch(updateLoadingCourseXblockStatus({ status: RequestStatus.FAILED }));
handleResponseErrors(error, dispatch, updateSavingStatus);
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getErrorMessage,
getSequenceStatus,
getStaticFileNotices,
getIsLoadingFailed,
} from './data/selectors';
import { changeEditTitleFormOpen, updateQueryPendingStatus } from './data/slice';
import { PUBLISH_TYPES } from './constants';
Expand All @@ -38,6 +39,7 @@ export const useCourseUnit = ({ courseId, blockId }) => {
const courseUnit = useSelector(getCourseUnitData);
const savingStatus = useSelector(getSavingStatus);
const isLoading = useSelector(getIsLoading);
const isLoadingFailed = useSelector(getIsLoadingFailed);
const errorMessage = useSelector(getErrorMessage);
const sequenceStatus = useSelector(getSequenceStatus);
const { draftPreviewLink, publishedPreviewLink } = useSelector(getCourseSectionVertical);
Expand Down Expand Up @@ -134,6 +136,7 @@ export const useCourseUnit = ({ courseId, blockId }) => {
staticFileNotices,
currentlyVisibleToStudents,
isLoading,
isLoadingFailed,
isTitleEditFormOpen,
sharedClipboardData,
showPasteXBlock,
Expand Down

0 comments on commit 6263c24

Please sign in to comment.