From 63caf098a57db870341166c26db182564d16377f Mon Sep 17 00:00:00 2001 From: Hina Khadim Date: Tue, 25 Feb 2025 14:52:16 +0500 Subject: [PATCH] [TNL-11885] fix: resolve course-optimizer failure case bug (#1674) * fix: resolve course-optimizer failure case bug --------- Co-authored-by: Hina Khadim --- src/optimizer-page/CourseOptimizerPage.tsx | 7 ++++--- src/optimizer-page/data/constants.ts | 8 ++++---- src/optimizer-page/data/thunks.test.js | 8 ++++---- src/optimizer-page/data/thunks.ts | 9 +++++++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/optimizer-page/CourseOptimizerPage.tsx b/src/optimizer-page/CourseOptimizerPage.tsx index f760e45fc..7fad8a7f7 100644 --- a/src/optimizer-page/CourseOptimizerPage.tsx +++ b/src/optimizer-page/CourseOptimizerPage.tsx @@ -59,7 +59,8 @@ const CourseOptimizerPage: FC<{ courseId: string }> = ({ courseId }) => { const isSavingDenied = (RequestFailureStatuses as string[]).includes(savingStatus); const interval = useRef(undefined); const courseDetails = useModel('courseDetails', courseId); - const linkCheckPresent = !!currentStage; + const linkCheckPresent = currentStage != null ? currentStage >= 0 : !!currentStage; + const intl = useIntl(); const courseStepperSteps = [ @@ -157,13 +158,13 @@ const CourseOptimizerPage: FC<{ courseId: string }> = ({ courseId }) => { // @ts-ignore steps={courseStepperSteps} activeKey={currentStage} - hasError={currentStage < 0 || !!errorMessage} + hasError={currentStage === 1 && !!errorMessage} errorMessage={errorMessage} /> )} - {linkCheckPresent && } + {(linkCheckPresent && linkCheckResult) && } diff --git a/src/optimizer-page/data/constants.ts b/src/optimizer-page/data/constants.ts index 3eca0838d..31d9a973b 100644 --- a/src/optimizer-page/data/constants.ts +++ b/src/optimizer-page/data/constants.ts @@ -18,13 +18,13 @@ export enum LinkCheckStatusTypes { RETRYING = 'Retrying', } export const SCAN_STAGES = { - [LINK_CHECK_STATUSES.UNINITIATED]: 0, - [LINK_CHECK_STATUSES.PENDING]: 1, + [LINK_CHECK_STATUSES.UNINITIATED]: -1, + [LINK_CHECK_STATUSES.PENDING]: 0, [LINK_CHECK_STATUSES.IN_PROGRESS]: 1, [LINK_CHECK_STATUSES.RETRYING]: 1, [LINK_CHECK_STATUSES.SUCCEEDED]: 2, - [LINK_CHECK_STATUSES.FAILED]: -1, - [LINK_CHECK_STATUSES.CANCELED]: -1, + [LINK_CHECK_STATUSES.FAILED]: 1, + [LINK_CHECK_STATUSES.CANCELED]: 1, }; export const LINK_CHECK_IN_PROGRESS_STATUSES = [ diff --git a/src/optimizer-page/data/thunks.test.js b/src/optimizer-page/data/thunks.test.js index 208b8f452..045ebb096 100644 --- a/src/optimizer-page/data/thunks.test.js +++ b/src/optimizer-page/data/thunks.test.js @@ -20,7 +20,7 @@ describe('startLinkCheck thunk', () => { describe('successful request', () => { it('should set link check stage and request statuses to their in-progress states', async () => { - const inProgressStageId = 1; + const inPendingStageId = 0; await startLinkCheck(courseId)(dispatch, getState); expect(dispatch).toHaveBeenCalledWith({ @@ -39,7 +39,7 @@ describe('startLinkCheck thunk', () => { }); expect(dispatch).toHaveBeenCalledWith({ - payload: inProgressStageId, + payload: inPendingStageId, type: 'courseOptimizer/updateCurrentStage', }); }); @@ -60,7 +60,7 @@ describe('startLinkCheck thunk', () => { type: 'courseOptimizer/updateLinkCheckInProgress', }); expect(dispatch).toHaveBeenCalledWith({ - payload: -1, + payload: 1, type: 'courseOptimizer/updateCurrentStage', }); }); @@ -180,7 +180,7 @@ describe('fetchLinkCheckStatus thunk', () => { }); expect(dispatch).toHaveBeenCalledWith({ - payload: -1, + payload: 1, type: 'courseOptimizer/updateCurrentStage', }); diff --git a/src/optimizer-page/data/thunks.ts b/src/optimizer-page/data/thunks.ts index 1fb3c5720..9bb8ee420 100644 --- a/src/optimizer-page/data/thunks.ts +++ b/src/optimizer-page/data/thunks.ts @@ -20,6 +20,7 @@ import { export function startLinkCheck(courseId: string) { return async (dispatch) => { + dispatch(updateError({ msg: null, unitUrl: null })); // Reset Error State when user click on Start scanning dispatch(updateSavingStatus({ status: RequestStatus.PENDING })); dispatch(updateLinkCheckInProgress(true)); dispatch(updateCurrentStage(SCAN_STAGES[LINK_CHECK_STATUSES.PENDING])); @@ -60,8 +61,12 @@ export function fetchLinkCheckStatus(courseId) { ) { dispatch(updateError({ msg: 'Link Check Failed' })); dispatch(updateIsErrorModalOpen(true)); - } else if (linkCheckOutput) { - dispatch(updateLinkCheckResult(linkCheckOutput)); + } else if (LINK_CHECK_STATUSES.SUCCEEDED === linkCheckStatus) { + if (linkCheckOutput) { + dispatch(updateLinkCheckResult(linkCheckOutput)); + } else { + dispatch(updateLinkCheckResult([])); + } dispatch(updateLastScannedAt(linkCheckCreatedAt)); }