2019-08-23 14:48:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import PropTypes from 'prop-types';
|
2023-04-28 10:29:45 +00:00
|
|
|
import { debounce } from '@woocommerce/base-utils';
|
2019-08-23 14:48:48 +00:00
|
|
|
import { Placeholder } from '@wordpress/components';
|
2021-09-16 09:32:48 +00:00
|
|
|
import { useBlockProps } from '@wordpress/block-editor';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import EditorBlock from './editor-block.js';
|
2019-10-28 13:53:09 +00:00
|
|
|
import { getBlockClassName, getSortArgs } from './utils.js';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
2021-09-16 09:32:48 +00:00
|
|
|
const EditorContainerBlock = ( {
|
|
|
|
attributes,
|
|
|
|
icon,
|
|
|
|
name,
|
|
|
|
noReviewsPlaceholder,
|
|
|
|
} ) => {
|
|
|
|
const {
|
|
|
|
categoryIds,
|
|
|
|
productId,
|
|
|
|
reviewsOnPageLoad,
|
|
|
|
showProductName,
|
|
|
|
showReviewDate,
|
|
|
|
showReviewerName,
|
|
|
|
showReviewContent,
|
|
|
|
showReviewImage,
|
|
|
|
showReviewRating,
|
|
|
|
} = attributes;
|
|
|
|
const { order, orderby } = getSortArgs( attributes.orderby );
|
|
|
|
const isAllContentHidden =
|
|
|
|
! showReviewContent &&
|
|
|
|
! showReviewRating &&
|
|
|
|
! showReviewDate &&
|
|
|
|
! showReviewerName &&
|
|
|
|
! showReviewImage &&
|
|
|
|
! showProductName;
|
|
|
|
|
|
|
|
const blockProps = useBlockProps( {
|
|
|
|
className: getBlockClassName( attributes ),
|
|
|
|
} );
|
2019-08-23 14:48:48 +00:00
|
|
|
|
2021-09-16 09:32:48 +00:00
|
|
|
if ( isAllContentHidden ) {
|
2019-08-23 14:48:48 +00:00
|
|
|
return (
|
2019-09-05 15:09:31 +00:00
|
|
|
<Placeholder icon={ icon } label={ name }>
|
|
|
|
{ __(
|
|
|
|
'The content for this block is hidden due to block settings.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-08-23 14:48:48 +00:00
|
|
|
</Placeholder>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-16 09:32:48 +00:00
|
|
|
return (
|
|
|
|
<div { ...blockProps }>
|
|
|
|
<EditorBlock
|
|
|
|
attributes={ attributes }
|
|
|
|
categoryIds={ categoryIds }
|
|
|
|
delayFunction={ ( callback ) => debounce( callback, 400 ) }
|
|
|
|
noReviewsPlaceholder={ noReviewsPlaceholder }
|
|
|
|
orderby={ orderby }
|
|
|
|
order={ order }
|
|
|
|
productId={ productId }
|
|
|
|
reviewsToDisplay={ reviewsOnPageLoad }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
EditorContainerBlock.propTypes = {
|
|
|
|
attributes: PropTypes.object.isRequired,
|
|
|
|
icon: PropTypes.node.isRequired,
|
|
|
|
name: PropTypes.string.isRequired,
|
2023-06-19 07:07:57 +00:00
|
|
|
noReviewsPlaceholder: PropTypes.elementType.isRequired,
|
2019-08-23 14:48:48 +00:00
|
|
|
className: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditorContainerBlock;
|