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';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-02-21 19:00:47 +00:00
|
|
|
import GridContentControl from '../../components/grid-content-control';
|
2019-01-31 22:55:54 +00:00
|
|
|
import GridLayoutControl from '../../components/grid-layout-control';
|
2019-01-10 18:16:37 +00:00
|
|
|
import ProductCategoryControl from '../../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,
|
|
|
|
} = 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 }
|
|
|
|
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 }
|
|
|
|
onChange={ ( value ) => setAttributes( { contentVisibility: value } ) }
|
|
|
|
/>
|
|
|
|
</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-06-11 13:50:42 +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;
|