* Optimise imports of Product Query variation

* Lint: add whitespace
This commit is contained in:
Karol Manijak 2023-07-26 11:08:01 +02:00 committed by GitHub
parent 99e1f46281
commit e09962d65a
4 changed files with 20 additions and 16 deletions

View File

@ -8,15 +8,15 @@ import {
} from '@wordpress/blocks';
import { isWpVersion } from '@woocommerce/settings';
import { __, sprintf } from '@wordpress/i18n';
import {
INNER_BLOCKS_TEMPLATE as productsInnerBlocksTemplate,
QUERY_DEFAULT_ATTRIBUTES as productsQueryDefaultAttributes,
PRODUCT_QUERY_VARIATION_NAME as productsVariationName,
} from '@woocommerce/blocks/product-query/constants';
/**
* Internal dependencies
*/
import {
INNER_BLOCKS_TEMPLATE as productsInnerBlocksTemplate,
QUERY_DEFAULT_ATTRIBUTES as productsQueryDefaultAttributes,
} from '../product-query/constants';
import { VARIATION_NAME as productsVariationName } from '../product-query/variations/product-query';
import { createArchiveTitleBlock, createRowBlock } from './utils';
import { OnClickCallbackParameter, type InheritedAttributes } from './types';

View File

@ -9,15 +9,15 @@ import {
} from '@wordpress/blocks';
import { isWpVersion } from '@woocommerce/settings';
import { __, sprintf } from '@wordpress/i18n';
import {
INNER_BLOCKS_TEMPLATE as productsInnerBlocksTemplate,
QUERY_DEFAULT_ATTRIBUTES as productsQueryDefaultAttributes,
PRODUCT_QUERY_VARIATION_NAME as productsVariationName,
} from '@woocommerce/blocks/product-query/constants';
/**
* Internal dependencies
*/
import {
INNER_BLOCKS_TEMPLATE as productsInnerBlocksTemplate,
QUERY_DEFAULT_ATTRIBUTES as productsQueryDefaultAttributes,
} from '../product-query/constants';
import { VARIATION_NAME as productsVariationName } from '../product-query/variations/product-query';
import { createArchiveTitleBlock, createRowBlock } from './utils';
import { OnClickCallbackParameter, type InheritedAttributes } from './types';

View File

@ -16,6 +16,8 @@ import { ImageSizing } from '../../atomic/blocks/product-elements/image/types';
export const AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false;
export const MANUAL_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false;
export const PRODUCT_QUERY_VARIATION_NAME = 'woocommerce/product-query';
export const EDIT_ATTRIBUTES_URL =
'/wp-admin/edit.php?post_type=product&page=product_attributes';

View File

@ -17,14 +17,13 @@ import { isSiteEditorPage } from '@woocommerce/utils';
* Internal dependencies
*/
import {
PRODUCT_QUERY_VARIATION_NAME,
DEFAULT_ALLOWED_CONTROLS,
INNER_BLOCKS_TEMPLATE,
QUERY_DEFAULT_ATTRIBUTES,
QUERY_LOOP_ID,
} from '../constants';
export const VARIATION_NAME = 'woocommerce/product-query';
const ARCHIVE_PRODUCT_TEMPLATES = [
'woocommerce/woocommerce//archive-product',
'woocommerce/woocommerce//taxonomy-product_cat',
@ -39,11 +38,11 @@ const registerProductsBlock = ( attributes: QueryBlockAttributes ) => {
'A block that displays a selection of products in your store.',
'woo-gutenberg-products-block'
),
name: VARIATION_NAME,
name: PRODUCT_QUERY_VARIATION_NAME,
/* translators: “Products“ is the name of the block. */
title: __( 'Products (Beta)', 'woo-gutenberg-products-block' ),
isActive: ( blockAttributes ) =>
blockAttributes.namespace === VARIATION_NAME,
blockAttributes.namespace === PRODUCT_QUERY_VARIATION_NAME,
icon: (
<Icon
icon={ stacks }
@ -52,7 +51,7 @@ const registerProductsBlock = ( attributes: QueryBlockAttributes ) => {
),
attributes: {
...attributes,
namespace: VARIATION_NAME,
namespace: PRODUCT_QUERY_VARIATION_NAME,
},
// Gutenberg doesn't support this type yet, discussion here:
// https://github.com/WordPress/gutenberg/pull/43632
@ -84,7 +83,10 @@ if ( isWpVersion( '6.1', '>=' ) ) {
},
};
unregisterBlockVariation( QUERY_LOOP_ID, VARIATION_NAME );
unregisterBlockVariation(
QUERY_LOOP_ID,
PRODUCT_QUERY_VARIATION_NAME
);
registerProductsBlock( queryAttributes );
}