Fix: Exclude Mini Cart and other blocks inside the Mini Cart Contents block (https://github.com/woocommerce/woocommerce-blocks/pull/5616)
This commit is contained in:
parent
9934533375
commit
6f4c00a2fd
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { getBlockTypes } from '@wordpress/blocks';
|
||||
|
||||
const EXCLUDED_BLOCKS: readonly string[] = [
|
||||
'woocommerce/mini-cart',
|
||||
'woocommerce/checkout',
|
||||
'woocommerce/cart',
|
||||
'woocommerce/single-product',
|
||||
'woocommerce/cart-totals-block',
|
||||
'woocommerce/checkout-fields-block',
|
||||
'core/post-template',
|
||||
'core/comment-template',
|
||||
'core/query-pagination',
|
||||
'core/comments-query-loop',
|
||||
'core/post-comments-form',
|
||||
'core/post-comments-link',
|
||||
'core/post-comments-count',
|
||||
'core/comments-pagination',
|
||||
'core/post-navigation-link',
|
||||
];
|
||||
|
||||
export const getMiniCartAllowedBlocks = (): string[] =>
|
||||
getBlockTypes()
|
||||
.filter( ( block ) => {
|
||||
if ( EXCLUDED_BLOCKS.includes( block.name ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclude child blocks of EXCLUDED_BLOCKS.
|
||||
if (
|
||||
block.parent &&
|
||||
block.parent.filter( ( value ) =>
|
||||
EXCLUDED_BLOCKS.includes( value )
|
||||
).length > 0
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} )
|
||||
.map( ( { name } ) => name );
|
|
@ -3,48 +3,15 @@
|
|||
*/
|
||||
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
|
||||
import { useEditorContext } from '@woocommerce/base-context';
|
||||
import { getBlockTypes } from '@wordpress/blocks';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
const EXCLUDED_BLOCKS: readonly string[] = [
|
||||
'woocommerce/mini-cart',
|
||||
'woocommerce/single-product',
|
||||
'core/post-template',
|
||||
'core/comment-template',
|
||||
'core/query-pagination',
|
||||
'core/comments-query-loop',
|
||||
'core/post-comments-form',
|
||||
'core/post-comments-link',
|
||||
'core/post-comments-count',
|
||||
'core/comments-pagination',
|
||||
'core/post-navigation-link',
|
||||
];
|
||||
import { getMiniCartAllowedBlocks } from '../allowed-blocks';
|
||||
|
||||
export const Edit = (): JSX.Element => {
|
||||
const blockProps = useBlockProps();
|
||||
const { currentView } = useEditorContext();
|
||||
const allowedBlocks = getBlockTypes()
|
||||
.filter( ( block ) => {
|
||||
if ( EXCLUDED_BLOCKS.includes( block.name ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclude child blocks of EXCLUDED_BLOCKS.
|
||||
if (
|
||||
block.parent &&
|
||||
block.parent.filter( ( value ) =>
|
||||
EXCLUDED_BLOCKS.includes( value )
|
||||
).length > 0
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} )
|
||||
.map( ( { name } ) => name );
|
||||
|
||||
return (
|
||||
<div
|
||||
|
@ -54,7 +21,7 @@ export const Edit = (): JSX.Element => {
|
|||
}
|
||||
>
|
||||
<InnerBlocks
|
||||
allowedBlocks={ allowedBlocks }
|
||||
allowedBlocks={ getMiniCartAllowedBlocks() }
|
||||
renderAppender={ InnerBlocks.ButtonBlockAppender }
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -14,7 +14,7 @@ import { useForcedLayout, getAllowedBlocks } from '../../../shared';
|
|||
|
||||
export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {
|
||||
const blockProps = useBlockProps();
|
||||
const allowedBlocks = getAllowedBlocks( innerBlockAreas.EMPTY_MINI_CART );
|
||||
const allowedBlocks = getAllowedBlocks( innerBlockAreas.FILLED_MINI_CART );
|
||||
const { currentView } = useEditorContext();
|
||||
|
||||
const defaultTemplate = ( [
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { TemplateArray } from '@wordpress/blocks';
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { getMiniCartAllowedBlocks } from '../allowed-blocks';
|
||||
|
||||
export const Edit = (): JSX.Element => {
|
||||
const blockProps = useBlockProps();
|
||||
|
@ -21,6 +22,7 @@ export const Edit = (): JSX.Element => {
|
|||
template={ defaultTemplate }
|
||||
renderAppender={ InnerBlocks.ButtonBlockAppender }
|
||||
templateLock={ false }
|
||||
allowedBlocks={ getMiniCartAllowedBlocks() }
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue