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

Introduce ReferenceFieldBase #9698

Merged
merged 12 commits into from
Apr 8, 2024
Merged

Introduce ReferenceFieldBase #9698

merged 12 commits into from
Apr 8, 2024

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Mar 4, 2024

Problem

While working on the alternative UI libraries demos, we had to re-implement all the reference fields and inputs logic.

Solution

Add core headless versions for these components
This PR introduces only the ReferenceFieldBase.

Tasks

  • Implementation
  • Tests

Comment on lines 72 to 77
return id == null ? (
emptyText ? (
<Typography component="span" variant="body2">
{emptyText && translate(emptyText, { _: emptyText })}
</Typography>
) : null
Copy link
Member

Choose a reason for hiding this comment

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

it seems to me that this case is no longer handled

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Storybook disagrees with you. Having no id will disable the query in useReferenceFieldController so no referenceRecord will be available at L146 in this file thus showing the empty message

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was an error in the useReferenceFieldController though. Both the tests and the storybook show that all empty cases are handled

Copy link
Member

Choose a reason for hiding this comment

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

Except in the previous code, the empty text was displayed in a Typography. That's no longer the case.

options: UseReferenceFieldControllerOptions<ReferenceRecordType>
): UseReferenceFieldControllerResult<ReferenceRecordType> => {
const { source, link = 'edit', reference, queryOptions } = options;
const record = useRecordContext<RecordType>(options);
Copy link
Member

Choose a reason for hiding this comment

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

throw if reference is empty

@fzaninotto fzaninotto merged commit 44fd60a into next Apr 8, 2024
12 checks passed
@fzaninotto fzaninotto deleted the reference-field-base branch April 8, 2024 07:59
@fzaninotto fzaninotto added this to the 5.0.0 milestone Apr 8, 2024
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.

3 participants