Block Widgets: add block transforms for legacy widgets with a block equivalent (https://github.com/woocommerce/woocommerce-blocks/pull/4292)
* Block Widgets: add transforms for legacy widgets with a block equivalent * Update All Reviews block transform to more closely resemble the widget Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * Convert integers to boolean Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
This commit is contained in:
parent
ffa77f26f7
commit
20f70b6626
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue