-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Image Block: Conditionally Render Block Control Based on Component Presence #62132
Image Block: Conditionally Render Block Control Based on Component Presence #62132
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. |
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.
Hi @amitraj2203! Thanks for the contribution, it fixes the issue perfectly fine!
Could we group the various conditionals together like:
const showUrlInput =
isSingleSelected &&
! isEditingImage &&
! lockHrefControls &&
! lockUrlControls;
const showCoverControls = isSingleSelected && canInsertCover;
const showBlockControls =
showUrlInput || allowCrop || showCoverControls;
and then use them to conditionally render the ImageURLInputUI
and ToolbarButton
.
This way, there's only one place to add additional conditions in the future so less risk that someone forgets to update both places
lightboxEnabled={ lightboxChecked } | ||
onSetLightbox={ onSetLightbox } | ||
resetLightbox={ resetLightbox } | ||
{ shouldRenderOtherControls && ( |
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.
A better name might be showBlockControls
because they belong to the block
group. The other
group is below in the component tree.
Also, for consistency, we use show
instead of render
verb in variable names here to indicate that something is being shown (rendered).
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.
Hi @michalczaplinski, Thank you for reviewing the PR. I have made the changes as per your suggestions and will keep this approach in mind for future work.
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.
Great work! 👍 Thanks for the quick response.
…esence (WordPress#62132) * Refactor image block control rendering logic for clarity. * Refactor conditional rendering logic for block controls. Co-authored-by: amitraj2203 <amitraj2203@git.wordpress.org> Co-authored-by: michalczaplinski <czapla@git.wordpress.org> Co-authored-by: annezazu <annezazu@git.wordpress.org>
…esence (WordPress#62132) * Refactor image block control rendering logic for clarity. * Refactor conditional rendering logic for block controls. Co-authored-by: amitraj2203 <amitraj2203@git.wordpress.org> Co-authored-by: michalczaplinski <czapla@git.wordpress.org> Co-authored-by: annezazu <annezazu@git.wordpress.org>
What?
Fixes: #62040
Why?
There is a redundant separator in the block toolbar of Image block after setting an override in a synced pattern with an Image block.
How?
Conditionally render the block control based on the presence of internal components.
Testing Instructions
Screenshots or screencast