-
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
Patterns: Don't override the rootClientID in create menu - only set if undefined #52713
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,16 @@ export default function ReusableBlockConvertButton( { | |
const canConvert = useSelect( | ||
( select ) => { | ||
const { canUser } = select( coreStore ); | ||
const { getBlocksByClientId, canInsertBlockType } = | ||
select( blockEditorStore ); | ||
const { | ||
getBlocksByClientId, | ||
canInsertBlockType, | ||
getBlockRootClientId, | ||
} = select( blockEditorStore ); | ||
|
||
const rootId = | ||
rootClientId || clientIds.length > 0 | ||
? getBlockRootClientId( clientIds[ 0 ] ) | ||
: undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong, no? It will call const rootId = rootClientId || ( clientIds.length > 0 ? getBlockRootClientId( clientIds[ 0 ] ) : undefined ); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦 should have stuck with the nested ternary I first had, it was easier to grok 😄 It works as expected when properly bracketed and have updated, but I wonder if something like the following is clearer for our future selves and not much more verbose 🤔 : let rootId;
if ( rootClientId ) {
rootId = rootClientId;
} else if ( clientIds.length > 0 ) {
rootId = getBlockRootClientId( clientIds[ 0 ] );
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Up to you 😀 |
||
|
||
const blocks = getBlocksByClientId( clientIds ) ?? []; | ||
|
||
|
@@ -70,7 +78,7 @@ export default function ReusableBlockConvertButton( { | |
// Hide when this is already a reusable block. | ||
! isReusable && | ||
// Hide when reusable blocks are disabled. | ||
canInsertBlockType( 'core/block', rootClientId ) && | ||
canInsertBlockType( 'core/block', rootId ) && | ||
blocks.every( | ||
( block ) => | ||
// Guard against the case where a regular block has *just* been converted. | ||
|
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 pass
[]
as thedeps
foruseSelect
here. Annoyingly it doesn't default to[]
.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, fixed, we should have a lint rule for that.