-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrate deprecated Table to DataTable for CompletedLearnersTable
- Loading branch information
1 parent
152488a
commit c3d5a5b
Showing
15 changed files
with
782 additions
and
256 deletions.
There are no files selected for viewing
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,64 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { DataTable } from '@openedx/paragon'; | ||
import { useGenericTableData } from './data/hooks'; | ||
import EnterpriseDataApiService from '../../data/services/EnterpriseDataApiService'; | ||
import EmailCell from './EmailCell'; | ||
|
||
const CompletedLearnersTable = (enterpriseId) => { | ||
const intl = useIntl(); | ||
const { | ||
isLoading, | ||
tableData, | ||
fetchTableData, | ||
} = useGenericTableData( | ||
enterpriseId, | ||
'completed-learners', | ||
EnterpriseDataApiService.fetchCompletedLearners, | ||
useMemo(() => ({ | ||
userEmail: { key: 'user_email' }, | ||
completedCourses: { key: 'completed_courses' }, | ||
}), []), | ||
); | ||
|
||
return ( | ||
<DataTable | ||
isSortable | ||
manualSortBy | ||
isPaginated | ||
manualPagination | ||
isLoading={isLoading} | ||
columns={[ | ||
{ | ||
Header: intl.formatMessage({ | ||
id: 'admin.portal.lpr.completed.learners.table.user_email.column.heading', | ||
defaultMessage: 'Email', | ||
description: 'Column heading for the user email column in the completed learners table', | ||
}), | ||
accessor: 'userEmail', | ||
Cell: EmailCell, | ||
}, | ||
{ | ||
Header: intl.formatMessage({ | ||
id: 'admin.portal.lpr.completed.learners.table.completed_courses.column.heading', | ||
defaultMessage: 'Total Course Completed Count', | ||
description: 'Column heading for the completed courses column in the completed learners table', | ||
}), | ||
accessor: 'completedCourses', | ||
}, | ||
]} | ||
initialState={{ | ||
pageIndex: 20, | ||
pageSize: 0, | ||
sortBy: [{ id: 'completedCourses', desc: true }], | ||
selectedRowsOrdered: [], | ||
}} | ||
fetchData={fetchTableData} | ||
data={tableData.results} | ||
itemCount={tableData.itemCount} | ||
pageCount={tableData.pageCount} | ||
/> | ||
); | ||
}; | ||
|
||
export default CompletedLearnersTable; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const EmailCell = ({ row }) => ( | ||
<span data-hj-suppress>{row.original.userEmail}</span> | ||
); | ||
|
||
EmailCell.propTypes = { | ||
row: PropTypes.shape({ | ||
original: PropTypes.shape({ | ||
userEmail: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default EmailCell; |
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,42 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import EmailCell from './EmailCell'; | ||
|
||
describe('Email Component', () => { | ||
it('should display the user email and suppress highlighting', () => { | ||
const mockRow = { | ||
original: { | ||
userEmail: '[email protected]', | ||
}, | ||
}; | ||
|
||
render( | ||
<EmailCell row={mockRow} />, | ||
); | ||
|
||
// Assert that the email is rendered correctly | ||
const emailElement = screen.getByText('[email protected]'); | ||
expect(emailElement).toBeInTheDocument(); | ||
|
||
// Assert that data-hj-suppress is present to suppress highlighting | ||
expect(emailElement).toHaveAttribute('data-hj-suppress'); | ||
}); | ||
|
||
it('should throw a prop-type warning if the email is not provided', () => { | ||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
const invalidRow = { | ||
original: {}, | ||
}; | ||
|
||
// Render with invalid props | ||
render(<EmailCell row={invalidRow} />); | ||
|
||
// Assert that a prop-types error has been logged | ||
expect(consoleSpy).toHaveBeenCalled(); | ||
|
||
// Clean up the spy | ||
consoleSpy.mockRestore(); | ||
}); | ||
}); |
Oops, something went wrong.