Skip to content

Commit

Permalink
Buttons Block: Show inserter if button have variations (#53498) (#53783)
Browse files Browse the repository at this point in the history
* Buttons Block: Show inserter if button have variations (#53498)

* Combine `useSelect` variations with the existing one

* Add comment about the custom check for the `directInsert` option value that should be handled in the `Inserter`
  • Loading branch information
petitphp authored Sep 11, 2023
1 parent 0246dab commit ef5bd83
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -42,17 +43,26 @@ function ButtonsEdit( { attributes, className } ) {
'has-custom-font-size': fontSize || style?.typography?.fontSize,
} ),
} );
const preferredStyle = useSelect( ( select ) => {
const { preferredStyle, hasButtonVariations } = useSelect( ( select ) => {
const preferredStyleVariations =
select( blockEditorStore ).getSettings()
.__experimentalPreferredStyleVariations;
return preferredStyleVariations?.value?.[ buttonBlockName ];
const buttonVariations = select( blocksStore ).getBlockVariations(
buttonBlockName,
'inserter'
);
return {
preferredStyle:
preferredStyleVariations?.value?.[ buttonBlockName ],
hasButtonVariations: buttonVariations.length > 0,
};
}, [] );

const innerBlocksProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
defaultBlock: DEFAULT_BLOCK,
directInsert: true,
// This check should be handled by the `Inserter` internally to be consistent across all blocks that use it.
directInsert: ! hasButtonVariations,
template: [
[
buttonBlockName,
Expand Down

1 comment on commit ef5bd83

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in ef5bd83.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6150648336
📝 Reported issues:

Please sign in to comment.