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';
|
|
|
|
import Editor from './edit';
|
|
|
|
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', {
|
|
|
|
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,
|
|
|
|
},
|
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,
|
|
|
|
} ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2019-08-23 14:48:48 +00:00
|
|
|
/**
|
|
|
|
* Renders and manages the block.
|
2019-12-10 17:17:46 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Props to pass to block.
|
2019-08-23 14:48:48 +00:00
|
|
|
*/
|
|
|
|
edit( props ) {
|
|
|
|
return <Editor { ...props } />;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the props to post content.
|
|
|
|
*/
|
|
|
|
save,
|
|
|
|
} );
|