-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Replace 'Remove from Reusable blocks' with 'Manage Reusable blocks'. #27026
Replace 'Remove from Reusable blocks' with 'Manage Reusable blocks'. #27026
Conversation
@@ -35,6 +35,7 @@ | |||
"@wordpress/i18n": "file:../i18n", | |||
"@wordpress/icons": "file:../icons", | |||
"@wordpress/notices": "file:../notices", | |||
"@wordpress/url": "^2.19.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.
This dependency should be declared as a file link the same as the other @wordpress/
dependencies above.
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.
Thanks so much for working on this @wallstead, the code looks really solid for your first contribution. I left a few comments, but nothing too complex.
( select ) => { | ||
const { getBlock } = select( 'core/block-editor' ); | ||
const { canUser } = select( 'core' ); | ||
const blockObj = getBlock( clientId ); |
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.
Would be great to avoid an abbreviation here (the coding standards says to use full names where possible - https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/#naming-conventions).
I think I'd go with naming this reusableBlock
and change the later variable to reusableBlockPost
(if it's needed).
const reusableBlock = | ||
blockObj && isReusableBlock( blockObj ) | ||
? select( 'core' ).getEntityRecord( | ||
'postType', | ||
'wp_block', | ||
blockObj.attributes.ref | ||
) | ||
: null; |
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.
When I tested, blockObj.attributes.ref
and reusableBlock.id
were the same value, so just wondering if this call to getEntityRecord
is needed? Is this to check that a post actually exists for the editor that's about to be loaded?
Worth noting that while the reusable block is saving I believe it has a temporary id (mentioned here - #19115), so we might want to check for that.
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. I don't think getEntityRecord
is needed here. It was a remnant from the ReusableBlockDeleteButton
component, but I don't think it is relevant for the user experience in this case. I removed it in my most recent commit.
As for the temporary id, I cannot replicate the ref attribute being anything other than a number id. I looked for documentation on this for a while but came up empty-handed.
<BlockSettingsMenuControls> | ||
<MenuItem | ||
onClick={ () => { | ||
window.location = addQueryArgs( 'edit.php', { |
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 think this menu item should ideally render as a link (an <a>
element instead of a <button>
).
MenuItem
can take the same props as Button
, so it should be possible to pass the value to the href
prop:
https://github.com/WordPress/gutenberg/blob/master/packages/components/src/button/index.js#L23
I do wonder if it should open in a new tab 🤔
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.
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.
This is looking good! Thanks for making those few extra changes.
The only remaining thing I noticed is that the capitalization isn't consistent with the 'Manage all reusable blocks' option in the editor menu. Then I looked closer, and lots of strings seem inconsistent, so I made an issue (#27085).
I think 'Manage all reusable blocks' is the incorrect label here, so lets leave it as is.
If you can resolve the merge conflict I'd be happy to merge. Congrats on your first contribution!
* Removed ReusableBlockDeleteButton component and added ReusableBlocksManageButton in its place. * On click, ReusableBlocksManageButton sends the user to the reusable blocks management screen. * Added '@wordpress/url' dependency to the package. This is used to build the url for the reusable blocks management screen. Fixes WordPress#12791.
* Use file link for new @wordpress/url dependency. * Rename abbreviated blockObj variable to reusableBlock to follow coding standards. * Simplified logic to check if the 'Manage Reusable blocks' menu item should be visible. * Use MenuItem's href prop to create an a tag instead of relying on onClick on a button. Fixes WordPress#27026.
e20c3e6
to
ef3def1
Compare
@talldan I fixed the merge conflict and updated the package-lock to fix a failing check. Also, I saw a left-over e2e test for the "Remove from Reusable blocks" button we are replacing. I removed that unused test to fix another failing check. Hopefully, that's okay. |
Nice work! Would be great to add an e2e test for the new 'Manage reusable blocks' option if you feel like taking a crack at it 😄 |
Congratulations on your first merged pull request, @wallstead! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
Description
Fixes #12791.
How has this been tested?
npm test
.Screenshots
Types of changes
Replaces the 'Remove from Reusable blocks' button in block settings menu with a 'Manage Reusable blocks' button that takes the user to the reusable blocks management screen.
Checklist: