Skip to content

Commit

Permalink
Merge pull request #3887 from m4theushw/fix-sorting-with-filters
Browse files Browse the repository at this point in the history
[RFR] Prevent calling an outdated updateSort
  • Loading branch information
fzaninotto authored Oct 28, 2019
2 parents e9b1943 + 1a6e23d commit 0630de5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
15 changes: 15 additions & 0 deletions cypress/integration/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,20 @@ describe('List Page', () => {
)
).should('exist');
});

it('should keep filters when sorting a column', () => {
ListPagePosts.setFilterValue('q', 'quis culpa impedit');
cy.get(ListPagePosts.elements.recordRows).should(el =>
expect(el).to.have.length(1)
);

ListPagePosts.toggleColumnSort('title');
ListPagePosts.waitUntilDataLoaded();

cy.get(ListPagePosts.elements.filter('q')).should(
'have.value',
'quis culpa impedit'
);
});
});
});
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useListParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const useListParams = ({

const changeParams = useCallback(action => {
const newQuery = getQuery({
location: window.location,
location,
params,
filterDefaultValues,
sort,
Expand Down
4 changes: 1 addition & 3 deletions packages/ra-ui-materialui/src/list/DatagridHeaderCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ DatagridHeaderCell.propTypes = {

export default shouldUpdate(
(props, nextProps) =>
props.isSorting !== nextProps.isSorting ||
(nextProps.isSorting &&
props.currentSort.order !== nextProps.currentSort.order) ||
props.updateSort !== nextProps.updateSort ||
(nextProps.isSorting && props.sortable !== nextProps.sortable)
)(DatagridHeaderCell);

0 comments on commit 0630de5

Please sign in to comment.