Merge pull request woocommerce/woocommerce-blocks#37 from woocommerce/remove-toggles

Remove toggles and order setting
This commit is contained in:
Claudiu Lodromanean 2018-02-23 09:55:42 -08:00 committed by GitHub
commit c323d42345
2 changed files with 22 additions and 220 deletions

View File

@ -426,40 +426,25 @@ var ProductPreview = function (_React$Component4) {
image = wp.element.createElement('img', { src: product.images[0].src });
}
var title = null;
if (attributes.display_title) {
title = wp.element.createElement(
'div',
{ className: 'product-title' },
product.name
);
}
var price = null;
if (attributes.display_price) {
price = wp.element.createElement(
'div',
{ className: 'product-price' },
product.price
);
}
var add_to_cart = null;
if (attributes.display_add_to_cart) {
add_to_cart = wp.element.createElement(
'span',
{ className: 'product-add-to-cart' },
__('Add to cart')
);
}
return wp.element.createElement(
'div',
{ className: 'product-preview' },
image,
title,
price,
add_to_cart
wp.element.createElement(
'div',
{ className: 'product-title' },
product.name
),
wp.element.createElement(
'div',
{ className: 'product-price' },
product.price
),
wp.element.createElement(
'span',
{ className: 'product-add-to-cart' },
__('Add to cart')
)
);
}
}]);
@ -476,15 +461,13 @@ var ProductsBlockPreview = withAPIData(function (_ref) {
var attributes = _ref.attributes;
var columns = attributes.columns,
rows = attributes.rows,
order = attributes.order,
display = attributes.display,
display_setting = attributes.display_setting,
layout = attributes.layout;
var query = {
per_page: 'list' === layout ? rows : rows * columns,
orderby: order
per_page: 'list' === layout ? rows : rows * columns
};
if ('specific' === display) {
@ -587,38 +570,6 @@ registerBlockType('woocommerce/products', {
default: 1
},
/**
* Whether to display product titles.
*/
display_title: {
type: 'boolean',
default: true
},
/**
* Whether to display prices.
*/
display_price: {
type: 'boolean',
default: true
},
/**
* Whether to display Add to Cart buttons.
*/
display_add_to_cart: {
type: 'boolean',
default: false
},
/**
* Order to use for products. 'date', or 'title'.
*/
order: {
type: 'string',
default: 'date'
},
/**
* What types of products to display. 'all', 'specific', or 'category'.
*/
@ -656,10 +607,6 @@ registerBlockType('woocommerce/products', {
var layout = attributes.layout,
rows = attributes.rows,
columns = attributes.columns,
display_title = attributes.display_title,
display_price = attributes.display_price,
display_add_to_cart = attributes.display_add_to_cart,
order = attributes.order,
display = attributes.display,
display_setting = attributes.display_setting,
edit_mode = attributes.edit_mode;
@ -696,42 +643,6 @@ registerBlockType('woocommerce/products', {
},
min: 1,
max: 6
}),
wp.element.createElement(ToggleControl, {
label: __('Display title'),
checked: display_title,
onChange: function onChange() {
return setAttributes({ display_title: !display_title });
}
}),
wp.element.createElement(ToggleControl, {
label: __('Display price'),
checked: display_price,
onChange: function onChange() {
return setAttributes({ display_price: !display_price });
}
}),
wp.element.createElement(ToggleControl, {
label: __('Display add to cart button'),
checked: display_add_to_cart,
onChange: function onChange() {
return setAttributes({ display_add_to_cart: !display_add_to_cart });
}
}),
wp.element.createElement(SelectControl, {
key: 'query-panel-select',
label: __('Order'),
value: order,
options: [{
label: __('Newness'),
value: 'date'
}, {
label: __('Title'),
value: 'title'
}],
onChange: function onChange(value) {
return setAttributes({ order: value });
}
})
);
};
@ -819,17 +730,12 @@ registerBlockType('woocommerce/products', {
layout = _props$attributes.layout,
rows = _props$attributes.rows,
columns = _props$attributes.columns,
display_title = _props$attributes.display_title,
display_price = _props$attributes.display_price,
display_add_to_cart = _props$attributes.display_add_to_cart,
order = _props$attributes.order,
display = _props$attributes.display,
display_setting = _props$attributes.display_setting,
className = _props$attributes.className;
var shortcode_atts = new Map();
shortcode_atts.set('orderby', order);
shortcode_atts.set('limit', 'grid' === layout ? rows * columns : rows);
shortcode_atts.set('class', 'list' === layout ? className + ' list-layout' : className);
@ -837,18 +743,6 @@ registerBlockType('woocommerce/products', {
shortcode_atts.set('columns', columns);
}
if (!display_title) {
shortcode_atts.set('show_title', 0);
}
if (!display_price) {
shortcode_atts.set('show_price', 0);
}
if (!display_add_to_cart) {
shortcode_atts.set('show_add_to_cart', 0);
}
if ('specific' === display) {
shortcode_atts.set('include', display_setting.join(','));
}

View File

@ -229,27 +229,12 @@ class ProductPreview extends React.Component {
image = <img src={ product.images[0].src } />
}
let title = null;
if ( attributes.display_title ) {
title = <div className="product-title">{ product.name }</div>
}
let price = null;
if ( attributes.display_price ) {
price = <div className="product-price">{ product.price }</div>
}
let add_to_cart = null;
if ( attributes.display_add_to_cart ) {
add_to_cart = <span className="product-add-to-cart">{ __( 'Add to cart' ) }</span>
}
return (
<div className="product-preview">
{ image }
{ title }
{ price }
{ add_to_cart }
<div className="product-title">{ product.name }</div>
<div className="product-price">{ product.price }</div>
<span className="product-add-to-cart">{ __( 'Add to cart' ) }</span>
</div>
);
}
@ -260,11 +245,10 @@ class ProductPreview extends React.Component {
*/
const ProductsBlockPreview = withAPIData( ( { attributes } ) => {
const { columns, rows, order, display, display_setting, layout } = attributes;
const { columns, rows, display, display_setting, layout } = attributes;
let query = {
per_page: ( 'list' === layout ) ? rows : rows * columns,
orderby: order
};
if ( 'specific' === display ) {
@ -344,38 +328,6 @@ registerBlockType( 'woocommerce/products', {
default: 1,
},
/**
* Whether to display product titles.
*/
display_title: {
type: 'boolean',
default: true,
},
/**
* Whether to display prices.
*/
display_price: {
type: 'boolean',
default: true,
},
/**
* Whether to display Add to Cart buttons.
*/
display_add_to_cart: {
type: 'boolean',
default: false,
},
/**
* Order to use for products. 'date', or 'title'.
*/
order: {
type: 'string',
default: 'date',
},
/**
* What types of products to display. 'all', 'specific', or 'category'.
*/
@ -406,7 +358,7 @@ registerBlockType( 'woocommerce/products', {
*/
edit( props ) {
const { attributes, className, focus, setAttributes, setFocus } = props;
const { layout, rows, columns, display_title, display_price, display_add_to_cart, order, display, display_setting, edit_mode } = attributes;
const { layout, rows, columns, display, display_setting, edit_mode } = attributes;
/**
* Get the components for the sidebar settings area that is rendered while focused on a Products block.
@ -431,37 +383,6 @@ registerBlockType( 'woocommerce/products', {
min={ 1 }
max={ 6 }
/>
<ToggleControl
label={ __( 'Display title' ) }
checked={ display_title }
onChange={ () => setAttributes( { display_title: ! display_title } ) }
/>
<ToggleControl
label={ __( 'Display price' ) }
checked={ display_price }
onChange={ () => setAttributes( { display_price: ! display_price } ) }
/>
<ToggleControl
label={ __( 'Display add to cart button' ) }
checked={ display_add_to_cart }
onChange={ () => setAttributes( { display_add_to_cart: ! display_add_to_cart } ) }
/>
<SelectControl
key="query-panel-select"
label={ __( 'Order' ) }
value={ order }
options={ [
{
label: __( 'Newness' ),
value: 'date',
},
{
label: __( 'Title' ),
value: 'title',
},
] }
onChange={ ( value ) => setAttributes( { order: value } ) }
/>
</InspectorControls>
);
};
@ -543,10 +464,9 @@ registerBlockType( 'woocommerce/products', {
* @return string
*/
save( props ) {
const { layout, rows, columns, display_title, display_price, display_add_to_cart, order, display, display_setting, className } = props.attributes;
const { layout, rows, columns, display, display_setting, className } = props.attributes;
let shortcode_atts = new Map();
shortcode_atts.set( 'orderby', order );
shortcode_atts.set( 'limit', 'grid' === layout ? rows * columns : rows );
shortcode_atts.set( 'class', 'list' === layout ? className + ' list-layout' : className );
@ -554,18 +474,6 @@ registerBlockType( 'woocommerce/products', {
shortcode_atts.set( 'columns', columns );
}
if ( ! display_title ) {
shortcode_atts.set( 'show_title', 0 );
}
if ( ! display_price ) {
shortcode_atts.set( 'show_price', 0 );
}
if ( ! display_add_to_cart ) {
shortcode_atts.set( 'show_add_to_cart', 0 );
}
if ( 'specific' === display ) {
shortcode_atts.set( 'include', display_setting.join( ',' ) );
}