Skip to content

Commit

Permalink
fix(Tables): Reset page number on filter (#477)
Browse files Browse the repository at this point in the history
On affected clusters and clusters list tables, if you change per page or reset/apply filters, you will stay on the same page. Pages should be reset to 1 if you change the per page count or apply or remove a filter. This PR fixes those issues.

Co-authored-by: Michael Johnson <micjohns@newbeginnings.usersys.redhat.com>
  • Loading branch information
johnsonm325 and Michael Johnson authored Nov 29, 2022
1 parent aaad106 commit 7315589
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ describe('non-empty successful affected clusters table', () => {
cy.get(TOOLBAR).find('button').contains('Reset filters').click();
cy.get(TOOLBAR).find(CHIP_GROUP).should('not.exist');
checkPaginationSelected(0);
checkCurrentPage(2);
checkCurrentPage(1);
cy.get('th[data-label="Name"]')
.should('have.attr', 'aria-sort')
.and('contain', 'ascending');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const AffectedClustersTable = ({ query, rule, afterDisableFn }) => {

const onSetPerPage = (_e, perPage) => {
setRowsFiltered(false);
updateFilters({ ...filters, limit: perPage });
updateFilters({ ...filters, limit: perPage, offset: 0 });
};

// constructs array of rows (from the initial data) checking currently applied filters
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ClustersListTable/ClustersListTable.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ describe('clusters list table', () => {
cy.get(TOOLBAR).find('button').contains('Reset filters').click();
cy.get(CHIP_GROUP).should('have.length', 1);
checkPaginationSelected(0);
checkCurrentPage(2);
checkCurrentPage(1);
cy.get('th[data-label="Name"]')
.should('have.attr', 'aria-sort')
.and('contain', 'ascending');
Expand Down
3 changes: 2 additions & 1 deletion src/Components/ClustersListTable/ClustersListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ const ClustersListTable = ({
label: intl.formatMessage(messages.name).toLowerCase(),
filterValues: {
key: 'text-filter',
onChange: (_event, value) => updateFilters({ ...filters, text: value }),
onChange: (_event, value) =>
updateFilters({ ...filters, offset: 0, text: value }),
value: filters.text,
placeholder: intl.formatMessage(messages.filterByName),
},
Expand Down
3 changes: 1 addition & 2 deletions src/Services/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ const filtersInitialState = {
};

export const resetFilters = (filters, initialState, updateFilters) => {
const { limit, offset, sortIndex, sortDirection } = filters;
const { limit, sortIndex, sortDirection } = filters;
updateFilters({
...initialState,
...(limit !== undefined && { limit }),
...(limit !== undefined && { offset }),
sortIndex,
sortDirection,
});
Expand Down

0 comments on commit 7315589

Please sign in to comment.