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

Post Author - don't show 0 in inspector controls #51345

Conversation

mcliwanow
Copy link
Contributor

What?

This is a small fix addressing "0" displayed when user has no rights for fetching post authors.

Fixes: #51342

Why?

Even though 0 is a falsy value and it seems fine for using when rendering components conditionally, React will render it as 0 (when value is false, React renders nothing).

How?

When user has no access to authors, authors array was empty and when used as authorOptions.length, React would render "0". Changing it to a boolean condition ensures that nothing is rendered instead.

Another approach could be using a ternary operator and returning null if the condition is falsy.

Testing Instructions

  1. As an admin user, create a new page with any content
  2. Log in as an Editor
  3. Edit page added in step 1
  4. Add Post Author block
  5. Ensure that "0" doesn't show in Inspector controls in the "Settings" section. Just above "show avatar".

Screenshots or screencast

Before:

Screenshot 2023-06-08 at 16 23 13

After:

Screenshot 2023-06-08 at 16 40 15

When user has no access to authors, authors array was empty and when used as `authorOptions.length`, React would render "0". Changing it to a boolean condition ensures that nothing is rendered instead.
@mcliwanow mcliwanow requested a review from ajitbohra as a code owner June 8, 2023 14:10
@skorasaurus skorasaurus added the [Block] Post Author Affects the Post Author Block label Jun 8, 2023
@t-hamano t-hamano added the Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code label Jun 9, 2023
@t-hamano t-hamano self-requested a review June 10, 2023 02:20
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Nice catch, @mcliwanow! I followed the Test Instructions and confirmed that the problem has been resolved.

Thank you 👍

@t-hamano t-hamano merged commit d921d2a into WordPress:trunk Jun 10, 2023
@github-actions github-actions bot added this to the Gutenberg 16.1 milestone Jun 10, 2023
sethrubenstein pushed a commit to pewresearch/gutenberg that referenced this pull request Jul 13, 2023
When user has no access to authors, authors array was empty and when used as `authorOptions.length`, React would render "0". Changing it to a boolean condition ensures that nothing is rendered instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Author Affects the Post Author Block Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post Author block displays "0" in the inspector controls
3 participants