diff --git a/cypress/integration/auth.js b/cypress/integration/auth.js index 8a5454808cb..94c4fbfad53 100644 --- a/cypress/integration/auth.js +++ b/cypress/integration/auth.js @@ -30,4 +30,21 @@ describe('Authentication', () => { ListPage.navigate(); cy.url().then(url => expect(url).to.contain('/#/posts')); }); + + it('should redirect to initial url keeping query string', () => { + let urlBeforeLogout; + + ListPage.navigate(); + ListPage.addCommentableFilter(); + cy.url().then(url => { + urlBeforeLogout = url; + }); + ListPage.setAsNonLogged(); + cy.reload(); + LoginPage.login('login', 'password'); + cy.url().then(urlAfterLogin => { + expect(urlAfterLogin).to.contain(urlBeforeLogout); + }); + ListPage.commentableFilter().should('exist'); + }); }); diff --git a/cypress/support/ListPage.js b/cypress/support/ListPage.js index 01b14cf7eb9..70cd3bc19eb 100644 --- a/cypress/support/ListPage.js +++ b/cypress/support/ListPage.js @@ -4,6 +4,7 @@ export default url => ({ appLoader: '.app-loader', displayedRecords: '.displayed-records', filter: name => `.filter-field[data-source='${name}'] input`, + filterButton: name => `.filter-field[data-source='${name}']`, filterMenuItems: `.new-filter-item`, menuItems: `[role=menuitem]`, filterMenuItem: source => `.new-filter-item[data-key="${source}"]`, @@ -63,6 +64,15 @@ export default url => ({ return cy.get(this.elements.pageNumber(n)).click({ force: true }); }, + addCommentableFilter() { + this.openFilters(); + cy.get(this.elements.filterMenuItem('commentable')).click(); + }, + + commentableFilter() { + return cy.get(this.elements.filterButton('commentable')); + }, + setFilterValue(name, value, clearPreviousValue = true) { cy.get(this.elements.filter(name)); if (clearPreviousValue) { @@ -88,6 +98,12 @@ export default url => ({ cy.get(this.elements.logout).click(); }, + setAsNonLogged() { + cy.window().then(win => { + win.localStorage.setItem('not_authenticated', true); + }); + }, + toggleSelectAll() { cy.get(this.elements.selectAll).click(); }, diff --git a/packages/ra-core/src/auth/Authenticated.spec.tsx b/packages/ra-core/src/auth/Authenticated.spec.tsx index 12b4126777f..8e135089ad3 100644 --- a/packages/ra-core/src/auth/Authenticated.spec.tsx +++ b/packages/ra-core/src/auth/Authenticated.spec.tsx @@ -58,7 +58,10 @@ describe('', () => { type: 'RA/CLEAR_STATE', }); expect(history.location.pathname).toEqual('/login'); - expect(history.location.state).toEqual({ nextPathname: '/' }); + expect(history.location.state).toEqual({ + nextPathname: '/', + nextSearch: '', + }); }); }); }); diff --git a/packages/ra-core/src/auth/useAuthenticated.spec.tsx b/packages/ra-core/src/auth/useAuthenticated.spec.tsx index c31f5fc5d06..ab5e70393e0 100644 --- a/packages/ra-core/src/auth/useAuthenticated.spec.tsx +++ b/packages/ra-core/src/auth/useAuthenticated.spec.tsx @@ -100,7 +100,10 @@ describe('useAuthenticated', () => { type: 'RA/CLEAR_STATE', }); expect(history.location.pathname).toEqual('/login'); - expect(history.location.state).toEqual({ nextPathname: '/' }); + expect(history.location.state).toEqual({ + nextPathname: '/', + nextSearch: '', + }); }); }); }); diff --git a/packages/ra-core/src/auth/useLogin.ts b/packages/ra-core/src/auth/useLogin.ts index 3015879b0a5..8d5c120eaed 100644 --- a/packages/ra-core/src/auth/useLogin.ts +++ b/packages/ra-core/src/auth/useLogin.ts @@ -35,6 +35,7 @@ const useLogin = (): Login => { const history = useHistory(); const dispatch = useDispatch(); const nextPathName = locationState && locationState.nextPathname; + const nextSearch = locationState && locationState.nextSearch; const login = useCallback( (params: any = {}, pathName) => @@ -42,11 +43,12 @@ const useLogin = (): Login => { dispatch(resetNotification()); const redirectUrl = pathName ? pathName - : nextPathName || defaultAuthParams.afterLoginUrl; + : nextPathName + nextSearch || + defaultAuthParams.afterLoginUrl; history.push(redirectUrl); return ret; }), - [authProvider, history, nextPathName, dispatch] + [authProvider, history, nextPathName, nextSearch, dispatch] ); const loginWithoutProvider = useCallback( diff --git a/packages/ra-core/src/auth/useLogout.ts b/packages/ra-core/src/auth/useLogout.ts index 2f9854b7313..8185871354c 100644 --- a/packages/ra-core/src/auth/useLogout.ts +++ b/packages/ra-core/src/auth/useLogout.ts @@ -69,6 +69,7 @@ const useLogout = (): Logout => { ) { newLocation.state = { nextPathname: history.location.pathname, + nextSearch: history.location.search, }; } if (redirectToParts[1]) { diff --git a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx index c51e1e4abcb..a3f109b0f4f 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx @@ -206,7 +206,8 @@ const AutocompleteArrayInput = (props: AutocompleteArrayInputProps) => { }); // eslint-disable-next-line - const debouncedSetFilter = useCallback(debounce(setFilter || DefaultSetFilter, debounceDelay), + const debouncedSetFilter = useCallback( + debounce(setFilter || DefaultSetFilter, debounceDelay), [setFilter, debounceDelay] );