2019-08-23 14:48:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Disabled } from '@wordpress/components';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2020-09-02 08:21:46 +00:00
|
|
|
import ErrorPlaceholder from '@woocommerce/editor-components/error-placeholder';
|
2019-10-06 12:36:15 +00:00
|
|
|
import LoadMoreButton from '@woocommerce/base-components/load-more-button';
|
2020-03-30 13:04:27 +00:00
|
|
|
import {
|
|
|
|
ReviewList,
|
|
|
|
ReviewSortSelect,
|
|
|
|
} from '@woocommerce/base-components/reviews';
|
2019-10-06 12:36:15 +00:00
|
|
|
import withReviews from '@woocommerce/base-hocs/with-reviews';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Block rendered in the editor.
|
|
|
|
*/
|
|
|
|
class EditorBlock extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* The attributes for this block.
|
|
|
|
*/
|
|
|
|
attributes: PropTypes.object.isRequired,
|
|
|
|
// from withReviews
|
|
|
|
reviews: PropTypes.array,
|
|
|
|
totalReviews: PropTypes.number,
|
2019-09-05 15:09:31 +00:00
|
|
|
};
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
render() {
|
2019-09-05 15:09:31 +00:00
|
|
|
const {
|
|
|
|
attributes,
|
|
|
|
error,
|
|
|
|
isLoading,
|
|
|
|
noReviewsPlaceholder: NoReviewsPlaceholder,
|
|
|
|
reviews,
|
|
|
|
totalReviews,
|
|
|
|
} = this.props;
|
2019-08-27 09:38:41 +00:00
|
|
|
|
|
|
|
if ( error ) {
|
|
|
|
return (
|
2019-09-09 12:04:54 +00:00
|
|
|
<ErrorPlaceholder
|
2019-08-27 09:38:41 +00:00
|
|
|
className="wc-block-featured-product-error"
|
|
|
|
error={ error }
|
|
|
|
isLoading={ isLoading }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2019-08-23 14:48:48 +00:00
|
|
|
|
2019-11-07 14:45:45 +00:00
|
|
|
if ( reviews.length === 0 && ! isLoading ) {
|
2019-08-23 14:48:48 +00:00
|
|
|
return <NoReviewsPlaceholder attributes={ attributes } />;
|
|
|
|
}
|
|
|
|
|
2021-04-22 11:37:27 +00:00
|
|
|
const reviewRatingsEnabled = getSetting( 'reviewRatingsEnabled', true );
|
|
|
|
|
2019-08-23 14:48:48 +00:00
|
|
|
return (
|
2019-11-21 08:08:47 +00:00
|
|
|
<Disabled>
|
2021-04-22 11:37:27 +00:00
|
|
|
{ attributes.showOrderby && reviewRatingsEnabled && (
|
2019-11-21 08:08:47 +00:00
|
|
|
<ReviewSortSelect readOnly value={ attributes.orderby } />
|
|
|
|
) }
|
|
|
|
<ReviewList attributes={ attributes } reviews={ reviews } />
|
|
|
|
{ attributes.showLoadMore && totalReviews > reviews.length && (
|
|
|
|
<LoadMoreButton
|
|
|
|
screenReaderLabel={ __(
|
|
|
|
'Load more reviews',
|
|
|
|
'woo-gutenberg-products-block'
|
2019-09-05 15:09:31 +00:00
|
|
|
) }
|
2019-11-21 08:08:47 +00:00
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</Disabled>
|
2019-08-23 14:48:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 10:24:50 +00:00
|
|
|
export default withReviews( EditorBlock );
|