woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-top-rated/block.js

106 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-12-14 19:45:19 +00:00
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
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
*/
import GridContentControl from '../../components/grid-content-control';
import GridLayoutControl from '../../components/grid-layout-control';
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;
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
>
<GridLayoutControl
columns={ columns }
rows={ rows }
setAttributes={ setAttributes }
2018-12-14 19:45:19 +00:00
/>
</PanelBody>
<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
selected={ categories }
2018-12-14 19:45:19 +00:00
onChange={ ( value = [] ) => {
const ids = value.map( ( { id } ) => id );
setAttributes( { categories: ids } );
} }
operator={ catOperator }
onOperatorChange={ ( value = 'any' ) =>
setAttributes( { catOperator: value } )
}
2018-12-14 19:45:19 +00:00
/>
</PanelBody>
</InspectorControls>
);
}
render() {
const { name, attributes } = this.props;
2018-12-14 19:45:19 +00:00
return (
<Fragment>
{ this.getInspectorControls() }
<Disabled>
<ServerSideRender block={ name } attributes={ attributes } />
</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;