Skip to content

Commit

Permalink
refactor: address Nico's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sergivalero20 committed Mar 5, 2024
1 parent eda0642 commit 865c121
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ ACCOUNT_PROFILE_URL='http://localhost:1995/u'
MFE_CONFIG_API_URL='http://localhost:18000/api/mfe_config/v1'
INSTITUTION_PORTAL_PATH=''
COURSE_OPERATIONS_API_V2_BASE_URL='http://localhost:18000/pearson_course_operation/api/v2'
COURSE_OPERATIONS_API_METRICS_BASE_URL='http://localhost:18000/pearson_course_operation/api/metrics'
22 changes: 13 additions & 9 deletions src/features/Students/StudentsMetrics/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import 'features/Students/StudentsMetrics/index.scss';

const StudentsMetrics = () => {
const dispatch = useDispatch();
const selectedInstitution = useSelector((state) => state.main.selectedInstitution);
const stateStudentsMetrics = useSelector((state) => state.students.studentsMetrics.data);
const stateClassesMetrics = useSelector((state) => state.students.classesMetrics.data);
const institution = useSelector((state) => state.main.selectedInstitution);
const studentsMetrics = useSelector((state) => state.students.studentsMetrics.data);
const classesMetrics = useSelector((state) => state.students.classesMetrics.data);
const days = 100; // Temporal variable

useEffect(() => {
if (Object.keys(selectedInstitution).length > 0) {
dispatch(fetchStudentsMetricsData(selectedInstitution.id, days));
dispatch(fetchClassesMetricsData(selectedInstitution.id, days));
if (Object.keys(institution).length > 0) {
dispatch(fetchStudentsMetricsData(institution.id, days));
dispatch(fetchClassesMetricsData(institution.id, days));
}
}, [selectedInstitution, dispatch]);
}, [institution, dispatch]);

return (
<div className="container-cards d-flex flex-column">
Expand All @@ -45,15 +45,19 @@ const StudentsMetrics = () => {
title="New students registered"
/>
<Card.Section>
<div className="card-number">{stateStudentsMetrics.numberOfEnrollments}</div>
<p className="card-number">
{studentsMetrics.numberOfEnrollments ? studentsMetrics.numberOfEnrollments : '-'}
</p>
</Card.Section>
</Card>
<Card className="card-green">
<Card.Header
title="Classes scheduled"
/>
<Card.Section>
<div className="card-number">{stateClassesMetrics.numberOfClassesCreated}</div>
<p className="card-number">
{classesMetrics.numberOfClassesCreated ? classesMetrics.numberOfClassesCreated : '-'}
</p>
</Card.Section>
</Card>
</CardGrid>
Expand Down
17 changes: 15 additions & 2 deletions src/features/Students/StudentsPage/_test_/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,19 @@ const mockStore = {
num_pages: 1,
current_page: 1,
},
metrics: {
data: [],
classesMetrics: {
data: [
{
numberOfClassesCreated: 10,
}

Check failure on line 52 in src/features/Students/StudentsPage/_test_/index.test.jsx

View workflow job for this annotation

GitHub Actions / test

Missing trailing comma
],
},
studentsMetrics: {
data: [
{
numberOfEnrollments: 2,
}

Check failure on line 59 in src/features/Students/StudentsPage/_test_/index.test.jsx

View workflow job for this annotation

GitHub Actions / test

Missing trailing comma
],
},
classes: {
data: [],
Expand Down Expand Up @@ -75,6 +86,8 @@ describe('StudentsPage', () => {
expect(component.container).toHaveTextContent('Instructor 2');
expect(component.container).toHaveTextContent('active');
expect(component.container).toHaveTextContent('pending');
expect(component.container).toHaveTextContent('10');
expect(component.container).toHaveTextContent('2');
});
});
});

0 comments on commit 865c121

Please sign in to comment.