-
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
Switch back to getAuthors #26554
Switch back to getAuthors #26554
Conversation
const users = yield apiFetch( { | ||
path: `/wp/v2/users?who=authors&include=${ id }`, | ||
} ); | ||
yield receiveUserQuery( 'author', users ); |
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.
should the first argument here be "authors" to match the same entity as "getAuthors"?
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.
Maybe? I think that results in the fetched author overwriting the authors? I can test.
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.
Tested changing this and confirmed using the same key results in the query interfering with the getAuthors
query, causing errors or unexpected results as the results from the two queries overwrite each other.
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.
Mmm, so if I'm reading this right getAuthor(1)
and getAuthor(2)
are using the same query key which means if I trigger both concurrently, they'll mess with each other's result.
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.
@youknowriad - Oh, good point. I didn't think about concurrent requests. Should we build a dynamic key here that includes the requested id? Do we have an existing component that uses this approach/a helper to create the query key?
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.
Yes, I did add dynamic query keys for both getAuthor and getAuthors, I think it will solve both issues so I reverted the change you did with useMemo
const author = getUser( getEditedPostAttribute( 'author' ) ); | ||
const author = | ||
postAuthor || | ||
__unstableGetAuthor( getEditedPostAttribute( 'author' ) )[ 0 ]; |
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.
Actually, why do we need [ 0 ]
here. getAuthor only returns one author right?
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.
Yes, but it is returned as an array with a single element. I can change this so __unstableGetAuthor
returns a single element which makes more sense based on the naming, does that sound good?
Seems like there's some valid test failures. |
I'll take a look. |
05d2a9d
to
6c832c9
Compare
@youknowriad One issue was the selector was showing even when the site only had one author. I had removed the check for To alleviate this I added |
packages/core-data/src/selectors.js
Outdated
*/ | ||
export function __unstableGetAuthor( state ) { | ||
const authors = getUserQueryResults( state, 'author' ); | ||
return authors ? authors[ 0 ] : []; |
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.
It should probably return null
if the author was not found.
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.
Good point, will change.
I think that's the issue, both selectors use different queries, so they shouldn't share the same "query key". |
Right - that is why I changed the single author query key to 'author' vs 'authors' |
This is looking good for me, but it could use some testing @adamsilverstein |
Hi, I tested this out (last commit - f507edb ) on a test site [wordpress 5.5.3] with no other plugins installed except this one and the select author dropdown does not appear, even as an admin user. I created another user with the 'editor' role just to be sure that the author drop down didn't display if there was only one registered user and still had the same result. |
Tested this branch on top of WP 5.6-beta4 and can confirm the post author dropdown isn't showing for either editor or admin users. The |
Yep, i just realized I forgot to fix the query key in the selector.😅 |
Thanks for the additional fix; with that last commit, I now confirm that the postauthor component now displays as intended and is keyboard accessible as well. |
@youknowriad - Great! Works well in my testing. |
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.
👍 Looks good!
Co-authored-by: Riad Benguella <benguella@gmail.com>
* Provide a minimum of code wrapping for the code block. (#26623) * Block Support: Fix font size style when applying block support (#26762) * Fix Separator editor styles (#27071) * Fix the Post author selector for contributors (#26554) Co-authored-by: Riad Benguella <benguella@gmail.com> * Align single half width column to left (#27142) * remove the auto margin for individual column blocks * update margin values for blocks in blocks to zero insted of auto * Add backward compatibility support for lightBlockWrapper in getSaveElement (#27189) * Code block: paste plain text (#27236) * paste plain text option * Add e2e test * Fix crash when null date passed to TimePicker (#27316) * Fix crash when null date passed. * Update test * Fix GH actions "cancel" step (#27025) * use new syntax for setting env var * Update package-lock * Update package-lock again * Remove the button only option from the UI until it can be wired up to something that works in the front end. (#27379) * Fix combobox csuggestion list closure when clicking scrollbar (#27367) Co-authored-by: Joen A <1204802+jasmussen@users.noreply.github.com> Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com> Co-authored-by: Adam Silverstein <adamsilverstein@earthboundhosting.com> Co-authored-by: Riad Benguella <benguella@gmail.com> Co-authored-by: andrei draganescu <me@andreidraganescu.info> Co-authored-by: Daniel Richards <daniel.richards@automattic.com> Co-authored-by: Ella van Durpe <wp@iseulde.com> Co-authored-by: Noah Allen <noahtallen@gmail.com> Co-authored-by: Andy Peatling <apeatling@users.noreply.github.com>
Description
Fixes #26476
How has this been tested?
Screenshots
Types of changes
Checklist: