generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Pearson-Advance/vue/PADV-889
PADV-889 feat: Add metrics students panel
- Loading branch information
Showing
12 changed files
with
266 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/features/Students/StudentsMetrics/_test_/index.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import StudentsMetrics from 'features/Students/StudentsMetrics'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
describe('StudentsMetrics component', () => { | ||
test('renders components', () => { | ||
const { getByText } = render( | ||
<StudentsMetrics />, | ||
); | ||
|
||
expect(getByText('This week')).toBeInTheDocument(); | ||
expect(getByText('Next week')).toBeInTheDocument(); | ||
expect(getByText('Next month')).toBeInTheDocument(); | ||
expect(getByText('New students registered')).toBeInTheDocument(); | ||
expect(getByText('Classes scheduled')).toBeInTheDocument(); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
src/features/Students/StudentsMetrics/_test_/reducer.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
FETCH_METRICS_DATA_REQUEST, | ||
FETCH_METRICS_DATA_SUCCESS, | ||
FETCH_METRICS_DATA_FAILURE, | ||
} from 'features/Students/actionTypes'; | ||
import { RequestStatus } from 'features/constants'; | ||
import reducer from 'features/Students/StudentsMetrics/reducer'; | ||
|
||
describe('Student filter reducers', () => { | ||
const initialState = { | ||
data: [], | ||
status: RequestStatus.SUCCESS, | ||
error: null, | ||
}; | ||
|
||
test('should handle FETCH_METRICS_DATA_REQUEST', () => { | ||
const state = { | ||
...initialState, | ||
status: RequestStatus.LOADING, | ||
}; | ||
const action = { | ||
type: FETCH_METRICS_DATA_REQUEST, | ||
}; | ||
expect(reducer(state, action)).toEqual(state); | ||
}); | ||
|
||
test('should handle FETCH_METRICS_DATA_SUCCESS', () => { | ||
const state = { | ||
...initialState, | ||
status: RequestStatus.SUCCESS, | ||
data: [], | ||
}; | ||
const action = { | ||
type: FETCH_METRICS_DATA_SUCCESS, | ||
payload: [], | ||
}; | ||
expect(reducer(state, action)).toEqual(state); | ||
}); | ||
|
||
test('should handle FETCH_METRICS_DATA_FAILURE', () => { | ||
const state = { | ||
...initialState, | ||
status: RequestStatus.ERROR, | ||
error: '', | ||
}; | ||
const action = { | ||
type: FETCH_METRICS_DATA_FAILURE, | ||
payload: '', | ||
}; | ||
expect(reducer(state, action)).toEqual(state); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useEffect, useReducer } from 'react'; | ||
import { Card, CardGrid, ToggleButton } from '@edx/paragon'; | ||
import { ToggleButtonGroup } from 'react-paragon-topaz'; | ||
import { logError } from '@edx/frontend-platform/logging'; | ||
import { camelCaseObject } from '@edx/frontend-platform'; | ||
import { getMetricsStudents } from 'features/Students/data/api'; | ||
import { RequestStatus } from 'features/constants'; | ||
import reducer from 'features/Students/StudentsMetrics/reducer'; | ||
import { | ||
FETCH_METRICS_DATA_REQUEST, | ||
FETCH_METRICS_DATA_SUCCESS, | ||
FETCH_METRICS_DATA_FAILURE, | ||
} from 'features/Students/actionTypes'; | ||
import 'features/Students/StudentsMetrics/index.scss'; | ||
|
||
const initialState = { | ||
data: [], | ||
status: RequestStatus.SUCCESS, | ||
error: null, | ||
}; | ||
|
||
const StudentsMetrics = () => { | ||
const [state, dispatch] = useReducer(reducer, initialState); | ||
|
||
const fetchMetricsData = async () => { | ||
dispatch({ type: FETCH_METRICS_DATA_REQUEST }); | ||
|
||
try { | ||
const response = camelCaseObject(await getMetricsStudents()); | ||
dispatch({ type: FETCH_METRICS_DATA_SUCCESS, payload: response }); | ||
} catch (error) { | ||
dispatch({ type: FETCH_METRICS_DATA_FAILURE, payload: error }); | ||
logError(error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchMetricsData(); | ||
}, []); | ||
|
||
return ( | ||
<div className="container-cards d-flex flex-column"> | ||
<ToggleButtonGroup type="radio" defaultValue={1} name="period"> | ||
<ToggleButton id="tbg-radio-1" value={1} variant="outline-primary"> | ||
This week | ||
</ToggleButton> | ||
<ToggleButton id="tbg-radio-2" value={2} variant="outline-primary"> | ||
Next week | ||
</ToggleButton> | ||
<ToggleButton id="tbg-radio-3" value={3} variant="outline-primary"> | ||
Next month | ||
</ToggleButton> | ||
</ToggleButtonGroup> | ||
<CardGrid | ||
columnSizes={{ | ||
xs: 12, | ||
xl: 6, | ||
}} | ||
className="w-100" | ||
> | ||
<Card className="card-pink"> | ||
<Card.Header | ||
title="New students registered" | ||
/> | ||
<Card.Section> | ||
<div className="card-number">{state.data.newStudentsRegistered}</div> | ||
</Card.Section> | ||
</Card> | ||
<Card className="card-green"> | ||
<Card.Header | ||
title="Classes scheduled" | ||
/> | ||
<Card.Section> | ||
<div className="card-number">{state.data.classesScheduled}</div> | ||
</Card.Section> | ||
</Card> | ||
</CardGrid> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StudentsMetrics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@import "assets/colors.scss"; | ||
|
||
.container-cards { | ||
border: 1px solid $gray-light; | ||
padding: 2rem; | ||
border-radius: 0.375rem; | ||
margin-bottom: 2rem; | ||
box-shadow: 0px 3px 12px 0px rgba(0, 0, 0, 0.16); | ||
|
||
.pgn__card { | ||
box-shadow: none; | ||
min-height: 160px; | ||
|
||
.pgn__card-header .pgn__card-header-content { | ||
margin-top: 1rem; | ||
} | ||
|
||
.pgn__card-header .pgn__card-header-title-md { | ||
font-size: 1rem; | ||
text-align: center; | ||
font-weight: 600; | ||
color: $black-80; | ||
} | ||
|
||
.pgn__card-section { | ||
text-align: center; | ||
} | ||
} | ||
|
||
.card-pink { | ||
background: $color-pink; | ||
} | ||
|
||
.card-green { | ||
background: $color-green; | ||
} | ||
|
||
.card-yellow { | ||
background: $color-yellow; | ||
} | ||
|
||
.card-purple { | ||
background: $color-purple; | ||
} | ||
|
||
.card-number { | ||
font-size: 44px; | ||
color: $black-80; | ||
} | ||
|
||
.btn-group-tpz { | ||
width: 45%; | ||
margin-bottom: 2rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
FETCH_METRICS_DATA_REQUEST, | ||
FETCH_METRICS_DATA_SUCCESS, | ||
FETCH_METRICS_DATA_FAILURE, | ||
} from 'features/Students/actionTypes'; | ||
import { RequestStatus } from 'features/constants'; | ||
|
||
const reducer = (state, action) => { | ||
switch (action.type) { | ||
case FETCH_METRICS_DATA_REQUEST: | ||
return { | ||
...state, | ||
status: RequestStatus.LOADING, | ||
}; | ||
case FETCH_METRICS_DATA_SUCCESS: | ||
return { | ||
...state, | ||
status: RequestStatus.SUCCESS, | ||
data: action.payload, | ||
}; | ||
case FETCH_METRICS_DATA_FAILURE: | ||
return { | ||
...state, | ||
status: RequestStatus.ERROR, | ||
error: action.payload, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters