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';
|
2019-08-27 15:25:32 +00:00
|
|
|
import { ENABLE_REVIEW_RATING } from '@woocommerce/block-settings';
|
2019-08-23 14:48:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-10-06 12:36:15 +00:00
|
|
|
import ErrorPlaceholder from '@woocommerce/block-components/error-placeholder';
|
|
|
|
import LoadMoreButton from '@woocommerce/base-components/load-more-button';
|
|
|
|
import ReviewList from '@woocommerce/base-components/review-list';
|
|
|
|
import ReviewOrderSelect from '@woocommerce/base-components/review-order-select';
|
|
|
|
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
|
|
|
|
|
|
|
if ( 0 === reviews.length && ! isLoading ) {
|
|
|
|
return <NoReviewsPlaceholder attributes={ attributes } />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Disabled>
|
2019-09-05 15:09:31 +00:00
|
|
|
{ attributes.showOrderby && ENABLE_REVIEW_RATING && (
|
|
|
|
<ReviewOrderSelect readOnly value={ attributes.orderby } />
|
2019-08-23 14:48:48 +00:00
|
|
|
) }
|
2019-09-05 15:09:31 +00:00
|
|
|
<ReviewList attributes={ attributes } reviews={ reviews } />
|
|
|
|
{ attributes.showLoadMore && totalReviews > reviews.length && (
|
2019-08-23 14:48:48 +00:00
|
|
|
<LoadMoreButton
|
2019-09-05 15:09:31 +00:00
|
|
|
screenReaderLabel={ __(
|
|
|
|
'Load more reviews',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-08-23 14:48:48 +00:00
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</Disabled>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 10:24:50 +00:00
|
|
|
export default withReviews( EditorBlock );
|