-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add enrollments page #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bra-i-am
wants to merge
9
commits into
main
Choose a base branch
from
bc/students-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
291fd3d
feat: add course details retrieval and course enrollments API
bra-i-am 83be053
feat: add CourseEnrollmentsPage and CourseEnrollmentsList components
bra-i-am 92e28c8
feat: add internationalization messages for course enrollments
bra-i-am cf54865
fix: change objectFit style from 'cover' to 'contain' in ImageWithSke…
bra-i-am 2c6fcab
refactor: fix unknown error with partial wrapping & send a falsy valu…
bra-i-am 9a68405
feat: enhance getCourses and useCatalogCourses to support courseOverv…
bra-i-am 2266ebd
refactor: update useCatalogCourses and useCourseDetails to use object…
bra-i-am 43430c7
feat: implement useCatalogCourseEnrollments hook to fetch course enro…
bra-i-am a55fe9c
feat: use useCatalogCourseEnrollments for fetching enrollment data
bra-i-am File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
| import { useParams } from 'wouter'; | ||
| import { useIntl } from '@edx/frontend-platform/i18n'; | ||
| import { usePartnerDetails } from '@src/partner/hooks'; | ||
| import HeaderDescription from '@src/app/HeaderDescription'; | ||
| import { paths } from '@src/constants'; | ||
| import { useCatalogCourses, useCourseDetails } from '@src/courses/hooks'; | ||
| import AppLayout from '../app/AppLayout'; | ||
| import CourseEnrollmentsList from './components/CourseEnrollmentsList'; | ||
| import messages from './messages'; | ||
|
|
||
| const CourseEnrollmentsPage = () => { | ||
| const intl = useIntl(); | ||
| const { partnerId, catalogId, courseId } = useParams<{ partnerId: string, catalogId: string, courseId: string }>(); | ||
|
|
||
| const { courses } = useCatalogCourses({ partnerId, catalogId, courseOverview: courseId }); | ||
|
|
||
| const courseCatalogPK = courses.find((course) => course.courseRun.id === courseId)?.id; | ||
|
|
||
| const { partnerDetails } = usePartnerDetails({ partnerId }); | ||
| const { courseDetails } = useCourseDetails({ partnerId, catalogId, courseId: courseCatalogPK }); | ||
|
|
||
| return ( | ||
| <AppLayout withBackButton backPath={paths.courses.buildPath(partnerId, catalogId)}> | ||
| {courseDetails && ( | ||
| <HeaderDescription | ||
| context={{ | ||
| title: courseDetails.courseRun.displayName, | ||
| imageUrl: partnerDetails?.logo || null, | ||
| description: courseDetails.courseRun.id, | ||
| }} | ||
| info={[ | ||
| { title: intl.formatMessage(messages.infoEnrollments), value: courseDetails.enrollments }, | ||
| { title: intl.formatMessage(messages.infoCertified), value: courseDetails.certified }, | ||
| { title: intl.formatMessage(messages.infoCompletion), value: `${courseDetails.completionRate}%` }, | ||
| ]} | ||
| /> | ||
| )} | ||
| <CourseEnrollmentsList courseCatalogPK={courseCatalogPK} /> | ||
| </AppLayout> | ||
| ); | ||
| }; | ||
|
|
||
| export default CourseEnrollmentsPage; |
This file contains hidden or 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,34 @@ | ||
| import { camelCaseObject, getConfig } from '@edx/frontend-platform'; | ||
| import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
| import { logError } from '@edx/frontend-platform/logging'; | ||
| import { Learner, PaginatedResponse } from '../app/types'; | ||
|
|
||
| export const getCourseEnrollments = async ({ | ||
| partnerId, catalogId, courseId, pageIndex, pageSize, | ||
| }:{ | ||
| partnerId: string, | ||
| catalogId: string, | ||
| courseId: number, | ||
| pageIndex?: number, | ||
| pageSize?: number, | ||
| }): Promise<PaginatedResponse<Learner>> => { | ||
| try { | ||
| const url = new URL(`${getConfig().LMS_BASE_URL}/corporate_access/api/v1/partners/${partnerId}/catalogs/${catalogId}/courses/${courseId}/enrollments/`); | ||
| if (pageIndex) { url.searchParams.append('page', String(pageIndex)); } | ||
| if (pageSize) { url.searchParams.append('page_size', String(pageSize)); } | ||
|
|
||
| const response = await getAuthenticatedHttpClient().get(url); | ||
| return camelCaseObject(response.data); | ||
| } catch (error) { | ||
| logError(error); | ||
| return { | ||
| next: null, | ||
| previous: null, | ||
| count: 0, | ||
| numPages: 0, | ||
| currentPage: 0, | ||
| start: 0, | ||
| results: [], | ||
| }; | ||
| } | ||
| }; |
This file contains hidden or 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,71 @@ | ||
| import { FC } from 'react'; | ||
| import { useParams } from 'wouter'; | ||
| import { useIntl } from '@edx/frontend-platform/i18n'; | ||
| import { | ||
| DataTable, TextFilter, | ||
| } from '@openedx/paragon'; | ||
|
|
||
| import { usePagination } from '@src/hooks'; | ||
| import TableFooter from '@src/app/TableFooter'; | ||
|
|
||
| import messages from '../messages'; | ||
| import { useCatalogCourseEnrollments } from '../hooks'; | ||
|
|
||
| const CourseEnrollmentsList: FC<{ courseCatalogPK: number | undefined }> = ({ courseCatalogPK }) => { | ||
| const intl = useIntl(); | ||
|
|
||
| const { partnerId, catalogId } = useParams(); | ||
| const { pageSize, pageIndex, onPaginationChange } = usePagination(); | ||
|
|
||
| const { | ||
| enrollments, count, pageCount, isLoading, | ||
| } = useCatalogCourseEnrollments({ | ||
| partnerId: partnerId!, catalogId: catalogId!, courseId: courseCatalogPK, pageIndex: pageIndex + 1, pageSize, | ||
| }); | ||
|
|
||
| return ( | ||
| <DataTable | ||
| isLoading={isLoading || !courseCatalogPK} | ||
| isPaginated | ||
| isFilterable | ||
| defaultColumnValues={{ Filter: TextFilter }} | ||
| fetchData={onPaginationChange} | ||
| initialState={{ | ||
| pageSize: 30, | ||
| pageIndex: 0, | ||
| }} | ||
| itemCount={count} | ||
| pageCount={pageCount} | ||
| data={enrollments} | ||
| columns={[ | ||
| { | ||
| Header: intl.formatMessage(messages.headerStudentName), | ||
| accessor: 'user.username', | ||
| }, | ||
| { | ||
| Header: intl.formatMessage(messages.headerEmail), | ||
| accessor: 'user.email', | ||
| }, | ||
| { | ||
| Header: intl.formatMessage(messages.headerCompletedAssessments), | ||
| accessor: 'completedAssessments', | ||
| }, | ||
| { | ||
| Header: intl.formatMessage(messages.headerDueAssessments), | ||
| accessor: 'pendingAssessments', | ||
| }, | ||
| { | ||
| Header: intl.formatMessage(messages.headerProgress), | ||
| accessor: 'progress', | ||
| Cell: ({ cell: { value } }) => `${value}%`, | ||
| }, | ||
| ]} | ||
| > | ||
| <DataTable.TableControlBar /> | ||
| <DataTable.Table /> | ||
| <TableFooter /> | ||
| </DataTable> | ||
| ); | ||
| }; | ||
|
|
||
| export default CourseEnrollmentsList; |
This file contains hidden or 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,24 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { getCourseEnrollments } from './api'; | ||
|
|
||
| export const useCatalogCourseEnrollments = ({ | ||
| partnerId, catalogId, pageIndex, pageSize, courseId, | ||
| } : { | ||
| partnerId: string, | ||
| catalogId: string, | ||
| pageIndex?: number, | ||
| pageSize?: number, | ||
| courseId?: number, | ||
| }) => { | ||
| const { data, isLoading } = useQuery({ | ||
| queryKey: ['courseLearners', courseId], | ||
| queryFn: () => getCourseEnrollments({ | ||
| partnerId, catalogId, courseId: courseId!, pageIndex, pageSize, | ||
| }), | ||
| enabled: !!courseId, | ||
| }); | ||
|
|
||
| return { | ||
| enrollments: data?.results || [], count: data?.count || 0, pageCount: data?.numPages, isLoading, | ||
| }; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done because there were unknown issues with accessing the paths out of the context