feat: added process to sync discussions topic on page load

feat: added process to sync discussions topic on page load

fix: updated failing unit tests

feat: added course creation date in index api

feat: added course creation date in index api

fix: updated unit tests
This commit is contained in:
Ahtisham Shahid
2025-05-13 14:22:56 +05:00
committed by Muhammad Faraz Maqsood
parent 951b707c7d
commit 5167b167eb
6 changed files with 42 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ import { RequestStatus } from '../data/constants';
import {
fetchCourseBestPracticesQuery,
fetchCourseLaunchQuery,
fetchCourseOutlineIndexQuery,
fetchCourseOutlineIndexQuery, syncDiscussionsTopics,
updateCourseSectionHighlightsQuery,
} from './data/thunk';
import initializeStore from '../store';
@@ -126,6 +126,10 @@ jest.mock('@dnd-kit/core', () => ({
closestCorners: jest.fn(),
}));
jest.mock('./data/api', () => ({
...jest.requireActual('./data/api'),
createDiscussionsTopics: jest.fn().mockResolvedValue(undefined),
}));
// eslint-disable-next-line no-promise-executor-return
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -173,6 +177,7 @@ describe('<CourseOutline />', () => {
}))
.reply(200, courseLaunchMock);
await executeThunk(fetchCourseOutlineIndexQuery(courseId), store.dispatch);
await executeThunk(syncDiscussionsTopics(courseId), store.dispatch);
});
afterEach(() => {

View File

@@ -59,6 +59,17 @@ export async function getCourseOutlineIndex(courseId) {
return camelCaseObject(data);
}
/**
*
* @param courseId
* @returns {Promise<Array|Object>}
*/
export async function createDiscussionsTopics(courseId) {
const { data } = await getAuthenticatedHttpClient()
.post(`${getApiBaseUrl()}/api/discussions/v0/course/${courseId}/sync_discussion_topics`);
return camelCaseObject(data);
}
/**
* Get course best practices.
* @param {{courseId: string, excludeGraded: boolean, all: boolean}} options

View File

@@ -11,3 +11,4 @@ export const getCustomRelativeDatesActiveFlag = (state) => state.courseOutline.i
export const getProctoredExamsFlag = (state) => state.courseOutline.enableProctoredExams;
export const getPasteFileNotices = (state) => state.courseOutline.pasteFileNotices;
export const getErrors = (state) => state.courseOutline.errors;
export const getCreatedOn = (state) => state.courseOutline.createdOn;

View File

@@ -47,6 +47,7 @@ const slice = createSlice({
},
enableProctoredExams: false,
pasteFileNotices: {},
createdOn: null,
},
reducers: {
fetchOutlineIndexSuccess: (state, { payload }) => {
@@ -54,6 +55,7 @@ const slice = createSlice({
state.sectionsList = payload.courseStructure?.childInfo?.children || [];
state.isCustomRelativeDatesActive = payload.isCustomRelativeDatesActive;
state.enableProctoredExams = payload.courseStructure?.enableProctoredExams;
state.createdOn = payload.createdOn;
},
updateOutlineIndexLoadingStatus: (state, { payload }) => {
state.loadingStatus = {

View File

@@ -30,7 +30,7 @@ import {
setVideoSharingOption,
setCourseItemOrderList,
pasteBlock,
dismissNotification,
dismissNotification, createDiscussionsTopics,
} from './api';
import {
addSection,
@@ -95,6 +95,17 @@ export function fetchCourseOutlineIndexQuery(courseId) {
};
}
export function syncDiscussionsTopics(courseId) {
return async () => {
try {
await createDiscussionsTopics(courseId);
} catch (error) {
// eslint-disable-next-line no-console
console.log('There was an issue in discussion topic sync', error);
}
};
}
export function fetchCourseLaunchQuery({
courseId,
gradedOnly = true,

View File

@@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom';
import { useToggle } from '@openedx/paragon';
import { getConfig } from '@edx/frontend-platform';
import moment from 'moment';
import { getSavingStatus as getGenericSavingStatus } from '../generic/data/selectors';
import { getWaffleFlags } from '../data/selectors';
import { RequestStatus } from '../data/constants';
@@ -25,6 +26,7 @@ import {
getCurrentSubsection,
getCustomRelativeDatesActiveFlag,
getErrors,
getCreatedOn,
} from './data/selectors';
import {
addNewSectionQuery,
@@ -53,7 +55,7 @@ import {
setUnitOrderListQuery,
pasteClipboardContent,
dismissNotificationQuery,
addUnitFromLibrary,
addUnitFromLibrary, syncDiscussionsTopics,
} from './data/thunk';
const useCourseOutline = ({ courseId }) => {
@@ -73,7 +75,7 @@ const useCourseOutline = ({ courseId }) => {
mfeProctoredExamSettingsUrl,
advanceSettingsUrl,
} = useSelector(getOutlineIndexData);
const createdOn = useSelector(getCreatedOn);
const { outlineIndexLoadingStatus, reIndexLoadingStatus } = useSelector(getLoadingStatus);
const statusBarData = useSelector(getStatusBarData);
const savingStatus = useSelector(getSavingStatus);
@@ -292,6 +294,12 @@ const useCourseOutline = ({ courseId }) => {
dispatch(fetchCourseLaunchQuery({ courseId }));
}, [courseId]);
useEffect(() => {
if (createdOn && moment(new Date(createdOn)).isAfter(moment().subtract(31, 'days'))) {
dispatch(syncDiscussionsTopics);
}
}, [createdOn]);
useEffect(() => {
setShowSuccessAlert(reIndexLoadingStatus === RequestStatus.SUCCESSFUL);
}, [reIndexLoadingStatus]);