From 1a6e23d16f0d9ca294e8c47e1a887965b40e5635 Mon Sep 17 00:00:00 2001 From: Matheus Wichman Date: Sun, 27 Oct 2019 18:56:03 -0300 Subject: [PATCH] Prevent calling an outdated updateSort --- cypress/integration/list.js | 15 +++++++++++++++ packages/ra-core/src/controller/useListParams.ts | 2 +- .../src/list/DatagridHeaderCell.js | 4 +--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cypress/integration/list.js b/cypress/integration/list.js index f93685889f1..8f648a27076 100644 --- a/cypress/integration/list.js +++ b/cypress/integration/list.js @@ -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' + ); + }); }); }); diff --git a/packages/ra-core/src/controller/useListParams.ts b/packages/ra-core/src/controller/useListParams.ts index a20e6981c36..d05f3cd78e9 100644 --- a/packages/ra-core/src/controller/useListParams.ts +++ b/packages/ra-core/src/controller/useListParams.ts @@ -141,7 +141,7 @@ const useListParams = ({ const changeParams = useCallback(action => { const newQuery = getQuery({ - location: window.location, + location, params, filterDefaultValues, sort, diff --git a/packages/ra-ui-materialui/src/list/DatagridHeaderCell.js b/packages/ra-ui-materialui/src/list/DatagridHeaderCell.js index fb6f7342f6d..343687100af 100644 --- a/packages/ra-ui-materialui/src/list/DatagridHeaderCell.js +++ b/packages/ra-ui-materialui/src/list/DatagridHeaderCell.js @@ -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);