2019-08-23 14:48:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-06-04 14:47:30 +00:00
|
|
|
import { createBlock, registerBlockType } from '@wordpress/blocks';
|
2020-01-31 18:20:33 +00:00
|
|
|
import { Icon, discussion } from '@woocommerce/icons';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import '../editor.scss';
|
2021-09-16 09:32:48 +00:00
|
|
|
import edit from './edit';
|
2019-08-23 14:48:48 +00:00
|
|
|
import sharedAttributes from '../attributes';
|
|
|
|
import save from '../save.js';
|
2019-10-22 14:13:14 +00:00
|
|
|
import { example } from '../example';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register and run the "All Reviews" block.
|
2019-12-11 14:58:49 +00:00
|
|
|
* This block lists all product reviews.
|
2019-08-23 14:48:48 +00:00
|
|
|
*/
|
|
|
|
registerBlockType( 'woocommerce/all-reviews', {
|
2021-09-16 09:32:48 +00:00
|
|
|
apiVersion: 2,
|
2019-08-23 14:48:48 +00:00
|
|
|
title: __( 'All Reviews', 'woo-gutenberg-products-block' ),
|
|
|
|
icon: {
|
2020-01-31 18:20:33 +00:00
|
|
|
src: <Icon srcElement={ discussion } />,
|
2019-08-23 14:48:48 +00:00
|
|
|
foreground: '#96588a',
|
|
|
|
},
|
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __(
|
2020-02-17 22:02:59 +00:00
|
|
|
'Show a list of all product reviews.',
|
2019-08-23 14:48:48 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
2019-12-17 08:38:31 +00:00
|
|
|
supports: {
|
|
|
|
html: false,
|
2021-09-16 09:32:48 +00:00
|
|
|
color: {
|
|
|
|
background: false,
|
|
|
|
},
|
|
|
|
typography: {
|
|
|
|
fontSize: true,
|
|
|
|
},
|
2019-12-17 08:38:31 +00:00
|
|
|
},
|
2019-10-22 14:13:14 +00:00
|
|
|
example: {
|
|
|
|
...example,
|
|
|
|
attributes: {
|
|
|
|
...example.attributes,
|
|
|
|
showProductName: true,
|
|
|
|
},
|
|
|
|
},
|
2019-08-23 14:48:48 +00:00
|
|
|
attributes: {
|
|
|
|
...sharedAttributes,
|
|
|
|
/**
|
2019-09-05 15:09:31 +00:00
|
|
|
* Show the product name.
|
|
|
|
*/
|
2019-08-23 14:48:48 +00:00
|
|
|
showProductName: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-06-04 14:47:30 +00:00
|
|
|
transforms: {
|
|
|
|
from: [
|
|
|
|
{
|
|
|
|
type: 'block',
|
|
|
|
blocks: [ 'core/legacy-widget' ],
|
|
|
|
// We can't transform if raw instance isn't shown in the REST API.
|
|
|
|
isMatch: ( { idBase, instance } ) =>
|
|
|
|
idBase === 'woocommerce_recent_reviews' && !! instance?.raw,
|
|
|
|
transform: ( { instance } ) =>
|
|
|
|
createBlock( 'woocommerce/all-reviews', {
|
|
|
|
reviewsOnPageLoad: instance.raw.number,
|
|
|
|
imageType: 'product',
|
|
|
|
showLoadMore: false,
|
|
|
|
showOrderby: false,
|
|
|
|
showReviewDate: false,
|
|
|
|
showReviewContent: false,
|
|
|
|
} ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2021-09-16 09:32:48 +00:00
|
|
|
edit,
|
2019-08-23 14:48:48 +00:00
|
|
|
save,
|
|
|
|
} );
|