From e396b1cd34692d0ff0a3e318457a4f4f31d5542f Mon Sep 17 00:00:00 2001
From: Peter Kulko <93188219+PKulkoRaccoonGang@users.noreply.github.com>
Date: Mon, 29 Jan 2024 15:10:58 +0200
Subject: [PATCH] fix: replaced the LMS endpoint for navigating the course unit
page
fix: [AXIMST-424] Course unit - Fixed network connection behavior (#138)
* fix: [AXIMST-424] fixed network connetcion behavior
* fix: added placeholder for unsuccessful loading for the page
* refactor: code refactoring
---
src/course-unit/CourseUnit.jsx | 10 +
.../__mocks__/courseSectionVertical.js | 4 +
src/course-unit/course-sequence/hooks.js | 12 +-
.../SequenceNavigation.jsx | 4 +-
src/course-unit/data/api.js | 51 +----
src/course-unit/data/selectors.js | 29 +--
src/course-unit/data/slice.js | 20 --
src/course-unit/data/thunk.js | 94 +--------
src/course-unit/data/utils.js | 191 +-----------------
src/course-unit/hooks.jsx | 7 +-
10 files changed, 31 insertions(+), 391 deletions(-)
diff --git a/src/course-unit/CourseUnit.jsx b/src/course-unit/CourseUnit.jsx
index 8a117abab3..b2cda53184 100644
--- a/src/course-unit/CourseUnit.jsx
+++ b/src/course-unit/CourseUnit.jsx
@@ -13,6 +13,7 @@ import getPageHeadTitle from '../generic/utils';
import AlertMessage from '../generic/alert-message';
import ProcessingNotification from '../generic/processing-notification';
import InternetConnectionAlert from '../generic/internet-connection-alert';
+import ConnectionErrorAlert from '../generic/ConnectionErrorAlert';
import Loading from '../generic/Loading';
import AddComponent from './add-component/AddComponent';
import CourseXBlock from './course-xblock/CourseXBlock';
@@ -32,6 +33,7 @@ const CourseUnit = ({ courseId }) => {
sequenceId,
unitTitle,
isQueryPending,
+ sequenceStatus,
savingStatus,
isTitleEditFormOpen,
isErrorAlert,
@@ -57,6 +59,14 @@ const CourseUnit = ({ courseId }) => {
return ;
}
+ if (sequenceStatus === RequestStatus.FAILED) {
+ return (
+
+
+
+ );
+ }
+
return (
<>
diff --git a/src/course-unit/__mocks__/courseSectionVertical.js b/src/course-unit/__mocks__/courseSectionVertical.js
index ceea70fd55..67d57c2e62 100644
--- a/src/course-unit/__mocks__/courseSectionVertical.js
+++ b/src/course-unit/__mocks__/courseSectionVertical.js
@@ -289,6 +289,10 @@ module.exports = {
},
},
],
+ course_sequence_ids: [
+ 'block-v1:edx+876+2030+type@sequential+block@297321078a0f4c26a50d671ed87642a6',
+ 'block-v1:edx+876+2030+type@sequential+block@4e91bdfefd8e4173a03d19c4d91e1936',
+ ],
xblock_info: {
id: 'block-v1:edX+DemoX+Demo_Course+type@vertical+block@867dddb6f55d410caaa9c1eb9c6743ec',
display_name: 'Getting Started',
diff --git a/src/course-unit/course-sequence/hooks.js b/src/course-unit/course-sequence/hooks.js
index 043a693fff..28035e1afd 100644
--- a/src/course-unit/course-sequence/hooks.js
+++ b/src/course-unit/course-sequence/hooks.js
@@ -3,20 +3,14 @@ import { useLayoutEffect, useRef, useState } from 'react';
import { useWindowSize } from '@openedx/paragon';
import { useModel } from '../../generic/model-store';
-import {
- getCourseSectionVertical,
- getCourseUnit,
- sequenceIdsSelector,
-} from '../data/selectors';
+import { getCourseSectionVertical, getSequenceIds } from '../data/selectors';
-export function useSequenceNavigationMetadata(currentSequenceId, currentUnitId) {
- const sequenceIds = useSelector(sequenceIdsSelector);
+export function useSequenceNavigationMetadata(courseId, currentSequenceId, currentUnitId) {
const { nextUrl, prevUrl } = useSelector(getCourseSectionVertical);
const sequence = useModel('sequences', currentSequenceId);
- const { courseId } = useSelector(getCourseUnit);
const isFirstUnit = !prevUrl;
const isLastUnit = !nextUrl;
-
+ const sequenceIds = useSelector(getSequenceIds);
const sequenceIndex = sequenceIds.indexOf(currentSequenceId);
const unitIndex = sequence.unitIds.indexOf(currentUnitId);
diff --git a/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx b/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx
index e7a47ec748..a2fbe55d4e 100644
--- a/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx
+++ b/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx
@@ -20,6 +20,7 @@ import SequenceNavigationTabs from './SequenceNavigationTabs';
const SequenceNavigation = ({
intl,
+ courseId,
unitId,
sequenceId,
className,
@@ -28,7 +29,7 @@ const SequenceNavigation = ({
const sequenceStatus = useSelector(getSequenceStatus);
const {
isFirstUnit, isLastUnit, nextLink, previousLink,
- } = useSequenceNavigationMetadata(sequenceId, unitId);
+ } = useSequenceNavigationMetadata(courseId, sequenceId, unitId);
const sequence = useModel('sequences', sequenceId);
const shouldDisplayNotificationTriggerInSequence = useWindowSize().width < breakpoints.small.minWidth;
@@ -104,6 +105,7 @@ const SequenceNavigation = ({
SequenceNavigation.propTypes = {
intl: intlShape.isRequired,
+ courseId: PropTypes.string.isRequired,
unitId: PropTypes.string,
className: PropTypes.string,
sequenceId: PropTypes.string,
diff --git a/src/course-unit/data/api.js b/src/course-unit/data/api.js
index f7adc33b47..6520d1e1de 100644
--- a/src/course-unit/data/api.js
+++ b/src/course-unit/data/api.js
@@ -3,23 +3,13 @@ import { camelCaseObject, getConfig } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { PUBLISH_TYPES } from '../constants';
-import {
- normalizeLearningSequencesData,
- normalizeMetadata,
- normalizeCourseHomeCourseMetadata,
- appendBrowserTimezoneToUrl,
- normalizeCourseSectionVerticalData,
-} from './utils';
+import { normalizeCourseSectionVerticalData } from './utils';
const getStudioBaseUrl = () => getConfig().STUDIO_BASE_URL;
-const getLmsBaseUrl = () => getConfig().LMS_BASE_URL;
export const getCourseUnitApiUrl = (itemId) => `${getStudioBaseUrl()}/xblock/container/${itemId}`;
export const getXBlockBaseApiUrl = (itemId) => `${getStudioBaseUrl()}/xblock/${itemId}`;
export const getCourseSectionVerticalApiUrl = (itemId) => `${getStudioBaseUrl()}/api/contentstore/v1/container_handler/${itemId}`;
-export const getLearningSequencesOutlineApiUrl = (courseId) => `${getLmsBaseUrl()}/api/learning_sequences/v1/course_outline/${courseId}`;
-export const getCourseMetadataApiUrl = (courseId) => `${getLmsBaseUrl()}/api/courseware/course/${courseId}`;
-export const getCourseHomeCourseMetadataApiUrl = (courseId) => `${getLmsBaseUrl()}/api/course_home/course_metadata/${courseId}`;
export const getCourseVerticalChildrenApiUrl = (itemId) => `${getStudioBaseUrl()}/api/contentstore/v1/container/vertical/${itemId}/children`;
export const postXBlockBaseApiUrl = () => `${getStudioBaseUrl()}/xblock/`;
@@ -65,45 +55,6 @@ export async function getCourseSectionVerticalData(unitId) {
return normalizeCourseSectionVerticalData(data);
}
-/**
- * Retrieves the outline of learning sequences for a specific course.
- * @param {string} courseId - The ID of the course.
- * @returns {Promise