Skip to content

Commit

Permalink
refactor: sort enterprise enrollments ordering by default on last_act…
Browse files Browse the repository at this point in the history
…ivity_date
  • Loading branch information
zamanafzal committed Jul 13, 2023
1 parent 8b6d1c8 commit b26c27b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/EnrollmentsTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const EnrollmentsTable = () => {
fetchMethod={EnterpriseDataApiService.fetchCourseEnrollments}
columns={enrollmentTableColumns}
formatData={formatEnrollmentData}
defaultSortIndex={8}
defaultSortType='desc'
tableSortable
/>
);
Expand Down
10 changes: 8 additions & 2 deletions src/components/TableComponent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class TableComponent extends React.Component {
id,
loading,
enterpriseId,
defaultSortIndex,
defaultSortType,
} = this.props;

const sortByColumn = (column, direction) => {
Expand All @@ -76,8 +78,8 @@ class TableComponent extends React.Component {
let sortColumn;

if (tableSortable) {
sortDirection = ordering && ordering.indexOf('-') !== -1 ? 'desc' : 'asc';
sortColumn = (ordering && ordering.replace('-', '')) || columnConfig[0].key;
sortDirection = defaultSortType || (ordering && ordering.indexOf('-') !== -1 ? 'desc' : 'asc');
sortColumn = (ordering && ordering.replace('-', '')) || columnConfig[defaultSortIndex].key;
}

return (
Expand Down Expand Up @@ -169,6 +171,8 @@ TableComponent.propTypes = {
columns: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
formatData: PropTypes.func.isRequired,
tableSortable: PropTypes.bool,
defaultSortIndex: PropTypes.number,
defaultSortType: PropTypes.string,

// Props expected from TableContainer / redux store
enterpriseId: PropTypes.string.isRequired,
Expand All @@ -188,6 +192,8 @@ TableComponent.propTypes = {

TableComponent.defaultProps = {
className: null,
defaultSortIndex: 0,
defaultSortType: undefined,
tableSortable: false,
data: undefined,
ordering: undefined,
Expand Down

0 comments on commit b26c27b

Please sign in to comment.