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

Commit

Permalink
Add catOperator to remaining blocks (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle authored Jan 15, 2019
1 parent bacd407 commit 8aa785d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions assets/js/blocks/product-new/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ProductNewestBlock extends Component {
}

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

getInspectorControls() {
const { attributes, setAttributes } = this.props;
const { columns, rows } = attributes;
const { categories, catOperator, columns, rows } = attributes;

return (
<InspectorControls key="inspector">
Expand Down Expand Up @@ -100,11 +100,15 @@ class ProductNewestBlock extends Component {
initialOpen={ false }
>
<ProductCategoryControl
selected={ attributes.categories }
selected={ categories }
onChange={ ( value = [] ) => {
const ids = value.map( ( { id } ) => id );
setAttributes( { categories: ids } );
} }
operator={ catOperator }
onOperatorChange={ ( value = 'any' ) =>
setAttributes( { catOperator: value } )
}
/>
</PanelBody>
</InspectorControls>
Expand Down
10 changes: 7 additions & 3 deletions assets/js/blocks/product-top-rated/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ProductTopRatedBlock extends Component {
}

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

getInspectorControls() {
const { attributes, setAttributes } = this.props;
const { columns, rows } = attributes;
const { categories, catOperator, columns, rows } = attributes;

return (
<InspectorControls key="inspector">
Expand Down Expand Up @@ -100,11 +100,15 @@ class ProductTopRatedBlock extends Component {
initialOpen={ false }
>
<ProductCategoryControl
selected={ attributes.categories }
selected={ categories }
onChange={ ( value = [] ) => {
const ids = value.map( ( { id } ) => id );
setAttributes( { categories: ids } );
} }
operator={ catOperator }
onOperatorChange={ ( value = 'any' ) =>
setAttributes( { catOperator: value } )
}
/>
</PanelBody>
</InspectorControls>
Expand Down

0 comments on commit 8aa785d

Please sign in to comment.