/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { Disabled } from '@wordpress/components';
import { getSetting } from '@woocommerce/settings';
import ErrorPlaceholder, {
ErrorObject,
} from '@woocommerce/editor-components/error-placeholder';
import LoadMoreButton from '@woocommerce/base-components/load-more-button';
import {
ReviewList,
ReviewSortSelect,
} from '@woocommerce/base-components/reviews';
import type { Review } from '@woocommerce/base-components/reviews/types';
import withReviews from '@woocommerce/base-hocs/with-reviews';
/**
* Internal dependencies
*/
import { ReviewBlockAttributes } from './attributes';
interface EditorBlockProps {
attributes: ReviewBlockAttributes;
reviews: Review[];
totalReviews: number;
error?: ErrorObject;
isLoading: boolean;
noReviewsPlaceholder: React.ComponentType< {
attributes: EditorBlockProps[ 'attributes' ];
} >;
}
/**
* Block rendered in the editor.
*/
class EditorBlock extends Component< EditorBlockProps > {
render() {
const {
attributes,
error,
isLoading,
noReviewsPlaceholder: NoReviewsPlaceholder,
reviews,
totalReviews,
} = this.props;
if ( error ) {
return (
);
}
if ( reviews.length === 0 && ! isLoading ) {
return ;
}
const reviewRatingsEnabled = getSetting( 'reviewRatingsEnabled', true );
return (
{ attributes.showOrderby && reviewRatingsEnabled && (
null }
/>
) }
{ attributes.showLoadMore && totalReviews > reviews.length && (
null }
/>
) }
);
}
}
export default withReviews( EditorBlock );