Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Products by Rating: Add block transform for the legacy rating widget #7338

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion assets/js/blocks/rating-filter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { isExperimentalBuild } from '@woocommerce/block-settings';
import { registerBlockType } from '@wordpress/blocks';
import { createBlock, registerBlockType } from '@wordpress/blocks';
import { Icon, starEmpty } from '@wordpress/icons';
import classNames from 'classnames';
import { useBlockProps } from '@wordpress/block-editor';
Expand All @@ -29,6 +30,28 @@ if ( isExperimentalBuild() ) {
...metadata.attributes,
...blockAttributes,
},
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_rating_filter' &&
!! instance?.raw,
transform: ( { instance } ) =>
createBlock( 'woocommerce/rating-filter', {
heading:
instance?.raw?.title ||
__(
'Filter by rating',
'woo-gutenberg-products-block'
),
headingLevel: 3,
} ),
},
],
},
edit,
// Save the props to post content.
save( { attributes }: { attributes: Attributes } ) {
Expand Down
3 changes: 2 additions & 1 deletion src/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public function hide_legacy_widgets_with_block_equivalent( $widget_types ) {
'woocommerce_product_tag_cloud',
'woocommerce_price_filter',
'woocommerce_layered_nav',
'woocommerce_layered_nav_filters'
'woocommerce_layered_nav_filters',
'woocommerce_rating_filter'
);

return $widget_types;
Expand Down