Skip to content

Commit

Permalink
Products by Rating: Add block transform for the legacy rating widget (w…
Browse files Browse the repository at this point in the history
…oocommerce#7338)

* Products by Rating: Add legacy rating widget deprecation
* Products by Rating: Hide legacy Product Ratings widget
  • Loading branch information
danieldudzic authored and senadir committed Nov 12, 2022
1 parent a476ea1 commit bdb880b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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

0 comments on commit bdb880b

Please sign in to comment.