-
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
Fix showing double icons for connected blocks in pattern editor #62317
Changes from 3 commits
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _n, sprintf } from '@wordpress/i18n'; | ||
import { __, _n, sprintf, _x } from '@wordpress/i18n'; | ||
import { | ||
DropdownMenu, | ||
ToolbarButton, | ||
ToolbarGroup, | ||
ToolbarItem, | ||
__experimentalText as Text, | ||
MenuGroup, | ||
} from '@wordpress/components'; | ||
import { | ||
switchToBlockType, | ||
|
@@ -33,6 +35,7 @@ function BlockSwitcherDropdownMenuContents( { | |
clientIds, | ||
hasBlockStyles, | ||
canRemove, | ||
isUsingBindings, | ||
} ) { | ||
const { replaceBlocks, multiSelect, updateBlockAttributes } = | ||
useDispatch( blockEditorStore ); | ||
|
@@ -118,6 +121,17 @@ function BlockSwitcherDropdownMenuContents( { | |
</p> | ||
); | ||
} | ||
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. I'm wondering if we could get If we do this, I believe we could avoid passing Additionally, I think we wouldn't need I am not 100% sure if it makes sense, but maybe it is worth taking a look. 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. I believe so, yes! However I don't think it makes much difference. Currently we still need 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. I wasn't thinking about performance but about readability, but I don't have a strong opinion, so whatever you decide it's okay for me 🙂 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. I think it reads okay for me, but I'm obviously biased 😅. Happy to do some further improvements if we find something confusing later! 🙇 |
||
|
||
const connectedBlockDescription = isSingleBlock | ||
? _x( | ||
'This block is connected.', | ||
'block toolbar button label and description' | ||
) | ||
: _x( | ||
'These blocks are connected.', | ||
'block toolbar button label and description' | ||
); | ||
|
||
return ( | ||
<div className="block-editor-block-switcher__container"> | ||
{ hasPatternTransformation && ( | ||
|
@@ -156,11 +170,18 @@ function BlockSwitcherDropdownMenuContents( { | |
onSwitch={ onClose } | ||
/> | ||
) } | ||
{ isUsingBindings && ( | ||
<MenuGroup> | ||
<Text className="block-editor-block-switcher__binding-indicator"> | ||
{ connectedBlockDescription } | ||
</Text> | ||
</MenuGroup> | ||
) } | ||
</div> | ||
); | ||
} | ||
|
||
export const BlockSwitcher = ( { clientIds, disabled } ) => { | ||
export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { | ||
const { | ||
canRemove, | ||
hasBlockStyles, | ||
|
@@ -303,6 +324,7 @@ export const BlockSwitcher = ( { clientIds, disabled } ) => { | |
clientIds={ clientIds } | ||
hasBlockStyles={ hasBlockStyles } | ||
canRemove={ canRemove } | ||
isUsingBindings={ isUsingBindings } | ||
/> | ||
) } | ||
</DropdownMenu> | ||
|
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 I am not mistaken, this component becomes specific to pattern overrides because it is only used when adding a pattern in a post, right? Maybe we can rename it and slightly change the implementation to reflect 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.
On second thought, I don't think this even belongs in the
block-editor
package 😅. I'd imagine it'll be a bigger refactor if we figure out a way to move it to thepatterns
package though. I'd prefer to do it in a follow-up PR if necessary. WDYT?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.
Moving it to the
patterns
package seems logical to me 🙂 And I guess it is okay to do it in a follow-up PR. Should we create an issue or something to ensure it is not lost?Maybe it is still worth changing the component name to clarify it is related to patterns and not block bindings until that PR is done?
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.
Done in 72d0a8e! I renamed some stuff, so could appreciate a final review to ensure I didn't break anything 😆.