diff --git a/assets/js/blocks/product-categories/index.js b/assets/js/blocks/product-categories/index.js index 865a3658c76..87add60886b 100644 --- a/assets/js/blocks/product-categories/index.js +++ b/assets/js/blocks/product-categories/index.js @@ -2,7 +2,7 @@ * External dependencies */ import { __ } from '@wordpress/i18n'; -import { registerBlockType } from '@wordpress/blocks'; +import { createBlock, registerBlockType } from '@wordpress/blocks'; import { Icon, list } from '@woocommerce/icons'; /** @@ -83,6 +83,26 @@ registerBlockType( 'woocommerce/product-categories', { }, }, + transforms: { + from: [ + { + type: 'block', + blocks: [ 'core/legacy-widget' ], + // We can't transform if raw instance isn't shown in the REST API. + isMatch: ( { idBase, instance } ) => + idBase === 'woocommerce_product_categories' && + !! instance?.raw, + transform: ( { instance } ) => + createBlock( 'woocommerce/product-categories', { + hasCount: !! instance.raw.count, + hasEmpty: ! instance.raw.hide_empty, + isDropdown: !! instance.raw.dropdown, + isHierarchical: !! instance.raw.hierarchical, + } ), + }, + ], + }, + deprecated: [ { // Deprecate HTML save method in favor of dynamic rendering. diff --git a/assets/js/blocks/product-search/index.js b/assets/js/blocks/product-search/index.js index 7bb7a132e59..656e85220e1 100644 --- a/assets/js/blocks/product-search/index.js +++ b/assets/js/blocks/product-search/index.js @@ -2,7 +2,7 @@ * External dependencies */ import { __ } from '@wordpress/i18n'; -import { registerBlockType } from '@wordpress/blocks'; +import { createBlock, registerBlockType } from '@wordpress/blocks'; import { Icon, search } from '@woocommerce/icons'; /** * Internal dependencies @@ -71,6 +71,25 @@ registerBlockType( 'woocommerce/product-search', { }, }, + transforms: { + from: [ + { + type: 'block', + blocks: [ 'core/legacy-widget' ], + // We can't transform if raw instance isn't shown in the REST API. + isMatch: ( { idBase, instance } ) => + idBase === 'woocommerce_product_search' && !! instance?.raw, + transform: ( { instance } ) => + createBlock( 'woocommerce/product-search', { + label: + instance.raw.title === '' + ? __( 'Search', 'woo-gutenberg-products-block' ) + : instance.raw.title, + } ), + }, + ], + }, + edit, /** diff --git a/assets/js/blocks/reviews/all-reviews/index.js b/assets/js/blocks/reviews/all-reviews/index.js index 2700ce0ffc3..270ab01eca4 100644 --- a/assets/js/blocks/reviews/all-reviews/index.js +++ b/assets/js/blocks/reviews/all-reviews/index.js @@ -2,7 +2,7 @@ * External dependencies */ import { __ } from '@wordpress/i18n'; -import { registerBlockType } from '@wordpress/blocks'; +import { createBlock, registerBlockType } from '@wordpress/blocks'; import { Icon, discussion } from '@woocommerce/icons'; /** @@ -51,6 +51,27 @@ registerBlockType( 'woocommerce/all-reviews', { }, }, + transforms: { + from: [ + { + type: 'block', + blocks: [ 'core/legacy-widget' ], + // We can't transform if raw instance isn't shown in the REST API. + isMatch: ( { idBase, instance } ) => + idBase === 'woocommerce_recent_reviews' && !! instance?.raw, + transform: ( { instance } ) => + createBlock( 'woocommerce/all-reviews', { + reviewsOnPageLoad: instance.raw.number, + imageType: 'product', + showLoadMore: false, + showOrderby: false, + showReviewDate: false, + showReviewContent: false, + } ), + }, + ], + }, + /** * Renders and manages the block. *