[TNL-11885] fix: resolve course-optimizer failure case bug (#1674)

* fix: resolve course-optimizer failure case bug

---------

Co-authored-by: Hina Khadim <hina.khadim@PF1H334R.2tor.net>
This commit is contained in:
Hina Khadim
2025-02-25 14:52:16 +05:00
committed by GitHub
parent 8fe52d22e7
commit 63caf098a5
4 changed files with 19 additions and 13 deletions

View File

@@ -59,7 +59,8 @@ const CourseOptimizerPage: FC<{ courseId: string }> = ({ courseId }) => {
const isSavingDenied = (RequestFailureStatuses as string[]).includes(savingStatus);
const interval = useRef<number | undefined>(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}
/>
</Card.Section>
)}
</Card>
{linkCheckPresent && <ScanResults data={linkCheckResult} />}
{(linkCheckPresent && linkCheckResult) && <ScanResults data={linkCheckResult} />}
</article>
</Layout.Element>
</Layout>

View File

@@ -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 = [

View File

@@ -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',
});

View File

@@ -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));
}