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

Add a meta prop to react-admin reference components #9669

Open
Dreamsorcerer opened this issue Feb 15, 2024 · 2 comments · May be fixed by #9679
Open

Add a meta prop to react-admin reference components #9669

Dreamsorcerer opened this issue Feb 15, 2024 · 2 comments · May be fixed by #9679

Comments

@Dreamsorcerer
Copy link
Contributor

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.

@adguernier
Copy link
Contributor

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

@christiaanwesterbeek
Copy link
Contributor

Running into this one 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants