Lk/fix filter (#320)

* fix: cohort and track filtering

* chore: normalize using response.data instead of chaining
This commit is contained in:
leangseu-edx
2023-03-23 11:16:23 -04:00
committed by GitHub
parent abc68f4224
commit 541a661dcc
11 changed files with 39 additions and 66 deletions

View File

@@ -12,7 +12,7 @@ export const getGradesUrl = () => `${getUrlPrefix()}grades/v1/`;
export const getGradebookUrl = () => `${getGradesUrl()}gradebook/${courseId}/`;
export const getBulkUpdateUrl = () => `${getGradebookUrl()}bulk-update`;
export const getInterventionUrl = () => `${getBulkGradesUrl()}intervention/`;
export const getCohortsUrl = () => `${getUrlPrefix()}courses/${courseId}/cohorts/`;
export const getCohortsUrl = () => `${getUrlPrefix()}cohorts/v1/courses/${courseId}/cohorts/`;
export const getTracksUrl = () => `${getEnrollmentUrl()}course/${courseId}?include_expired=1`;
export const getBulkHistoryUrl = () => `${getBulkUpdateUrl()}history/`;
export const getAssignmentTypesUrl = () => stringifyUrl(`${getGradebookUrl()}grading-info`, { graded_only: true });

View File

@@ -15,8 +15,7 @@ export const fetchAssignmentTypes = () => (
(dispatch) => {
dispatch(fetching.started());
return lms.api.fetch.assignmentTypes()
.then(response => response.data)
.then((data) => {
.then(({ data }) => {
dispatch(fetching.received(Object.keys(data.assignment_types)));
dispatch(gotGradesFrozen(data.grades_frozen));
dispatch(gotBulkManagementConfig(data.can_see_bulk_management));

View File

@@ -7,9 +7,8 @@ export const fetchCohorts = () => (
(dispatch) => {
dispatch(actions.cohorts.fetching.started());
return lms.api.fetch.cohorts()
.then(response => response.data)
.then((data) => {
dispatch(actions.cohorts.fetching.received(data.cohorts));
.then(({ data }) => {
dispatch(actions.cohorts.fetching.received(data));
})
.catch(() => {
dispatch(actions.cohorts.fetching.error());

View File

@@ -11,7 +11,7 @@ jest.mock('data/services/lms', () => ({
}));
const responseData = {
cohorts: {
data: {
some: 'COHorts',
other: 'cohORT$',
},
@@ -27,10 +27,10 @@ describe('cohorts thunkActions', () => {
);
describe('actions dispatched on valid response', () => {
test('fetching.started, fetching.received', () => testFetch(
(resolve) => resolve({ data: responseData }),
(resolve) => resolve(responseData),
[
actions.cohorts.fetching.started(),
actions.cohorts.fetching.received(responseData.cohorts),
actions.cohorts.fetching.received(responseData.data),
],
));
});

View File

@@ -39,24 +39,23 @@ export const fetchGrades = (overrides = {}) => (
cohort,
track,
fetchOptions,
).then(response => response.data)
.then((data) => {
dispatch(grades.fetching.received({
assignmentType: (assignmentType || selectors.filters.assignmentType(getState())),
cohort,
courseId,
track,
grades: data.results.sort(sortAlphaAsc),
prev: data.previous,
next: data.next,
totalUsersCount: data.total_users_count,
filteredUsersCount: data.filtered_users_count,
}));
if (fetchOptions.showSuccess) {
dispatch(grades.banner.open());
}
dispatch(grades.fetching.finished());
})
).then(({ data }) => {
dispatch(grades.fetching.received({
assignmentType: (assignmentType || selectors.filters.assignmentType(getState())),
cohort,
courseId,
track,
grades: data.results.sort(sortAlphaAsc),
prev: data.previous,
next: data.next,
totalUsersCount: data.total_users_count,
filteredUsersCount: data.filtered_users_count,
}));
if (fetchOptions.showSuccess) {
dispatch(grades.banner.open());
}
dispatch(grades.fetching.finished());
})
.catch(() => {
dispatch(grades.fetching.error());
});
@@ -73,8 +72,7 @@ export const fetchGradesIfAssignmentGradeFiltersSet = () => (
export const fetchGradeOverrideHistory = (subsectionId, userId) => (
dispatch => lms.api.fetch.gradeOverrideHistory(subsectionId, userId)
.then(response => response.data)
.then((data) => {
.then(({ data }) => {
if (data.success) {
dispatch(grades.overrideHistory.received({
overrideHistory: formatGradeOverrideForDisplay(data.history),
@@ -147,8 +145,7 @@ export const updateGrades = () => (
const updateData = selectors.app.editUpdateData(getState());
dispatch(grades.update.request());
return lms.api.updateGradebookData(updateData)
.then(response => response.data)
.then((data) => {
.then(({ data }) => {
dispatch(grades.update.success({ data }));
dispatch(module.fetchGrades({
assignmentType: defaultAssignmentFilter,

View File

@@ -16,12 +16,11 @@ export const fetchRoles = () => (
(dispatch, getState) => {
const courseId = selectors.app.courseId(getState());
return lms.api.fetch.roles()
.then(response => response.data)
.then((response) => {
.then(({ data }) => {
const isAllowedRole = (role) => (
(role.course_id === courseId) && allowedRoles.includes(role.role)
);
const canUserViewGradebook = (response.is_staff || (response.roles.some(isAllowedRole)));
const canUserViewGradebook = (data.is_staff || (data.roles.some(isAllowedRole)));
dispatch(roles.fetching.received({ canUserViewGradebook }));
if (canUserViewGradebook) {
dispatch(fetchGrades());

View File

@@ -8,8 +8,7 @@ export const fetchTracks = () => (
(dispatch) => {
dispatch(actions.tracks.fetching.started());
return lms.api.fetch.tracks()
.then(response => response.data)
.then((data) => {
.then(({ data }) => {
dispatch(actions.tracks.fetching.received(data.course_modes));
})
.catch(() => {