-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fields: Fix author field view when editing
#73482
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
Conversation
66d9c51 to
ebb1659
Compare
|
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. |
| ]; | ||
|
|
||
| // Override author field with mock getElements for Storybook. | ||
| const authorFieldForStory: Field< any > = { |
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.
Not related to this PR but added a small fix for Data Forms Preview story (?path=/story/fields-base-fields--data-forms-preview&args=type:panel) where clicking to edit the author wouldn't display anything.
For that story the edited value is not reflected because AuthorView uses core-data, but that's fine for the context of storybook, since I'm not even sure we should try to mock the call. Instead I've updated an existing e2e test to cover this change.
| label: name, | ||
| } ) ); | ||
| }, | ||
| setValue: ( { value } ) => ( { author: Number( 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.
Since author value is an integer we should be a bit more defensive. The reason I added here is because when we edit through the select control, the value becomes a string. There is no problem with REST API, but I'd have to coerce the values to the same type in AuthorView when I'm comparing item.author and item._embedded.author ids.
|
Size Change: +120 B (0%) Total Size: 2.54 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in ebb1659. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19569479383
|
What?
Fixes: #73462
View of
authorfield used the data from_embedded.author. When we edit this value, the change wasn't reflected in the DataForm panel. This happened because we update theitem.authorprop and we don't handle embed data updates in core-data - I explored a bit to update core-data, but I couldn't find a good solution to work seamlessly as it would require complex handling and mapping from_embedvalues to how to fetch the entities, plus possible not needed performance overhead.So the solution here is to update
AuthorViewand check ifitem.authordiffers fromitem?._embedded?.author?.[ 0 ]?.id. This indicates when the component is used in an edit context and only then retrieves the edited user from the store. This doesn't make extra REST requests because the records are already in the store from the field's getElements function.Additionally the displayed list of items still render the saved information (from
embedded.author).Finally this PR adds a small fix for Data Forms Preview story (
?path=/story/fields-base-fields--data-forms-preview&args=type:panel) where clicking to edit theauthorwouldn't display anything. For that story the edited value is not reflected becauseAuthorViewuses core-data, but that's fine for the context of storybook, since I'm not even sure we should try to mock the call. Instead I've updated an existing e2e test to cover this change.Testing Instructions
authoris updated and in the list is displayed the saved author.