react-admin
react-admin copied to clipboard
Redundant call to items in SelectArrayInput
Is your feature request related to a problem? Please describe.
When I have basic usage of SelectArrayInput
with ReferenceArrayInput
and I know referenced data items will be always less than page size because they're static, I would like to avoid Get many call to selected items inside useReferenceArrayInputController
as it doesn't make sense to fetch the data again, I have all data I need and I (as a developer) assure that.
<ReferenceArrayInput source="allowedRegions" reference="region">
<SelectArrayInput placeholder="Choose" />
</ReferenceArrayInput>
my point is that there is no filter
query parameter for these simple static (enum like) endpoints at our API.
Describe the solution you'd like
Allow manual suspend of request to getMany items in useReferenceArrayInputController
something like
<ReferenceArrayInput source="allowedRegions" reference="region" suspendGetManyFetch>
<SelectArrayInput placeholder="Choose" />
</ReferenceArrayInput>
Describe alternatives you've considered Don't have an idea how to solve this better 🤷♂️
Thanks for submitting your idea. We are listening to any feedback about it and would gladly welcome a pull request! 😅
Np, I can make the PR, I've submitted it just for that, to listen your feedback. If you think it's a good idea, the attribute name isn't against any of RA conventions, etc. 🙂
I had a question around here, when will you know you have to suspend with "suspendGetManyFetch"?
I meant it to be a static property, not changing over time. Once you know your api returns less than 10 items all the time, as the result is static list, you can use it and don't worry about missing data. As I said, it would delegate responsibility to the developer..
I understand but what if there is nothing in cache yet? ,..., if it is something in line with "preferCache" or "forceFetch={false}", that if there is no cache it makes the call, but if there is it never calls. This same idea could be taken to other Reference components as well, in my case I have several apis with static values.
The property you suggest seems reasonable, but I don't have such deep knowledge of internals. Is the data cache shared between getList
and getMany
calls? So that if there are already two items in data cache returned by getList
[
{ id: 1, name: 'Greece'},
{ id: 2, name: 'Croatia'}
]
then call to getMany(2)
will return the item from the cache?