Product gallery/legacy/transform (#42719)

* Product Image Gallery: Add transform to Product Gallery block

* Single Product Template: Transform to blocks with new Product Gallery block

* Ensure we first check for block existance

* Add changelog

* Add/delete changelog file
This commit is contained in:
Roy Ho 2023-12-14 05:47:48 -08:00 committed by GitHub
parent 81c19c0e39
commit 255f1ff919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -3,6 +3,8 @@
*/ */
import { gallery as icon } from '@wordpress/icons'; import { gallery as icon } from '@wordpress/icons';
import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils'; import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils';
import { createBlock } from '@wordpress/blocks';
import { isExperimentalBuild } from '@woocommerce/block-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -11,6 +13,8 @@ import edit from './edit';
import metadata from './block.json'; import metadata from './block.json';
import './style.scss'; import './style.scss';
const galleryBlock = isExperimentalBuild() ? 'woocommerce/product-gallery' : '';
registerBlockSingleProductTemplate( { registerBlockSingleProductTemplate( {
blockName: metadata.name, blockName: metadata.name,
// @ts-expect-error: `metadata` currently does not have a type definition in WordPress core // @ts-expect-error: `metadata` currently does not have a type definition in WordPress core
@ -19,6 +23,17 @@ registerBlockSingleProductTemplate( {
icon, icon,
// @ts-expect-error `edit` can be extended to include other attributes // @ts-expect-error `edit` can be extended to include other attributes
edit, edit,
transforms: {
to: [
{
type: 'block',
blocks: [ galleryBlock ],
transform: () => {
return createBlock( galleryBlock );
},
},
],
},
}, },
isAvailableOnPostEditor: false, isAvailableOnPostEditor: false,
} ); } );

View File

@ -6,12 +6,17 @@ import { isWpVersion } from '@woocommerce/settings';
import { BlockInstance, createBlock } from '@wordpress/blocks'; import { BlockInstance, createBlock } from '@wordpress/blocks';
import { VARIATION_NAME as PRODUCT_TITLE_VARIATION_NAME } from '@woocommerce/blocks/product-query/variations/elements/product-title'; import { VARIATION_NAME as PRODUCT_TITLE_VARIATION_NAME } from '@woocommerce/blocks/product-query/variations/elements/product-title';
import { VARIATION_NAME as PRODUCT_SUMMARY_VARIATION_NAME } from '@woocommerce/blocks/product-query/variations/elements/product-summary'; import { VARIATION_NAME as PRODUCT_SUMMARY_VARIATION_NAME } from '@woocommerce/blocks/product-query/variations/elements/product-summary';
import { isExperimentalBuild } from '@woocommerce/block-settings';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { OnClickCallbackParameter } from './types'; import { OnClickCallbackParameter } from './types';
const galleryBlock = isExperimentalBuild()
? 'woocommerce/product-gallery'
: 'woocommerce/product-image-gallery';
const getBlockifiedTemplate = () => const getBlockifiedTemplate = () =>
[ [
createBlock( 'woocommerce/breadcrumbs' ), createBlock( 'woocommerce/breadcrumbs' ),
@ -29,7 +34,7 @@ const getBlockifiedTemplate = () =>
justifyContent: 'right', justifyContent: 'right',
width: '512px', width: '512px',
}, },
[ createBlock( 'woocommerce/product-image-gallery' ) ] [ createBlock( galleryBlock ) ]
), ),
createBlock( 'core/column', {}, [ createBlock( 'core/column', {}, [
createBlock( 'core/post-title', { createBlock( 'core/post-title', {

View File

@ -0,0 +1,3 @@
Significance: patch
Type: tweak
Comment: Product Gallery: Add transforms for better discovery.