2018-12-14 19:45:19 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2019-05-28 12:06:12 +00:00
|
|
|
import { Disabled, PanelBody } from '@wordpress/components';
|
|
|
|
import { InspectorControls, ServerSideRender } from '@wordpress/editor';
|
2018-12-14 19:45:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-10-06 12:36:15 +00:00
|
|
|
import GridContentControl from '@woocommerce/block-components/grid-content-control';
|
|
|
|
import GridLayoutControl from '@woocommerce/block-components/grid-layout-control';
|
|
|
|
import ProductCategoryControl from '@woocommerce/block-components/product-category-control';
|
2018-12-14 19:45:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to handle edit mode of "Top Rated Products".
|
|
|
|
*/
|
|
|
|
class ProductTopRatedBlock extends Component {
|
|
|
|
getInspectorControls() {
|
|
|
|
const { attributes, setAttributes } = this.props;
|
2019-02-21 19:00:47 +00:00
|
|
|
const {
|
|
|
|
categories,
|
|
|
|
catOperator,
|
|
|
|
columns,
|
|
|
|
contentVisibility,
|
|
|
|
rows,
|
2019-06-27 11:13:02 +00:00
|
|
|
alignButtons,
|
2019-02-21 19:00:47 +00:00
|
|
|
} = attributes;
|
2018-12-14 19:45:19 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<InspectorControls key="inspector">
|
|
|
|
<PanelBody
|
|
|
|
title={ __( 'Layout', 'woo-gutenberg-products-block' ) }
|
|
|
|
initialOpen
|
|
|
|
>
|
2019-01-31 22:55:54 +00:00
|
|
|
<GridLayoutControl
|
|
|
|
columns={ columns }
|
|
|
|
rows={ rows }
|
2019-06-27 11:13:02 +00:00
|
|
|
alignButtons={ alignButtons }
|
2019-01-31 22:55:54 +00:00
|
|
|
setAttributes={ setAttributes }
|
2018-12-14 19:45:19 +00:00
|
|
|
/>
|
|
|
|
</PanelBody>
|
2019-02-21 19:00:47 +00:00
|
|
|
<PanelBody
|
|
|
|
title={ __( 'Content', 'woo-gutenberg-products-block' ) }
|
|
|
|
initialOpen
|
|
|
|
>
|
|
|
|
<GridContentControl
|
|
|
|
settings={ contentVisibility }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ ( value ) =>
|
|
|
|
setAttributes( { contentVisibility: value } )
|
|
|
|
}
|
2019-02-21 19:00:47 +00:00
|
|
|
/>
|
|
|
|
</PanelBody>
|
2018-12-14 19:45:19 +00:00
|
|
|
<PanelBody
|
|
|
|
title={ __(
|
|
|
|
'Filter by Product Category',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
initialOpen={ false }
|
|
|
|
>
|
|
|
|
<ProductCategoryControl
|
2019-01-15 18:52:34 +00:00
|
|
|
selected={ categories }
|
2018-12-14 19:45:19 +00:00
|
|
|
onChange={ ( value = [] ) => {
|
|
|
|
const ids = value.map( ( { id } ) => id );
|
|
|
|
setAttributes( { categories: ids } );
|
|
|
|
} }
|
2019-01-15 18:52:34 +00:00
|
|
|
operator={ catOperator }
|
|
|
|
onOperatorChange={ ( value = 'any' ) =>
|
|
|
|
setAttributes( { catOperator: value } )
|
|
|
|
}
|
2018-12-14 19:45:19 +00:00
|
|
|
/>
|
|
|
|
</PanelBody>
|
|
|
|
</InspectorControls>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-05-28 12:06:12 +00:00
|
|
|
const { name, attributes } = this.props;
|
2018-12-14 19:45:19 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
{ this.getInspectorControls() }
|
2019-05-28 12:06:12 +00:00
|
|
|
<Disabled>
|
2019-09-09 10:52:48 +00:00
|
|
|
<ServerSideRender
|
|
|
|
block={ name }
|
|
|
|
attributes={ attributes }
|
|
|
|
/>
|
2019-05-28 12:06:12 +00:00
|
|
|
</Disabled>
|
2018-12-14 19:45:19 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProductTopRatedBlock.propTypes = {
|
|
|
|
/**
|
|
|
|
* The attributes for this block
|
|
|
|
*/
|
|
|
|
attributes: PropTypes.object.isRequired,
|
|
|
|
/**
|
|
|
|
* The register block name.
|
|
|
|
*/
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
/**
|
|
|
|
* A callback to update attributes
|
|
|
|
*/
|
|
|
|
setAttributes: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProductTopRatedBlock;
|