2018-12-14 19:45:19 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-12-14 11:54:34 +00:00
|
|
|
import { Component } from '@wordpress/element';
|
2019-05-28 12:06:12 +00:00
|
|
|
import { Disabled, PanelBody } from '@wordpress/components';
|
2020-05-12 20:31:49 +00:00
|
|
|
import { InspectorControls } from '@wordpress/block-editor';
|
|
|
|
import { ServerSideRender } from '@wordpress/editor';
|
2018-12-14 19:45:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-09-02 08:21:46 +00:00
|
|
|
import GridContentControl from '@woocommerce/editor-components/grid-content-control';
|
|
|
|
import GridLayoutControl from '@woocommerce/editor-components/grid-layout-control';
|
|
|
|
import ProductCategoryControl from '@woocommerce/editor-components/product-category-control';
|
2019-11-15 15:16:18 +00:00
|
|
|
import { gridBlockPreview } from '@woocommerce/resource-previews';
|
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
|
|
|
|
2019-11-15 15:16:18 +00:00
|
|
|
if ( attributes.isPreview ) {
|
|
|
|
return gridBlockPreview;
|
|
|
|
}
|
|
|
|
|
2018-12-14 19:45:19 +00:00
|
|
|
return (
|
2020-12-14 11:54:34 +00:00
|
|
|
<>
|
2018-12-14 19:45:19 +00:00
|
|
|
{ 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>
|
2020-12-14 11:54:34 +00:00
|
|
|
</>
|
2018-12-14 19:45:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|