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

Allow to customize default display field per resource (use name instead of id) #4899

Closed
olivierdalang opened this issue Jun 5, 2020 · 4 comments
Assignees

Comments

@olivierdalang
Copy link

Is your feature request related to a problem? Please describe.

By default, react-admin uses the id field to represent a row (for example as the first column in the list view, as the displayed attribute in ReferenceFields, in the navbar of the edit view, etc.).

This behavior range from not very helpful when using integers pks (Client #3 => doesn't give much info) to not usable when using uuids (Client #00c8b66f-4f01-4db7-b0c6-ad588c7842ba => destroys the layout and looks like a bug).

Describe the solution you'd like

I'd love to be able to specify the field to be used to represent the row like this :

<Resource name="clients" display="fullname" list={ListGuesser} (...) />

(alternative naming ideas instead of display : repr, mainAttribute, titleAttribute, ...)

Describe alternatives you've considered

Not using Guessers, and creating title componenents for all my resources. This works well, but is verbose, and you loose a bit the out-of-the-box-awesomeness of react-admin.

Additional context

Thanks for react-admin, it's really awesome :-)

@fzaninotto
Copy link
Member

Hi, and thank for your input.

So you're using guessers, and you want the ability to customize them. This is not what guessers were designed for. Guessers are here to bootstrap your code. If the default output of a guesser doesn't suit you, you should copy the code written by the guesser in the console, and use it to replace the guesser component by a custom component that you can customize.

So we won't implement what you're asking, sorry.

@olivierdalang
Copy link
Author

Fair enough about the Guessers !

But having a default text representation for resources still makes sense outside of Guessers (I'm used to this from the Django framework). It would allow to reduce boiler plate code in a lot of places. It's also more DRY as the day you want to change from name to full_name. A few examples :

ReferenceField before

<ReferenceField label="User" source="user_id" reference="users">
    <TextField source="name" />
</ReferenceField>

ReferenceField after

<ReferenceField label="User" source="user_id" reference="users" />

Edit Before

const UserTitle = ({ record }) => (
   <>User {record.name}</>
);
export const UserEdit = props => (
  <Edit title={<UserTitle/>} {...props}>
      <SimpleForm>
          <TextInput source="name" />
      </SimpleForm>
  </Edit>
);

Edit After

export const UserEdit = props => (
  <Edit {...props}>
      <SimpleForm>
          <TextInput source="name" />
      </SimpleForm>
  </Edit>
);

@fzaninotto
Copy link
Member

True, this is convenient. Let's make it an enhancement request.

@fzaninotto
Copy link
Member

Fixed by #8011

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

No branches or pull requests

2 participants