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';
|
2022-02-01 16:54:38 +00:00
|
|
|
import { Icon, postComments } from '@wordpress/icons';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import '../editor.scss';
|
2023-06-06 12:46:49 +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';
|
2023-06-06 12:46:49 +00:00
|
|
|
import type { AllReviewsEditorProps } from './types';
|
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', {
|
2024-08-20 10:14:11 +00:00
|
|
|
apiVersion: 3,
|
2023-12-12 22:12:36 +00:00
|
|
|
title: __( 'All Reviews', 'woocommerce' ),
|
2019-08-23 14:48:48 +00:00
|
|
|
icon: {
|
2021-12-10 14:32:44 +00:00
|
|
|
src: (
|
|
|
|
<Icon
|
2022-02-01 16:54:38 +00:00
|
|
|
icon={ postComments }
|
2021-12-10 14:32:44 +00:00
|
|
|
className="wc-block-editor-components-block-icon"
|
|
|
|
/>
|
|
|
|
),
|
2019-08-23 14:48:48 +00:00
|
|
|
},
|
|
|
|
category: 'woocommerce',
|
2023-12-12 22:12:36 +00:00
|
|
|
keywords: [ __( 'WooCommerce', 'woocommerce' ) ],
|
2023-12-12 23:05:20 +00:00
|
|
|
description: __( 'Show a list of all product reviews.', 'woocommerce' ),
|
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.
|
2023-06-06 12:46:49 +00:00
|
|
|
isMatch: ( { idBase, instance }: AllReviewsEditorProps ) =>
|
2021-06-04 14:47:30 +00:00
|
|
|
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,
|
|
|
|
} ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2023-06-06 12:46:49 +00:00
|
|
|
edit: Edit,
|
2019-08-23 14:48:48 +00:00
|
|
|
save,
|
|
|
|
} );
|