Specify Product Price ancestor and simplify Product Elements ancestors (#47802)

* Extend product elements sharedConfig ancestor with Product Collection and Products (Beta)

* Utilise sharedConfig ancestor in Image block

* Utilise sharedConfig ancestor in Price block

* Utilise sharedConfig ancestor in Rating block

* Utilise sharedConfig ancestor in Sale Badge block

* Utilise sharedConfig ancestor in SKU block

* Utilise sharedConfig ancestor in Stock Indicator block

* Add changelog

* Bring back original ancestors for Summary and Title blocks

* Remove Product Price from a test as it's no longer available in global context
This commit is contained in:
Karol Manijak 2024-05-27 09:15:32 +02:00 committed by GitHub
parent c70a09a57e
commit 92fec889f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 22 additions and 36 deletions

View File

@ -27,12 +27,6 @@ const blockConfig: BlockConfiguration = {
keywords: [ 'WooCommerce' ], keywords: [ 'WooCommerce' ],
description, description,
usesContext: [ 'query', 'queryId', 'postId' ], usesContext: [ 'query', 'queryId', 'postId' ],
ancestor: [
'woocommerce/all-products',
'woocommerce/single-product',
'core/post-template',
'woocommerce/product-template',
],
textdomain: 'woocommerce', textdomain: 'woocommerce',
attributes, attributes,
supports, supports,

View File

@ -16,10 +16,8 @@ import {
BLOCK_DESCRIPTION as description, BLOCK_DESCRIPTION as description,
} from './constants'; } from './constants';
const { ancestor, ...configuration } = sharedConfig;
const blockConfig = { const blockConfig = {
...configuration, ...sharedConfig,
apiVersion: 2, apiVersion: 2,
title, title,
description, description,

View File

@ -15,12 +15,6 @@ import { supports } from './support';
const blockConfig: BlockConfiguration = { const blockConfig: BlockConfiguration = {
...sharedConfig, ...sharedConfig,
ancestor: [
'woocommerce/all-products',
'woocommerce/single-product',
'core/post-template',
'woocommerce/product-template',
],
icon: { src: icon }, icon: { src: icon },
supports, supports,
edit, edit,

View File

@ -28,10 +28,7 @@ const blockConfig: BlockConfiguration = {
edit, edit,
usesContext: [ 'query', 'queryId', 'postId' ], usesContext: [ 'query', 'queryId', 'postId' ],
ancestor: [ ancestor: [
'woocommerce/all-products', ...( sharedConfig.ancestor || [] ),
'woocommerce/single-product',
'core/post-template',
'woocommerce/product-template',
'woocommerce/product-gallery', 'woocommerce/product-gallery',
], ],
}; };

View File

@ -28,7 +28,14 @@ const sharedConfig: Omit< BlockConfiguration, 'attributes' | 'title' > = {
supports: { supports: {
html: false, html: false,
}, },
ancestor: [ 'woocommerce/all-products', 'woocommerce/single-product' ], ancestor: [
'woocommerce/all-products',
'woocommerce/single-product',
// Product Collection product template
'woocommerce/product-template',
// Products (Beta) product template
'core/post-template',
],
save, save,
deprecated: [ deprecated: [
{ {

View File

@ -17,10 +17,8 @@ import {
BLOCK_DESCRIPTION as description, BLOCK_DESCRIPTION as description,
} from './constants'; } from './constants';
const { ancestor, ...configuration } = sharedConfig;
const blockConfig: BlockConfiguration = { const blockConfig: BlockConfiguration = {
...configuration, ...sharedConfig,
apiVersion: 2, apiVersion: 2,
title, title,
description, description,
@ -28,10 +26,7 @@ const blockConfig: BlockConfiguration = {
usesContext: [ 'query', 'queryId', 'postId' ], usesContext: [ 'query', 'queryId', 'postId' ],
attributes, attributes,
ancestor: [ ancestor: [
'woocommerce/all-products', ...( sharedConfig.ancestor || [] ),
'woocommerce/single-product',
'core/post-template',
'woocommerce/product-template',
'woocommerce/product-meta', 'woocommerce/product-meta',
], ],
edit, edit,

View File

@ -28,12 +28,6 @@ const blockConfig: BlockConfiguration = {
supports, supports,
edit, edit,
usesContext: [ 'query', 'queryId', 'postId' ], usesContext: [ 'query', 'queryId', 'postId' ],
ancestor: [
'woocommerce/all-products',
'woocommerce/single-product',
'core/post-template',
'woocommerce/product-template',
],
}; };
registerBlockType( 'woocommerce/product-stock-indicator', { registerBlockType( 'woocommerce/product-stock-indicator', {

View File

@ -20,6 +20,9 @@ import { Save } from './save';
const blockConfig: BlockConfiguration = { const blockConfig: BlockConfiguration = {
...sharedConfig, ...sharedConfig,
// Product Summary is not expected to be available in Product Collection
// nor Products (Beta). They use core/post-summary variation.
ancestor: [ 'woocommerce/all-products', 'woocommerce/single-product' ],
apiVersion: 2, apiVersion: 2,
title, title,
description, description,

View File

@ -22,6 +22,9 @@ import { Save } from './save';
const blockConfig: BlockConfiguration = { const blockConfig: BlockConfiguration = {
...sharedConfig, ...sharedConfig,
// Product Title is not expected to be available in Product Collection
// nor Products (Beta). They use core/post-title variation.
ancestor: [ 'woocommerce/all-products', 'woocommerce/single-product' ],
apiVersion: 2, apiVersion: 2,
title, title,
description, description,

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Product Price: Narrow down the ancestors of the block so it's available in inserter only in places where block makes sense

View File

@ -13,9 +13,6 @@ const singleProductPrice = '555.00';
// all WooCommerce blocks except: // all WooCommerce blocks except:
// default cart and checkout blocks, mini-cart, product collection // default cart and checkout blocks, mini-cart, product collection
const blocks = [ const blocks = [
{
name: 'Product Price',
},
{ {
name: 'Product Search', name: 'Product Search',
}, },