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

Support <ReferenceOneField emptyContent> #10450

Open
wants to merge 8 commits into
base: next
Choose a base branch
from

Conversation

erwanMarmelab
Copy link
Contributor

@erwanMarmelab erwanMarmelab commented Jan 16, 2025

Closes #10185

Problem

We cannot pass a ReactNode to ReferenceOneField when we don't have any record, we can only pass text.

Solution

Support ReactElement in <ReferenceOneField emptyText>

How To Test

https://react-admin-storybook-gzj7x0njd-marmelab.vercel.app/?path=/story/ra-ui-materialui-fields-referenceonefield--empty-text

Additional Checks

  • The PR targets master for a bugfix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

@erwanMarmelab erwanMarmelab added the RFR Ready For Review label Jan 16, 2025
});

export const EmptyText = () => (
<AdminContext dataProvider={dataProvider} i18nProvider={i18nProvider}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you wrap this story inside a TestMemoryRouter?

Comment on lines 69 to 77
const renderEmptyItemOption = useCallback(() => {
return typeof emptyText === 'string' ? (
<Typography component="span" variant="body2">
{emptyText && translate(emptyText, { _: emptyText })}
</Typography>
) : emptyText ? (
emptyText
) : null;
}, [emptyText, translate]);
Copy link
Collaborator

@djhi djhi Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need all this. Just add the useCallback function content directly where you currently call it

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

Successfully merging this pull request may close these issues.

2 participants