Commit 7b7a925c7ec for woocommerce
commit 7b7a925c7ec2052601ca48cc3837ef651686fc31
Author: Luigi Teschio <gigitux@gmail.com>
Date: Fri Jul 31 11:35:30 2026 +0200
Fix review selector controls shown by default (#67151)
* Refactor inspector controls
* fix logic
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.tsx
index d400b256428..db5c0879a9b 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.tsx
@@ -46,31 +46,6 @@ const ReviewsByCategoryEditor = ( {
const getInspectorControls = () => {
return (
<InspectorControls key="inspector">
- <ToolsPanel
- label={ __( 'Category', 'woocommerce' ) }
- resetAll={ () => setAttributes( { categoryIds: [] } ) }
- >
- <ToolsPanelItem
- hasValue={ () =>
- ( attributes.categoryIds || [] ).length > 0
- }
- label={ __( 'Category', 'woocommerce' ) }
- onDeselect={ () =>
- setAttributes( { categoryIds: [] } )
- }
- isShownByDefault
- >
- <ProductCategoryControl
- selected={ attributes.categoryIds }
- onChange={ ( value = [] ) => {
- const ids = value.map( ( { id } ) => id );
- setAttributes( { categoryIds: ids } );
- } }
- isCompact={ true }
- showReviewCount={ true }
- />
- </ToolsPanelItem>
- </ToolsPanel>
<ToolsPanel
label={ __( 'Content', 'woocommerce' ) }
resetAll={ () =>
@@ -124,6 +99,31 @@ const ReviewsByCategoryEditor = ( {
>
{ getSharedReviewListControls( attributes, setAttributes ) }
</ToolsPanel>
+ <ToolsPanel
+ label={ __( 'Category', 'woocommerce' ) }
+ resetAll={ () => setAttributes( { categoryIds: [] } ) }
+ >
+ <ToolsPanelItem
+ hasValue={ () =>
+ ( attributes.categoryIds || [] ).length > 0
+ }
+ label={ __( 'Category', 'woocommerce' ) }
+ onDeselect={ () =>
+ setAttributes( { categoryIds: [] } )
+ }
+ isShownByDefault
+ >
+ <ProductCategoryControl
+ selected={ attributes.categoryIds }
+ onChange={ ( value = [] ) => {
+ const ids = value.map( ( { id } ) => id );
+ setAttributes( { categoryIds: ids } );
+ } }
+ isCompact={ true }
+ showReviewCount={ true }
+ />
+ </ToolsPanelItem>
+ </ToolsPanel>
</InspectorControls>
);
};
@@ -171,7 +171,7 @@ const ReviewsByCategoryEditor = ( {
);
};
- if ( ! categoryIds || editMode ) {
+ if ( ! categoryIds || categoryIds.length === 0 || editMode ) {
return renderEditMode();
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/edit.tsx
index 24f136dd7c4..a1cbba691ec 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/edit.tsx
@@ -76,31 +76,6 @@ const ReviewsByProductEditor = ( {
const getInspectorControls = () => {
return (
<InspectorControls key="inspector">
- <ToolsPanel
- label={ __( 'Product', 'woocommerce' ) }
- resetAll={ () => setAttributes( { productId: 0 } ) }
- >
- <ToolsPanelItem
- hasValue={ () => !! attributes.productId }
- label={ __( 'Product', 'woocommerce' ) }
- onDeselect={ () => setAttributes( { productId: 0 } ) }
- isShownByDefault
- >
- <ProductControl
- selected={
- attributes.productId
- ? [ attributes.productId ]
- : []
- }
- onChange={ ( value = [] ) => {
- const id = value[ 0 ] ? value[ 0 ].id : 0;
- setAttributes( { productId: id } );
- } }
- renderItem={ renderProductControlItem }
- isCompact={ true }
- />
- </ToolsPanelItem>
- </ToolsPanel>
<ToolsPanel
label={ __( 'Content', 'woocommerce' ) }
resetAll={ () =>
@@ -133,6 +108,31 @@ const ReviewsByProductEditor = ( {
>
{ getSharedReviewListControls( attributes, setAttributes ) }
</ToolsPanel>
+ <ToolsPanel
+ label={ __( 'Product', 'woocommerce' ) }
+ resetAll={ () => setAttributes( { productId: 0 } ) }
+ >
+ <ToolsPanelItem
+ hasValue={ () => !! attributes.productId }
+ label={ __( 'Product', 'woocommerce' ) }
+ onDeselect={ () => setAttributes( { productId: 0 } ) }
+ isShownByDefault
+ >
+ <ProductControl
+ selected={
+ attributes.productId
+ ? [ attributes.productId ]
+ : []
+ }
+ onChange={ ( value = [] ) => {
+ const id = value[ 0 ] ? value[ 0 ].id : 0;
+ setAttributes( { productId: id } );
+ } }
+ renderItem={ renderProductControlItem }
+ isCompact={ true }
+ />
+ </ToolsPanelItem>
+ </ToolsPanel>
</InspectorControls>
);
};