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

Commit

Permalink
Fix Product Rating Block not showing when manually inserted to Single…
Browse files Browse the repository at this point in the history
… Product block (#9413)
  • Loading branch information
thealexandrelara authored May 16, 2023
1 parent 4ee1f83 commit a4fb03d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
23 changes: 19 additions & 4 deletions assets/js/atomic/blocks/product-elements/rating/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 @@ -33,11 +34,25 @@ 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,
};
} );

useEffect(
() => setAttributes( { isDescendentOfQueryLoop } ),
[ setAttributes, isDescendentOfQueryLoop ]
);
useEffect( () => {
setAttributes( { isDescendentOfQueryLoop } );
setAttributes( { isDescendentOfSingleProductBlock } );
}, [
setAttributes,
isDescendentOfQueryLoop,
isDescendentOfSingleProductBlock,
] );

return (
<>
Expand Down
1 change: 1 addition & 0 deletions assets/js/atomic/blocks/product-elements/rating/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface BlockAttributes {
productId: number;
isDescendentOfQueryLoop: boolean;
isDescendentOfSingleProductBlock: boolean;
textAlign: string;
}

0 comments on commit a4fb03d

Please sign in to comment.