-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Editor: Refactor Post Author component #33695
Conversation
return { | ||
hasAssignAuthorAction: get( | ||
post, | ||
[ '_links', 'wp:action-assign-author' ], | ||
false | ||
), | ||
postType: select( editorStore ).getCurrentPostType(), |
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 weren't using this prop in PostAuthorCheck.
Size Change: +691 B (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
// Initializes the post author properly | ||
// Also ensures external changes are reflected. | ||
useEffect( () => { | ||
if ( postAuthor ) { | ||
setFieldValue( postAuthor.name ); | ||
} | ||
}, [ postAuthor ] ); | ||
|
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.
I couldn't track down why this effect was added precisely, but I don't think it's needed anymore.
It also initializes an unnecessary search query on the mount.
@@ -0,0 +1,6 @@ | |||
export const AUTHORS_QUERY = { | |||
who: 'authors', | |||
per_page: 50, |
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.
I changed the "per_page" argument from 100 to 50. However, I don't think this number makes a big difference when used with ComboboxControl.
It just needs to be higher than 25 and reasonable :)
Happy to revert it if needed.
@@ -46,7 +50,7 @@ function PostAuthorCombobox() { | |||
const fetchedAuthors = ( authors ?? [] ).map( ( author ) => { | |||
return { | |||
value: author.id, | |||
label: author.name, | |||
label: decodeEntities( author.name ), |
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.
Added missing entity decoding. We were already doing this for select control.
@youknowriad, this isn't necessarily related to this PR, but I'm just curious. Is it okay to perform gutenberg/packages/editor/src/components/post-author/select.js Lines 23 to 26 in c6ba02b
|
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.
@Mamaduka mapping/filtering inside useSelect/withSelect should definitely be avoided as it will trigger too much rerendering. Favor useMemo
outside the useSelect
for these situations.
Awesome work on this PR btw
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.
LGTM 👍
Thanks for the review, @youknowriad. |
Description
Refactors Editor's post author component to use
getUser
andgetUsers
selectors.The component previously was using temporary
getAuthors
and__unstableGetAuthor
to display author selection for non-admin users. Temp selectors are no longer required as now we can specify context when requesting data records.We can now deprecated/remove those temporary selectors.
Query Improvements
id, name
). The change reduces transferred data size by roughly 50%.How has this been tested?
Test creating/editing post.
Test with non-admin users. Again, the results should be the same.
Helpful WP CLI Commands
Generate 15 editors:
wp user generate --role=editor --count=15
Generate 50 editors:
wp user generate --role=editor --count=50
Cleanup:
wp user delete $(wp user list --role=editor --field=ID)
Screenshots
Types of changes
Refactoring
Checklist:
*.native.js
files for terms that need renaming or removal).