-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
return ( | ||
field?.elements?.find( ( element ) => element.value === value ) | ||
?.label || getValue( { item } ) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to start adding some unit tests for this function
The fix doesn't seem to work well with |
Flaky tests detected in c82506b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10286303872
|
const label = field?.elements?.find( ( element ) => { | ||
// Intentionally using == here to allow for type coercion. | ||
// eslint-disable-next-line eqeqeq | ||
return element.value == value; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@@ -18,7 +18,7 @@ export function normalizeFields< Item >( | |||
|
|||
const getValue = | |||
field.getValue || | |||
( ( { item }: { item: ItemRecord } ) => item[ field.id ] ); | |||
( ( { item }: { item: Item } ) => item[ field.id as keyof Item ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't notice this before. I see this was addressed at #64367
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, not important right now :)
Related #55101
Follow-up to #64299 (comment)
What?
Provide a better default
render
function when the field has declaredelements
.Why?
Note how the
author
andstatus
fields are rendered in the before/after.Before:
Gravacao.do.ecra.2024-08-07.as.14.19.10.mov
After:
Gravacao.do.ecra.2024-08-07.as.16.31.45.mov
Testing Instructions
npm install && npm run storybook:dev
and verifyauthor
andstatus
are properly rendered.