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

Commit

Permalink
Add useIsDescendentOfSingleProductBlock hook to product rating block (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
thealexandrelara authored May 17, 2023
1 parent 79c9459 commit f39831e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions assets/js/atomic/blocks/product-elements/rating/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 } );
Expand Down

0 comments on commit f39831e

Please sign in to comment.