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

Allow disabling store persistence of the list parameters #9019

Merged
merged 3 commits into from
Jun 16, 2023

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Jun 16, 2023

Problem

For one-off lists (e.g. in dashboards), <ListBase> does the fetching and puts the data in a <ListContext>, so it’s fine.

But as it uses the store by default, a list for a given resource will be affected by the actions of the user in other lists of the same resource.

It’s possible to specify a different storeKey to avoid that, but it’s silly to have to define a store key when what I want is to disable the use of the store altogether.

It’s also possible to use disableSyncWithLocation, but the name of that prop isn’t clearly related to the store.

Solution

Allow to set storeKey to false to disable the store altogether

@@ -88,15 +88,23 @@ export const useListParams = ({
const location = useLocation();
const navigate = useNavigate();
const [localParams, setLocalParams] = useState(defaultParams);
const [params, setParams] = useStore(storeKey, defaultParams);
const [params, setParams] = useStore(
storeKey || `${resource}.listParams`,
Copy link
Member

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?

Copy link
Collaborator Author

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

@@ -111,7 +119,10 @@ export const useListParams = ({
() =>
getQuery({
queryFromLocation,
params: disableSyncWithLocation ? localParams : params,
params:
disableSyncWithLocation || disableSyncWithStore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you must also dd the check for disableSyncWithStore in changeParams L146, and anywhere else the setParams may be called.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changeParams does not call setParams

@fzaninotto fzaninotto merged commit fdfc40d into next Jun 16, 2023
@fzaninotto fzaninotto deleted the list-no-store branch June 16, 2023 12:43
@fzaninotto fzaninotto added this to the 4.12.0 milestone Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants