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

ReferenceInput label uses the wrong resource for translation message #7646

Closed
atcg01 opened this issue May 5, 2022 · 10 comments · Fixed by #7710
Closed

ReferenceInput label uses the wrong resource for translation message #7646

atcg01 opened this issue May 5, 2022 · 10 comments · Fixed by #7710
Assignees
Labels

Comments

@atcg01
Copy link

atcg01 commented May 5, 2022

ReferenceInput in react-admin@4.02 traduct field in the same way of react-admin@3.19

When editing a resource posts with the following field
<ReferenceInput source="idUser" reference="users"><AutoComplete /></ReferenceInput>
The ReferenceInput label will be traduct with the key resources.users.fields.idUser in react-admin@4, while react-admin@3.19 use resources.posts.fields.idUser

The ReferenceField use resources.posts.fields.idUser in react-admin@3.19 and react-admin@4.02

@djhi
Copy link
Collaborator

djhi commented May 5, 2022

Please follow the issue template

@atcg01
Copy link
Author

atcg01 commented May 5, 2022

What you were expecting:
ReferenceInput in react-admin@4.02 traduct field label in the same way of react-admin@3.19

What happened instead:
ReferenceInput use resources.{resource in reference prop}.fields.field_name instead of resources.{current edited resource}.fields.field_name

Steps to reproduce:
When editing a resource posts with the following field
<ReferenceInput source="idUser" reference="**users**"><AutoComplete /></ReferenceInput>
The ReferenceInput label will be traduct with the key resources.users.fields.idUser in react-admin@4.02, while react-admin@3.19 use resources.posts.fields.idUser

Other information:
The ReferenceField use resources.posts.fields.idUser in react-admin@3.19 and react-admin@4.02

Environment

  • React-admin version: 4.02
  • React version: 17.0.2
  • Browser: Chrome

@atcg01 atcg01 changed the title ReferenceInput label traduction in react-admin@4.0 ReferenceInput label traduction in react-admin@4.02 May 5, 2022
@fzaninotto
Copy link
Member

Reproduced, thanks!

@fzaninotto
Copy link
Member

The problem is that, since we removed prop injection, the child of ReferenceInput has no way to access the original resource... That's a tough one.

One solution would be to augment the ChoicesContext to store the original resource, but it's a bit hacky... The other solution would be to create a new context. But why would children of ReferenceInput read that context? Not a good one either.

@fzaninotto fzaninotto changed the title ReferenceInput label traduction in react-admin@4.02 ReferenceInput label uses the wrong resource for translation message May 5, 2022
@fzaninotto
Copy link
Member

I may have a good solution. The idea is to invert the control of FieldTitle. Instead of pushing props to it, let it pull data from a context...

So SimpleForm, ArrayInput, ReferenceInput, and many other components, should create a <FieldTitlePrefixContext>. They have the means to build a value for it.

Individual inputs would just pass the props they receive to FieldTitle: label, and source. <FieldTitle> would use the FieldTitlePrefixContext value to prefix the source it receives in case it has no label.

This is a pretty large change, but I think it's the right way - it's, in fact, the continuation of what we've done in the 3.0 -> 4.0 migration.

And it's backwards compatible.

@fzaninotto
Copy link
Member

After thinking a bit about it, the previous version didn't make sense. It generated translation messages like resources.users.fields.idUser, which doesn't exist, as users doesn't have an idUser field (but an id field).

@atcg01
Copy link
Author

atcg01 commented May 18, 2022

The key use for translation is not resources.users.fields.idUser but resources.posts.fields.idUser in 3.19

@fzaninotto
Copy link
Member

right, I mixed it up, sorry.

@atcg01
Copy link
Author

atcg01 commented May 18, 2022

no it generate resources.posts.fields.idUser for posts resource with foreign key idUser reference key id in user resource.
Now it generate resources.users.fields.idUser that not make sense

@fzaninotto
Copy link
Member

Fixed by #7110

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

Successfully merging a pull request may close this issue.

3 participants