Skip to content

Commit

Permalink
fix: filter classes by courseId
Browse files Browse the repository at this point in the history
  • Loading branch information
sergivalero20 committed Jun 20, 2024
1 parent c5c9311 commit 3ce496a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/features/Classes/ClassesTable/columns.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const columns = [
accessor: 'className',
Cell: ({ row }) => (
<Link
to={`/courses/${row.values.masterCourseName}/${row.values.className}?classId=${row.original.classId}&previous=classes`}
to={`/courses/${row.original.masterCourseId}/${row.values.className}?classId=${row.original.classId}&previous=classes`}
className="text-truncate link"
>
{row.values.className}
Expand Down
6 changes: 4 additions & 2 deletions src/features/Classes/data/_test_/redux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ describe('Classes redux tests', () => {
});

test('successful fetch classes data', async () => {
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`;
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`;
const mockResponse = {
results: [
{
masterCourseId: 'course-v1:USB+CCD+2023',
masterCourseName: 'Demo MasterCourse 1',
className: 'Demo Class 1',
startDate: '09/21/24',
Expand Down Expand Up @@ -91,9 +92,10 @@ describe('Classes redux tests', () => {
});

test('successful fetch all classes data', async () => {
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`;
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`;
const mockResponse = [
{
masterCourseId: 'course-v1:USB+CCD+2023',
masterCourseName: 'Demo MasterCourse 1',
className: 'Demo Class 1',
startDate: '09/21/24',
Expand Down
8 changes: 4 additions & 4 deletions src/features/Classes/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
import { getClassesByInstitution } from 'features/Common/data/api';
import { initialPage } from 'features/constants';

function fetchClassesData(id, currentPage, courseName = '', urlParamsFilters = '', limit = true) {
function fetchClassesData(id, currentPage, courseId = '', urlParamsFilters = '', limit = true) {
return async (dispatch) => {
dispatch(fetchClassesDataRequest());

try {
const response = camelCaseObject(
await getClassesByInstitution(id, courseName, limit, currentPage, urlParamsFilters),
await getClassesByInstitution(id, courseId, limit, currentPage, urlParamsFilters),
);
dispatch(fetchClassesDataSuccess(response.data));
} catch (error) {
Expand All @@ -43,13 +43,13 @@ function fetchClassesOptionsData(id, courseName) {
};
}

function fetchAllClassesData(id, courseName = '', urlParamsFilters = '', limit = false) {
function fetchAllClassesData(id, courseId = '', urlParamsFilters = '', limit = false) {
return async (dispatch) => {
dispatch(fetchAllClassesDataRequest());

try {
const response = camelCaseObject(
await getClassesByInstitution(id, courseName, limit, initialPage, urlParamsFilters),
await getClassesByInstitution(id, courseId, limit, initialPage, urlParamsFilters),
);
dispatch(fetchAllClassesDataSuccess(response.data));
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/features/Common/data/_test_/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ describe('Common api services', () => {
};

const institutionId = 1;
const courseName = 'ccx1';
const courseId = 'course-v1';

getAuthenticatedHttpClient.mockReturnValue(httpClientMock);

getClassesByInstitution(institutionId, courseName);
getClassesByInstitution(institutionId, courseId);

expect(getAuthenticatedHttpClient).toHaveBeenCalledTimes(1);
expect(getAuthenticatedHttpClient).toHaveBeenCalledWith();

expect(httpClientMock.get).toHaveBeenCalledTimes(1);
expect(httpClientMock.get).toHaveBeenCalledWith(
`${COURSE_OPERATIONS_API_V2}/classes/?course_name=ccx1`,
`${COURSE_OPERATIONS_API_V2}/classes/?course_id=course-v1`,
{
params: {
institution_id: 1, limit: false, page: '',
Expand Down
6 changes: 3 additions & 3 deletions src/features/Common/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ function getLicensesByInstitution(institutionId, limit, page = 1, urlParamsFilte
);
}

function getClassesByInstitution(institutionId, courseName, limit = false, page = '', urlParamsFilters = '') {
const encodedCourseName = encodeURIComponent(courseName);
function getClassesByInstitution(institutionId, courseId, limit = false, page = '', urlParamsFilters = '') {
const encodedCourseId = encodeURIComponent(courseId);
const params = {
limit,
institution_id: institutionId,
page,
...urlParamsFilters,
};
return getAuthenticatedHttpClient().get(
`${getConfig().COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=${encodedCourseName}`,
`${getConfig().COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=${encodedCourseId}`,
{ params },
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/features/Courses/CoursesDetailPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CoursesDetailPage = () => {
numberOfStudents: '-',
numberOfPendingStudents: '-',
masterCourseId: '-',
masterCourseName: '-',
masterCourseName: '',
};

const courseInfo = useSelector((state) => state.courses.table.data)
Expand All @@ -51,7 +51,7 @@ const CoursesDetailPage = () => {
};

if (institution.id) {
dispatch(fetchClassesData(institution.id, initialPage, courseInfo.masterCourseName));
dispatch(fetchClassesData(institution.id, initialPage, courseId));
dispatch(fetchCoursesData(institution.id, initialPage, null));
}

Expand All @@ -62,7 +62,7 @@ const CoursesDetailPage = () => {
}, [dispatch, institution.id, courseId]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
dispatch(fetchClassesData(institution.id, currentPage, courseInfo.masterCourseName));
dispatch(fetchClassesData(institution.id, currentPage, courseId));
}, [currentPage]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
Expand All @@ -82,7 +82,7 @@ const CoursesDetailPage = () => {
<Link to="/courses" className="mr-3 link">
<i className="fa-solid fa-arrow-left" />
</Link>
<h3 className="h2 mb-0 course-title">{courseId}</h3>
<h3 className="h2 mb-0 course-title">{courseInfo.masterCourseName}</h3>
</div>

<div className="card-container d-flex justify-content-around align-items-center">
Expand Down
6 changes: 4 additions & 2 deletions src/features/Dashboard/data/_test_/redux.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ describe('Dashboard redux tests', () => {
});

test('successful fetch classesNoInstructors data', async () => {
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`;
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`;
const mockResponse = [
{
classId: 'ccx-v1:demo+demo1+2020+ccx1',
className: 'ccx 1',
masterCourseId: 'course-v1:USB+CCD+2023',
masterCourseName: 'Demo Course 1',
instructors: [],
numberOfStudents: 0,
Expand Down Expand Up @@ -125,11 +126,12 @@ describe('Dashboard redux tests', () => {
});

test('successful fetch classes data', async () => {
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`;
const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`;
const mockResponse = [
{
classId: 'ccx-v1:demo+demo1+2020+ccx1',
className: 'ccx 1',
masterCourseId: 'course-v1:USB+CCD+2023',
masterCourseName: 'Demo Course 1',
instructors: [],
numberOfStudents: 0,
Expand Down

0 comments on commit 3ce496a

Please sign in to comment.