From f39831e2f655beef68b6d8ef08cd5cb660979bae Mon Sep 17 00:00:00 2001 From: Alexandre Lara Date: Wed, 17 May 2023 10:58:12 -0300 Subject: [PATCH] Add useIsDescendentOfSingleProductBlock hook to product rating block (#9489) --- .../blocks/product-elements/rating/edit.tsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/assets/js/atomic/blocks/product-elements/rating/edit.tsx b/assets/js/atomic/blocks/product-elements/rating/edit.tsx index 7bda840fef3..bdc91ed662e 100644 --- a/assets/js/atomic/blocks/product-elements/rating/edit.tsx +++ b/assets/js/atomic/blocks/product-elements/rating/edit.tsx @@ -10,7 +10,6 @@ import { import type { BlockEditProps } from '@wordpress/blocks'; import { useEffect } from '@wordpress/element'; import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types'; -import { useSelect } from '@wordpress/data'; /** * Internal dependencies @@ -20,6 +19,7 @@ import withProductSelector from '../shared/with-product-selector'; import { BLOCK_TITLE, BLOCK_ICON } from './constants'; import { BlockAttributes } from './types'; import './editor.scss'; +import { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block'; const Edit = ( { attributes, @@ -34,16 +34,10 @@ const Edit = ( { ...context, }; const isDescendentOfQueryLoop = Number.isFinite( context.queryId ); - const { isDescendentOfSingleProductBlock } = useSelect( ( select ) => { - const { getBlockParentsByBlockName } = select( 'core/block-editor' ); - const blockParentBlocksIds = getBlockParentsByBlockName( - blockProps?.id?.replace( 'block-', '' ), - [ 'woocommerce/single-product' ] - ); - return { - isDescendentOfSingleProductBlock: blockParentBlocksIds.length > 0, - }; - } ); + const { isDescendentOfSingleProductBlock } = + useIsDescendentOfSingleProductBlock( { + blockClientId: blockProps?.id, + } ); useEffect( () => { setAttributes( { isDescendentOfQueryLoop } );