2019-08-23 14:48:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-05-12 20:31:49 +00:00
|
|
|
import { InspectorControls } from '@wordpress/block-editor';
|
2019-08-23 14:48:48 +00:00
|
|
|
import { PanelBody, ToggleControl } from '@wordpress/components';
|
|
|
|
import PropTypes from 'prop-types';
|
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 EditorContainerBlock from '../editor-container-block.js';
|
|
|
|
import NoReviewsPlaceholder from './no-reviews-placeholder.js';
|
2019-09-05 15:09:31 +00:00
|
|
|
import {
|
|
|
|
getSharedReviewContentControls,
|
|
|
|
getSharedReviewListControls,
|
|
|
|
} from '../edit-utils.js';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to handle edit mode of "All Reviews".
|
2020-09-20 23:54:08 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Incoming props for the component.
|
|
|
|
* @param {Object} props.attributes Incoming block attributes.
|
|
|
|
* @param {function(any):any} props.setAttributes Setter for block attributes.
|
2019-08-23 14:48:48 +00:00
|
|
|
*/
|
|
|
|
const AllReviewsEditor = ( { attributes, setAttributes } ) => {
|
|
|
|
const getInspectorControls = () => {
|
|
|
|
return (
|
|
|
|
<InspectorControls key="inspector">
|
2019-09-09 10:52:48 +00:00
|
|
|
<PanelBody
|
|
|
|
title={ __( 'Content', 'woo-gutenberg-products-block' ) }
|
|
|
|
>
|
2019-08-23 14:48:48 +00:00
|
|
|
<ToggleControl
|
2019-09-09 10:52:48 +00:00
|
|
|
label={ __(
|
|
|
|
'Product name',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-08-23 14:48:48 +00:00
|
|
|
checked={ attributes.showProductName }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showProductName: ! attributes.showProductName,
|
|
|
|
} )
|
|
|
|
}
|
2019-08-23 14:48:48 +00:00
|
|
|
/>
|
2019-09-09 10:52:48 +00:00
|
|
|
{ getSharedReviewContentControls(
|
|
|
|
attributes,
|
|
|
|
setAttributes
|
|
|
|
) }
|
2019-08-23 14:48:48 +00:00
|
|
|
</PanelBody>
|
2019-09-05 15:09:31 +00:00
|
|
|
<PanelBody
|
2019-09-09 10:52:48 +00:00
|
|
|
title={ __(
|
|
|
|
'List Settings',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-09-05 15:09:31 +00:00
|
|
|
>
|
2019-08-23 14:48:48 +00:00
|
|
|
{ getSharedReviewListControls( attributes, setAttributes ) }
|
|
|
|
</PanelBody>
|
|
|
|
</InspectorControls>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-12-14 11:54:34 +00:00
|
|
|
<>
|
2019-08-23 14:48:48 +00:00
|
|
|
{ getInspectorControls() }
|
|
|
|
<EditorContainerBlock
|
|
|
|
attributes={ attributes }
|
2020-01-31 18:20:33 +00:00
|
|
|
icon={
|
|
|
|
<Icon
|
2022-02-01 16:54:38 +00:00
|
|
|
icon={ postComments }
|
2020-01-31 18:20:33 +00:00
|
|
|
className="block-editor-block-icon"
|
|
|
|
/>
|
|
|
|
}
|
2019-08-23 14:48:48 +00:00
|
|
|
name={ __( 'All Reviews', 'woo-gutenberg-products-block' ) }
|
|
|
|
noReviewsPlaceholder={ NoReviewsPlaceholder }
|
|
|
|
/>
|
2020-12-14 11:54:34 +00:00
|
|
|
</>
|
2019-08-23 14:48:48 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AllReviewsEditor.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 AllReviewsEditor;
|