-
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
Refactor the BlockToolbar compoonent to avoid getSelectedBlock #11843
Conversation
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 did a set of smoke tests and things looked good. The changes also seem logical 👍
There is only one small change that I think we should do before the merge.
*/ | ||
export function isBlockValid( state, clientId ) { | ||
const block = state.editor.present.blocks.byClientId[ clientId ]; | ||
return block && block.isValid; |
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.
If the block is undefined we will return undefined instead of a boolean. I think we should do !! ( block && block.isValid )
or !! block && block.isValid
if we are totally sure isValid is always defined to a boolean.
d264c4e
to
aa48d43
Compare
@@ -398,6 +398,19 @@ the client ID. | |||
|
|||
Block name. | |||
|
|||
### isBlockValid |
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 some discussion at #10891 (comment) concerning the naming with regards to placement of adjectives. I think it's particularly relevant here only because we already have precedent with blocks, and with block validation specification, i.e. wp.blocks.isValidBlockContent
.
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.
On second thought, there seems to be subtle distinction between what's being validated, where the language here might be more appropriate for a known identity, vs. in the block API case of considering some transient inputs.
¯\_(ツ)_/¯
Extracted from #11811
I'm using
getSelectedBlockClientId
and a newisBlockValid
selector to avoid the less performantgetSelectedBlock
selector in the BlockToolbar.