react-admin

Is it possible to reference another field than the id field in messages and titles?


I would like the titles of the screens, as well as the delete confirmation messages, to use a different field to identify the record to the user than the id, since the id format is not very human friendly.

I know how to customise the text of the messages and titles. However, I have no idea how to access other fields than the id param when constructing the text message.

Is this possible, or do I need to anonymise the messages to not include a reference to the actual record?

This is an illustration of the delete message, where I'd like something nicer for the user, like eg. the e-mail of the employee to delete, instead of the random string that is the id value.


Solution

  • In the page headers you can use any field from the record: https://marmelab.com/react-admin/Show.html#page-title

    const PostTitle = ({ record }) => {
        return <span>Post {record ? `"${record.title}"` : ''}</span>;
    };
    
    export const PostShow = (props) => (
        <Show title={<PostTitle />} {...props}>
            ...
        </Show>
    );
    

    In the deletion confirmation dialog, now it is impossible to change the id field to another, in my opinion this possibility is only in development: https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.js