react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Redundant call to items in SelectArrayInput

Open horaklukas opened this issue 1 year ago • 6 comments

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 🤷‍♂️

horaklukas avatar Aug 12 '22 12:08 horaklukas

Thanks for submitting your idea. We are listening to any feedback about it and would gladly welcome a pull request! 😅

antoinefricker avatar Aug 16 '22 09:08 antoinefricker

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. 🙂

horaklukas avatar Aug 16 '22 10:08 horaklukas

I had a question around here, when will you know you have to suspend with "suspendGetManyFetch"?

lukascivil avatar Aug 16 '22 13:08 lukascivil

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..

horaklukas avatar Aug 16 '22 14:08 horaklukas

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.

lukascivil avatar Aug 16 '22 19:08 lukascivil

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?

horaklukas avatar Aug 20 '22 09:08 horaklukas