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

DataForm: provide a better default for render when field has elements #64338

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/dataviews/src/normalize-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ export function normalizeFields< Item >(

const renderFromElements = ( { item }: { item: Item } ) => {
const value = getValue( { item } );
return (
field?.elements?.find( ( element ) => element.value === value )
?.label || getValue( { item } )
);
const label = field?.elements?.find( ( element ) => {
// Intentionally using == here to allow for type coercion.
// eslint-disable-next-line eqeqeq
return element.value == value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the issue in the field though. If the field is "string" its values should be string both in getValue and elements for me. and same for integer no?

Copy link
Member Author

Choose a reason for hiding this comment

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

#64391 may be a better approach.

} )?.label;

return label || value;
};

const render =
Expand Down
Loading