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

Commit 8aa785d

Browse files
authored
Add catOperator to remaining blocks (#328)
1 parent bacd407 commit 8aa785d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

assets/js/blocks/product-new/block.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ProductNewestBlock extends Component {
4444
}
4545

4646
componentDidUpdate( prevProps ) {
47-
const hasChange = [ 'rows', 'columns', 'categories' ].reduce( ( acc, key ) => {
47+
const hasChange = [ 'rows', 'columns', 'categories', 'catOperator' ].reduce( ( acc, key ) => {
4848
return acc || prevProps.attributes[ key ] !== this.props.attributes[ key ];
4949
}, false );
5050
if ( hasChange ) {
@@ -69,7 +69,7 @@ class ProductNewestBlock extends Component {
6969

7070
getInspectorControls() {
7171
const { attributes, setAttributes } = this.props;
72-
const { columns, rows } = attributes;
72+
const { categories, catOperator, columns, rows } = attributes;
7373

7474
return (
7575
<InspectorControls key="inspector">
@@ -100,11 +100,15 @@ class ProductNewestBlock extends Component {
100100
initialOpen={ false }
101101
>
102102
<ProductCategoryControl
103-
selected={ attributes.categories }
103+
selected={ categories }
104104
onChange={ ( value = [] ) => {
105105
const ids = value.map( ( { id } ) => id );
106106
setAttributes( { categories: ids } );
107107
} }
108+
operator={ catOperator }
109+
onOperatorChange={ ( value = 'any' ) =>
110+
setAttributes( { catOperator: value } )
111+
}
108112
/>
109113
</PanelBody>
110114
</InspectorControls>

assets/js/blocks/product-top-rated/block.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ProductTopRatedBlock extends Component {
4444
}
4545

4646
componentDidUpdate( prevProps ) {
47-
const hasChange = [ 'rows', 'columns', 'categories' ].reduce( ( acc, key ) => {
47+
const hasChange = [ 'rows', 'columns', 'categories', 'catOperator' ].reduce( ( acc, key ) => {
4848
return acc || prevProps.attributes[ key ] !== this.props.attributes[ key ];
4949
}, false );
5050
if ( hasChange ) {
@@ -69,7 +69,7 @@ class ProductTopRatedBlock extends Component {
6969

7070
getInspectorControls() {
7171
const { attributes, setAttributes } = this.props;
72-
const { columns, rows } = attributes;
72+
const { categories, catOperator, columns, rows } = attributes;
7373

7474
return (
7575
<InspectorControls key="inspector">
@@ -100,11 +100,15 @@ class ProductTopRatedBlock extends Component {
100100
initialOpen={ false }
101101
>
102102
<ProductCategoryControl
103-
selected={ attributes.categories }
103+
selected={ categories }
104104
onChange={ ( value = [] ) => {
105105
const ids = value.map( ( { id } ) => id );
106106
setAttributes( { categories: ids } );
107107
} }
108+
operator={ catOperator }
109+
onOperatorChange={ ( value = 'any' ) =>
110+
setAttributes( { catOperator: value } )
111+
}
108112
/>
109113
</PanelBody>
110114
</InspectorControls>

0 commit comments

Comments
 (0)