Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preventing navigation while setting List filters #7416

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/ra-core/src/controller/list/useListParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useMemo, useEffect, useState, useRef } from 'react';
import { parse, stringify } from 'query-string';
import lodashDebounce from 'lodash/debounce';
import pickBy from 'lodash/pickBy';
import { useNavigate, useLocation } from 'react-router-dom';
import { useNavigate, useLocation, useMatch } from 'react-router-dom';

import { useStore } from '../../store';
import queryReducer, {
Expand Down Expand Up @@ -85,6 +85,7 @@ export const useListParams = ({
}: ListParamsOptions): [Parameters, Modifiers] => {
const location = useLocation();
const navigate = useNavigate();
const match = useMatch(`/${resource}`);
const [localParams, setLocalParams] = useState(defaultParams);
const storeKey = `${resource}.listParams`;
const [params, setParams] = useStore(storeKey, defaultParams);
Expand Down Expand Up @@ -134,8 +135,9 @@ export const useListParams = ({
setTimeout(() => {
if (disableSyncWithLocation) {
setLocalParams(tempParams.current);
} else {
} else if (!!match) {
// the useEffect above will apply the changes to the params in the store
// if the location maches the current resource
navigate(
{
search: `?${stringify({
Expand Down