-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 default Record representation #8011
Conversation
Co-authored-by: Antoine Fricker <102964006+septentrion-730n@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so good! 💪
@@ -47,12 +47,12 @@ const frenchMessages: TranslationMessages = { | |||
page: { | |||
create: 'Créer %{name}', | |||
dashboard: 'Tableau de bord', | |||
edit: '%{name} #%{id}', | |||
edit: '%{name} %{recordRepresentation}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change for all translation packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not. Existing translations will still work as before. We still pass the id
, the recordRepresentation
is passed in addition to other message args. The new translation takes advantage of it.
@@ -123,10 +115,11 @@ ReferenceInput.defaultProps = { | |||
page: 1, | |||
perPage: 25, | |||
sort: { field: 'id', order: 'DESC' }, | |||
children: <AutocompleteInput />, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't a good opportunity to avoid defaultProps
? We could initialize those defaults when destructuring the props
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice to have
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
This is great! Thank you! |
@djhi @fzaninotto So if we want to validate the AutocompleteInput to be required can we do this? <ReferenceInput source="territoryId" reference="territories" validate={[required()]} /> instead of <ReferenceInput source="territoryId" reference="territories">
<AutocompleteInput validate={[required()]}/>
</ReferenceInput> Is there anything wrong with passing the props (label, validate, etc) down from ReferenceInput to AutocompleteInput? That would REALLY cut the code down! |
@davidhenley currently you can't. I was about to answer that having the So yeah, actually, it's defendable, and does not look too complicated to do imho. |
Personally, I never know if I have to pass the But:
I'm not sure we can draw systematically pass props down. I'll need to play with a Storybook that does all possibilities to understand the best decision to make. |
Problem
React-admin forces developers to define a child
<Field>
for<ReferenceField>
to represent the related record. This is cumbersome.Solution
Add the ability to define a
recordRepresentation
at the<Resource>
level, and let<ReferenceField>
. Use that knowledge to render without a child.<Resource>
andResourceDefinitionContext
to carry therecordRepresentation
useGetRecordRepresentation
hookrecordRepresentation
in<ReferenceField>
and let it work without childrenrecordRepresentation
in<ReferenceOneField>
and let it work without childrenrecordRepresentation
in<Edit>
and<Show>
page titlesrecordRepresentation
in<SelectInput>
and let it work withoutoptionText
when used in<ReferenceInput>
recordRepresentation
in<AutocompleteInput>
and let it work withoutoptionText
when used in<ReferenceInput>
recordRepresentation
in<ReferenceInput>
and let it work without children<ListGuesser>
,<EditGuesser>
and<ShowGuesser>
to output child-less References<SelectInput>
,<AutocompleteInput>
, and<ReferenceInput>
docs in the process)Closes #4899