-
Notifications
You must be signed in to change notification settings - Fork 33
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 99a7b8a
Showing
12 changed files
with
485 additions
and
156 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 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 Email from './Email'; | ||
|
||
const CompletedLearnersTable = (enterpriseId) => { | ||
const intl = useIntl(); | ||
const { | ||
isLoading, | ||
tableData, | ||
fetchTableData, | ||
} = useGenericTableData( | ||
enterpriseId, | ||
'completed-learners', | ||
EnterpriseDataApiService.fetchCompletedLearners, | ||
{ | ||
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: Email, | ||
}, | ||
{ | ||
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 Email = ({ row }) => ( | ||
<span data-hj-suppress>{row.original.userEmail}</span> | ||
); | ||
|
||
Email.propTypes = { | ||
row: PropTypes.shape({ | ||
original: PropTypes.shape({ | ||
userEmail: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default Email; |
236 changes: 236 additions & 0 deletions
236
src/components/Admin/__snapshots__/CompletedLearnersTable.test.jsx.snap
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,236 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CompletedLearnersTable renders empty state correctly 1`] = ` | ||
<div | ||
className="pgn__data-table-layout-wrapper" | ||
> | ||
<div | ||
className="pgn__data-table-layout-main" | ||
> | ||
<div | ||
className="pgn__data-table-wrapper" | ||
> | ||
<div | ||
className="pgn__data-table-status-bar" | ||
data-testid="table-control-bar" | ||
> | ||
<div | ||
className="pgn__data-table-status" | ||
> | ||
<div | ||
className="pgn__data-table-status-left" | ||
/> | ||
<div | ||
className="pgn__data-table-actions-right" | ||
> | ||
<div | ||
className="pgn__data-table-toggle" | ||
/> | ||
<div /> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
className="pgn__data-table-container" | ||
data-testid="data-table-container" | ||
> | ||
<table | ||
className="pgn__data-table is-striped" | ||
role="table" | ||
> | ||
<thead> | ||
<tr | ||
role="row" | ||
> | ||
<th | ||
colSpan={1} | ||
onClick={[Function]} | ||
role="columnheader" | ||
style={ | ||
{ | ||
"cursor": "pointer", | ||
} | ||
} | ||
title="Toggle SortBy" | ||
> | ||
<span | ||
className="d-flex align-items-center" | ||
> | ||
<span> | ||
</span> | ||
<span | ||
className="pgn__icon" | ||
data-testid="arrow-drop-up-down" | ||
style={ | ||
{ | ||
"opacity": 0.5, | ||
} | ||
} | ||
> | ||
<svg | ||
aria-hidden={true} | ||
fill="none" | ||
focusable={false} | ||
height={24} | ||
role="img" | ||
viewBox="0 0 24 24" | ||
width={24} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="m7 10 5-5 5 5H7ZM7 14l5 5 5-5H7Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
</th> | ||
<th | ||
colSpan={1} | ||
onClick={[Function]} | ||
role="columnheader" | ||
style={ | ||
{ | ||
"cursor": "pointer", | ||
} | ||
} | ||
title="Toggle SortBy" | ||
> | ||
<span | ||
className="d-flex align-items-center" | ||
> | ||
<span> | ||
Total Course Completed Count | ||
</span> | ||
<span | ||
className="pgn__icon" | ||
data-testid="arrow-drop-down" | ||
> | ||
<svg | ||
aria-hidden={true} | ||
fill="none" | ||
focusable={false} | ||
height={24} | ||
role="img" | ||
viewBox="0 0 24 24" | ||
width={24} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="m7 10 5 5 5-5H7Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody | ||
role="rowgroup" | ||
/> | ||
</table> | ||
</div> | ||
<div | ||
className="pgn__data-table-empty" | ||
> | ||
No results found | ||
</div> | ||
<div | ||
className="pgn__data-table-footer" | ||
data-testid="table-footer" | ||
> | ||
<nav | ||
aria-label="table pagination" | ||
className="pagination-minimal" | ||
> | ||
<div | ||
aria-atomic={true} | ||
aria-live="polite" | ||
aria-relevant="text" | ||
className="sr-only" | ||
> | ||
Page 21, Current Page, of -1 | ||
</div> | ||
<ul | ||
className="pagination" | ||
> | ||
<li | ||
className="page-item" | ||
> | ||
<button | ||
aria-label="Previous, Page 20" | ||
className="btn-icon btn-icon-primary btn-icon-md previous page-link" | ||
disabled={false} | ||
onClick={[Function]} | ||
type="button" | ||
> | ||
<span | ||
className="btn-icon__icon-container" | ||
> | ||
<span | ||
className="pgn__icon btn-icon__icon" | ||
> | ||
<svg | ||
aria-hidden={true} | ||
fill="none" | ||
focusable={false} | ||
height={24} | ||
role="img" | ||
viewBox="0 0 24 24" | ||
width={24} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M17.51 3.87 15.73 2.1 5.84 12l9.9 9.9 1.77-1.77L9.38 12l8.13-8.13Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
</button> | ||
</li> | ||
<li | ||
className="page-item disabled" | ||
> | ||
<button | ||
aria-label="Next, Page 22" | ||
className="btn-icon btn-icon-primary btn-icon-md next page-link" | ||
disabled={true} | ||
onClick={[Function]} | ||
tabIndex="-1" | ||
type="button" | ||
> | ||
<span | ||
className="btn-icon__icon-container" | ||
> | ||
<span | ||
className="pgn__icon btn-icon__icon" | ||
> | ||
<svg | ||
aria-hidden={true} | ||
fill="none" | ||
focusable={false} | ||
height={24} | ||
role="img" | ||
viewBox="0 0 24 24" | ||
width={24} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="m6.49 20.13 1.77 1.77 9.9-9.9-9.9-9.9-1.77 1.77L14.62 12l-8.13 8.13Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
</button> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.