-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Allow disabling store persistence of the list parameters #9019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,15 +88,25 @@ export const useListParams = ({ | |
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const [localParams, setLocalParams] = useState(defaultParams); | ||
const [params, setParams] = useStore(storeKey, defaultParams); | ||
// As we can't conditionally call a hook, if the storeKey is false, | ||
// we'll ignore the params variable later on and won't call setParams either. | ||
const [params, setParams] = useStore( | ||
storeKey || `${resource}.listParams`, | ||
defaultParams | ||
); | ||
const tempParams = useRef<ListParams>(); | ||
const isMounted = useIsMounted(); | ||
const disableSyncWithStore = storeKey === false; | ||
|
||
const requestSignature = [ | ||
location.search, | ||
resource, | ||
storeKey, | ||
JSON.stringify(disableSyncWithLocation ? localParams : params), | ||
JSON.stringify( | ||
disableSyncWithLocation || disableSyncWithStore | ||
? localParams | ||
: params | ||
), | ||
JSON.stringify(filterDefaultValues), | ||
JSON.stringify(sort), | ||
perPage, | ||
|
@@ -111,7 +121,10 @@ export const useListParams = ({ | |
() => | ||
getQuery({ | ||
queryFromLocation, | ||
params: disableSyncWithLocation ? localParams : params, | ||
params: | ||
disableSyncWithLocation || disableSyncWithStore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you must also dd the check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
? localParams | ||
: params, | ||
filterDefaultValues, | ||
sort, | ||
perPage, | ||
|
@@ -124,7 +137,10 @@ export const useListParams = ({ | |
// store as well so that we don't lose them after a redirection back | ||
// to the list | ||
useEffect(() => { | ||
if (Object.keys(queryFromLocation).length > 0) { | ||
if ( | ||
Object.keys(queryFromLocation).length > 0 && | ||
!disableSyncWithStore | ||
) { | ||
setParams(query); | ||
} | ||
}, [location.search]); // eslint-disable-line | ||
|
@@ -377,7 +393,7 @@ export interface ListParamsOptions { | |
perPage?: number; | ||
resource: string; | ||
sort?: SortPayload; | ||
storeKey?: string; | ||
storeKey?: string | false; | ||
} | ||
|
||
interface Parameters extends ListParams { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
storeKey
is false, this will still use the store. Can you add a comment to explain what's the rationale?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't disable a hook, so although we still read the store, its values are not used later in the code