react-admin
react-admin copied to clipboard
Add a meta prop to react-admin reference components
Is your feature request related to a problem? Please describe. I need to pass a boolean flag to the backend when using ReferenceManyField.
Describe the solution you'd like
A meta prop that can be used to send data in the request using the optional meta parameter in the dataProvider.
i.e. <ReferenceManyField ... meta={orm: true}>
would result in a referenceMany() call with meta={orm: true}
.
Describe alternatives you've considered
As a simple workaround, I've instead done filter={'__meta__': {orm: true}}
and then popped it out of the filters in the backend. Though this is a bit of a hack and makes the code less maintainable.
Based on the documentation, it makes it sound like the recommendation is to write a custom component. For such a simple thing, this appears to require copying hundreds of lines of code out of react-admin and maintaining it, which doesn't seem like a viable solution.
Thanks for this report.
Indeed, <ReferenceManyField>
should accept queryOptions
with meta
inside.
For now, you can use the beforeGetManyReference
callback from the withLifecycleCallbacks
helper to add meta
:
const dataProvider = withLifecycleCallbacks(baseDataProvider, [
{
resource: 'comments',
beforeGetManyReference: async params => {
return { ...params, meta: { orm: true } };
},
},
]);
Feel free to open a PR if you come up with a fix of your own. 🙏 (the <ReferenceOneField>
component is a good start).
Running into this once again. While coding I intuitively add it but I seem to keep forgetting there isn't a queryOptions in ReferenceManyField... It's unfortunate that RA4 is not going to have this feature, since all PR's need to have the next branch as base. Instead I will use useGetManyReference and iterate the data.
Thanks for this report.
Indeed,
<ReferenceManyField>
should acceptqueryOptions
withmeta
inside. For now, you can use thebeforeGetManyReference
callback from thewithLifecycleCallbacks
helper to addmeta
:const dataProvider = withLifecycleCallbacks(baseDataProvider, [ { resource: 'comments', beforeGetManyReference: async params => { return { ...params, meta: { orm: true } }; }, }, ]);
Feel free to open a PR if you come up with a fix of your own. 🙏 (the
<ReferenceOneField>
component is a good start).
Hey i will like to ask if this issue is still open and if i can work on it?
#9750 is labelled as closing this issue, but seems to have been merged without it actually closing the issue...
Indeed, the #9750 adds the possibility to pass queryOptions
to the <ReferenceManyField>
component as you can see in the WithMeta
story.
Thanks for pointing this @Dreamsorcerer. So I'm closing this issue.
Thanks for your interest @AustineChi. Feel free to explore other issues. Any contribution is welcome!