woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-on-sale/block.js

139 lines
3.5 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { Disabled, PanelBody, Placeholder } from '@wordpress/components';
Dynamic grid blocks: Try using ServerSideRender component for preview (https://github.com/woocommerce/woocommerce-blocks/pull/565) * Add grid block base class to handle rendering all grid blocks Using code from the shortcode handler to create the query, subclass into newest product to show use * Update preview content to match rendering from the new grid block handler * Fix the categories query builder * Update order of rating/price * Remove center alignment * Extract rating & button into separate functions * Wrap the content in a link * Add the current class names for better theme support * Fix some styling in editor preview & frontend * Add back the deprecated cols support for existing blocks * Add multiple-rows class, style tweaks * Switch Newest Products to dynamic rendering, deprecate existing shortcode method * Add “On Sale” flag * Switch “On Sale Products” to dynamic rendering * Fix reusable block preview * Add correct classes to On Sale Products * Remove dynamic blocks from CSS hidden content rules Content is not output to browser now, so we don’t need to hide it * Fix undefined parameters * Fix attributes for on sale * Add deprecation comment, use more descriptive function name * Addressing review feedback * Update test: classnames have changed, image now wrapped in div * Disable HTML editing for dynamic blocks * Moved rendering logic into block library * Try using ServerSideRender component for preview * Define the schema for contentVisibility This ensures the API correctly uses boolean instead of “true”/“false” strings * Move the star rating CSS to the general grid-blocks section * Remove the list styling, which is added back by core GB styles * Fix stylelint issues
2019-05-21 20:34:48 +00:00
import { InspectorControls, ServerSideRender } from '@wordpress/editor';
import PropTypes from 'prop-types';
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';
import ProductOrderbyControl from '@woocommerce/block-components/product-orderby-control';
import { gridBlockPreview } from '@woocommerce/resource-previews';
import { IconProductOnSale } from '@woocommerce/block-components/icons';
const EmptyPlaceholder = () => (
<Placeholder
icon={ <IconProductOnSale /> }
label={ __( 'On Sale Products', 'woo-gutenberg-products-block' ) }
className="wc-block-product-on-sale"
>
{ __(
'This block shows on-sale products. There are currently no discounted products in your store.',
'woo-gutenberg-products-block'
) }
</Placeholder>
);
/**
* Component to handle edit mode of "On Sale Products".
*/
class ProductOnSaleBlock extends Component {
getInspectorControls() {
const { attributes, setAttributes } = this.props;
const {
categories,
catOperator,
columns,
contentVisibility,
rows,
orderby,
alignButtons,
} = attributes;
return (
<InspectorControls key="inspector">
<PanelBody
title={ __( 'Layout', 'woo-gutenberg-products-block' ) }
initialOpen
>
<GridLayoutControl
columns={ columns }
rows={ rows }
alignButtons={ alignButtons }
setAttributes={ setAttributes }
/>
</PanelBody>
<PanelBody
title={ __( 'Content', 'woo-gutenberg-products-block' ) }
initialOpen
>
<GridContentControl
settings={ contentVisibility }
onChange={ ( value ) =>
setAttributes( { contentVisibility: value } )
}
/>
</PanelBody>
<PanelBody
title={ __( 'Order By', 'woo-gutenberg-products-block' ) }
initialOpen={ false }
>
<ProductOrderbyControl
setAttributes={ setAttributes }
value={ orderby }
/>
</PanelBody>
<PanelBody
title={ __(
'Filter by Product Category',
'woo-gutenberg-products-block'
) }
initialOpen={ false }
>
<ProductCategoryControl
selected={ categories }
onChange={ ( value = [] ) => {
const ids = value.map( ( { id } ) => id );
setAttributes( { categories: ids } );
} }
operator={ catOperator }
onOperatorChange={ ( value = 'any' ) =>
setAttributes( { catOperator: value } )
}
/>
</PanelBody>
</InspectorControls>
);
}
render() {
const { attributes, name } = this.props;
if ( attributes.isPreview ) {
return gridBlockPreview;
}
return (
<Fragment>
{ this.getInspectorControls() }
Dynamic grid blocks: Try using ServerSideRender component for preview (https://github.com/woocommerce/woocommerce-blocks/pull/565) * Add grid block base class to handle rendering all grid blocks Using code from the shortcode handler to create the query, subclass into newest product to show use * Update preview content to match rendering from the new grid block handler * Fix the categories query builder * Update order of rating/price * Remove center alignment * Extract rating & button into separate functions * Wrap the content in a link * Add the current class names for better theme support * Fix some styling in editor preview & frontend * Add back the deprecated cols support for existing blocks * Add multiple-rows class, style tweaks * Switch Newest Products to dynamic rendering, deprecate existing shortcode method * Add “On Sale” flag * Switch “On Sale Products” to dynamic rendering * Fix reusable block preview * Add correct classes to On Sale Products * Remove dynamic blocks from CSS hidden content rules Content is not output to browser now, so we don’t need to hide it * Fix undefined parameters * Fix attributes for on sale * Add deprecation comment, use more descriptive function name * Addressing review feedback * Update test: classnames have changed, image now wrapped in div * Disable HTML editing for dynamic blocks * Moved rendering logic into block library * Try using ServerSideRender component for preview * Define the schema for contentVisibility This ensures the API correctly uses boolean instead of “true”/“false” strings * Move the star rating CSS to the general grid-blocks section * Remove the list styling, which is added back by core GB styles * Fix stylelint issues
2019-05-21 20:34:48 +00:00
<Disabled>
<ServerSideRender
block={ name }
attributes={ attributes }
EmptyResponsePlaceholder={ EmptyPlaceholder }
/>
Dynamic grid blocks: Try using ServerSideRender component for preview (https://github.com/woocommerce/woocommerce-blocks/pull/565) * Add grid block base class to handle rendering all grid blocks Using code from the shortcode handler to create the query, subclass into newest product to show use * Update preview content to match rendering from the new grid block handler * Fix the categories query builder * Update order of rating/price * Remove center alignment * Extract rating & button into separate functions * Wrap the content in a link * Add the current class names for better theme support * Fix some styling in editor preview & frontend * Add back the deprecated cols support for existing blocks * Add multiple-rows class, style tweaks * Switch Newest Products to dynamic rendering, deprecate existing shortcode method * Add “On Sale” flag * Switch “On Sale Products” to dynamic rendering * Fix reusable block preview * Add correct classes to On Sale Products * Remove dynamic blocks from CSS hidden content rules Content is not output to browser now, so we don’t need to hide it * Fix undefined parameters * Fix attributes for on sale * Add deprecation comment, use more descriptive function name * Addressing review feedback * Update test: classnames have changed, image now wrapped in div * Disable HTML editing for dynamic blocks * Moved rendering logic into block library * Try using ServerSideRender component for preview * Define the schema for contentVisibility This ensures the API correctly uses boolean instead of “true”/“false” strings * Move the star rating CSS to the general grid-blocks section * Remove the list styling, which is added back by core GB styles * Fix stylelint issues
2019-05-21 20:34:48 +00:00
</Disabled>
</Fragment>
);
}
}
ProductOnSaleBlock.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 ProductOnSaleBlock;