-
-
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
[RFR] Add option to make ReferenceInput choices lazy #6013
Conversation
61adb7f
to
9464d9c
Compare
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.
Nice! This will be a welcome addition.
You need to add unit tests and documentation to have this PR ready to merge.
} = useGetList(reference, pagination, sort, filterValues); | ||
} = useGetList(reference, pagination, sort, filterValues, { | ||
action: 'CUSTOM_QUERY', | ||
enabled: isEnabled && isEnabled(filterValues), |
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.
This won't work when isEnabled isn't set
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.
I actually relied on the enabled
option default value being true
. However, I can make it true
explicitly if you think this is clearer.
OK, happy that you like it. I'll add the tests and docs then. What do you think about my comments regarding |
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.
Nice! Feel free to do the same for ReferencearrayInput, too.
Edit: I've a working solution, I'll push it later today 🙂 |
I just pushed the support for the One small thing that I find misleading is that the Do you think this is something that should be taken care of or is fine like this? |
70dd18e
to
4703540
Compare
@fzaninotto do you think this PR is ready to be merged or is it still missing something? |
Why is this being closed? |
This PR was automatically closed by GitHub, I'm reopening it. Sorry for the noise. |
I think this PR was closed again by Github. I believe it is still valid. |
You're right, I'm reopening it. |
It's a great feature. Any idea in which release this PR is getting merged and will be available? |
Thanks for merging this PR! 🎉 |
Thanks! |
This is actually implementing a similar feature than the one requested in #5898 but for
<ReferenceInput
.Why
The goal is to be able to control when the
useGetList
isenabled
to avoid over-fetching the choices. In our application, we have a user autocomplete component and, as we have hundred of thousands of possible choices, we only want to start showing/fetching the choices if the user inputs at least 2 characters.Solution
This PR introduces an
isEnabled
option that is an optional function we use to set theenabled
option of theuseGetList()
. This function is passed thefilterValues
array.Example of usage:
Alternatives
Today, in order to work-around this, we pass a permanent filter
filter={{ is_autocomplete: true }}
that we use on our backend api to return early to avoid hitting the DB. However, we are still making calls for nothing.I also looked to add a similar prop for the
ReferenceArrayInput
but, as it's usinguseGetMatching
, it's a bit more complex.If you think this option makes sense, I'd be happy to dig more to also add support for it for the
ReferenceArrayInput
.