This commit is contained in:
Kelly Dwan 2019-01-15 13:52:34 -05:00 committed by GitHub
parent dfba64e833
commit ea4996267c
2 changed files with 14 additions and 6 deletions

View File

@ -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 ) {
@ -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">
@ -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>

View File

@ -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 ) {
@ -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">
@ -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>