2019-08-23 14:48:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
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';
|
2023-11-27 11:08:17 +00:00
|
|
|
import { EditorContainerBlockProps } from '@woocommerce/blocks/reviews/types';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2024-02-20 13:58:52 +00:00
|
|
|
import EditorBlock from './editor-block';
|
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,
|
2023-11-27 11:08:17 +00:00
|
|
|
}: EditorContainerBlockProps ) => {
|
2021-09-16 09:32:48 +00:00
|
|
|
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.',
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2019-09-05 15:09:31 +00:00
|
|
|
) }
|
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 }
|
2023-11-27 11:08:17 +00:00
|
|
|
delayFunction={ ( callback: () => void ) =>
|
|
|
|
debounce( callback, 400 )
|
|
|
|
}
|
2021-09-16 09:32:48 +00:00
|
|
|
noReviewsPlaceholder={ noReviewsPlaceholder }
|
|
|
|
orderby={ orderby }
|
|
|
|
order={ order }
|
|
|
|
productId={ productId }
|
|
|
|
reviewsToDisplay={ reviewsOnPageLoad }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
export default EditorContainerBlock;
|