Skip to content

Commit

Permalink
fix: [AXIMST-558] Course unit - Fixed loading errors and PropTypes (#199
Browse files Browse the repository at this point in the history
)

* fix: [AXIMST-558] fixed Course unit loading

* refactor: changed selector name
  • Loading branch information
PKulkoRaccoonGang committed Mar 18, 2024
1 parent 07819b8 commit fb9c34d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,9 @@ describe('<CourseUnit />', () => {

userEvent.click(getByRole('button', { name: pasteComponentMessages.pasteComponentButtonText.defaultMessage }));

expect(getAllByTestId('course-xblock')).toHaveLength(2);
await waitFor(() => {
expect(getAllByTestId('course-xblock')).toHaveLength(2);
});

axiosMock
.onGet(getCourseVerticalChildrenApiUrl(blockId))
Expand Down Expand Up @@ -1097,9 +1099,11 @@ describe('<CourseUnit />', () => {
courseUnitMock,
]);

units = getAllByTestId('course-unit-btn');
const courseUnits = courseSectionVerticalMock.xblock_info.ancestor_info.ancestors[0].child_info.children;
expect(units).toHaveLength(courseUnits.length);
await waitFor(() => {
units = getAllByTestId('course-unit-btn');
const courseUnits = courseSectionVerticalMock.xblock_info.ancestor_info.ancestors[0].child_info.children;
expect(units).toHaveLength(courseUnits.length);
});

axiosMock
.onPost(postXBlockBaseApiUrl(), postXBlockBody)
Expand Down
4 changes: 1 addition & 3 deletions src/course-unit/clipboard/paste-notification/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ const PastNotificationAlert = ({ staticFileNotices, courseId }) => {

PastNotificationAlert.propTypes = {
courseId: PropTypes.string.isRequired,
staticFileNotices: PropTypes.oneOfType([
staticFileNotices:
PropTypes.objectOf({
conflictingFiles: PropTypes.arrayOf(PropTypes.string),
errorFiles: PropTypes.arrayOf(PropTypes.string),
newFiles: PropTypes.arrayOf(PropTypes.string),
}),
PropTypes.arrayOf(PropTypes.string),
]),
};

PastNotificationAlert.defaultProps = {
Expand Down
12 changes: 10 additions & 2 deletions src/course-unit/data/selectors.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createSelector } from '@reduxjs/toolkit';
import { RequestStatus } from 'CourseAuthoring/data/constants';

export const getCourseUnitData = (state) => state.courseUnit.unit;
export const getCanEdit = (state) => state.courseUnit.canEdit;
export const getStaticFileNotices = (state) => state.courseUnit.staticFileNotices;
export const getCourseUnit = (state) => state.courseUnit;
export const getSavingStatus = (state) => state.courseUnit.savingStatus;
export const getLoadingStatus = (state) => state.courseUnit.loadingStatus;
export const getSequenceStatus = (state) => state.courseUnit.sequenceStatus;
export const getSequenceIds = (state) => state.courseUnit.courseSectionVertical.courseSequenceIds;
export const getCourseSectionVertical = (state) => state.courseUnit.courseSectionVertical;
export const getCourseId = (state) => state.courseDetail.courseId;
export const getSequenceId = (state) => state.courseUnit.sequenceId;
export const getCourseVerticalChildren = (state) => state.courseUnit.courseVerticalChildren;
export const getClipboardData = state => state.courseUnit.clipboardData;
export const getClipboardData = (state) => state.courseUnit.clipboardData;
const getLoadingStatuses = (state) => state.courseUnit.loadingStatus;
export const getIsLoading = createSelector(
[getLoadingStatuses],
loadingStatus => Object.values(loadingStatus)
.some((status) => status === RequestStatus.IN_PROGRESS),
);
7 changes: 3 additions & 4 deletions src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
getCourseSectionVertical,
getCourseVerticalChildren,
getCourseUnitData,
getLoadingStatus,
getIsLoading,
getSavingStatus,
getSequenceStatus,
getStaticFileNotices,
Expand All @@ -35,7 +35,7 @@ export const useCourseUnit = ({ courseId, blockId }) => {
const [hasInternetConnectionError, setInternetConnectionError] = useState(false);
const courseUnit = useSelector(getCourseUnitData);
const savingStatus = useSelector(getSavingStatus);
const loadingStatus = useSelector(getLoadingStatus);
const isLoading = useSelector(getIsLoading);
const sequenceStatus = useSelector(getSequenceStatus);
const { draftPreviewLink, publishedPreviewLink } = useSelector(getCourseSectionVertical);
const courseVerticalChildren = useSelector(getCourseVerticalChildren);
Expand Down Expand Up @@ -125,8 +125,7 @@ export const useCourseUnit = ({ courseId, blockId }) => {
isErrorAlert,
staticFileNotices,
currentlyVisibleToStudents,
isLoading: loadingStatus.fetchUnitLoadingStatus === RequestStatus.IN_PROGRESS
|| loadingStatus.courseSectionVerticalLoadingStatus === RequestStatus.IN_PROGRESS,
isLoading,
isTitleEditFormOpen,
isInternetConnectionAlertFailed: savingStatus === RequestStatus.FAILED,
sharedClipboardData,
Expand Down

0 comments on commit fb9c34d

Please sign in to comment.