Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Update Reviews blocks so they use block styles #4323

Merged
merged 3 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions assets/js/base/components/reviews/review-list-item/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,28 @@

.wc-block-components-review-list-item__product + .wc-block-components-review-list-item__author {
font-weight: normal;
color: #808080;
order: 4;
}

.wc-block-components-review-list-item__published-date {
color: #808080;
order: 5;
}

.wc-block-components-review-list-item__author + .wc-block-components-review-list-item__published-date {
.wc-block-components-review-list-item__product + .wc-block-components-review-list-item__author + .wc-block-components-review-list-item__published-date {
padding-left: $gap/2;
position: relative;

&::before {
content: "";
display: inline-block;
margin-right: $gap*0.5;
border-right: 1px solid #ddd;
margin-left: -$gap*0.5;
border-right: 1px solid currentColor;
opacity: 0.5;
height: 1em;
vertical-align: middle;
position: absolute;
top: calc(50% + 0.1em);
transform: translateY(-50%);
}
}

Expand All @@ -166,16 +171,15 @@

> .wc-block-components-review-list-item__rating__stars {
@include font-size(regular);
display: inline-block;
display: block;
top: 0;
overflow: hidden;
position: relative;
height: 1.618em;
line-height: 1.618;
height: 1em;
line-height: 1;
width: 5.3em;
font-family: star; /* stylelint-disable-line */
font-weight: 400;
vertical-align: top;
}

> .wc-block-components-review-list-item__rating__stars::before {
Expand Down Expand Up @@ -204,3 +208,7 @@
color: #e6a237;
}
}

.wc-block-components-review-list-item__text p {
font-size: inherit;
}
4 changes: 2 additions & 2 deletions assets/js/base/components/reviews/review-list/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wc-block-components-review-list,
.editor-styles .wc-block-components-review-list {
// Duplicate class for specificity in the editor.
.wc-block-components-review-list.wc-block-components-review-list {
margin: 0;
}
1 change: 1 addition & 0 deletions assets/js/base/components/sort-select/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
}

.wc-block-components-sort-select__select {
font-size: inherit;
width: max-content;
}
22 changes: 9 additions & 13 deletions assets/js/blocks/reviews/all-reviews/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Icon, discussion } from '@woocommerce/icons';
* Internal dependencies
*/
import '../editor.scss';
import Editor from './edit';
import edit from './edit';
import sharedAttributes from '../attributes';
import save from '../save.js';
import { example } from '../example';
Expand All @@ -19,6 +19,7 @@ import { example } from '../example';
* This block lists all product reviews.
*/
registerBlockType( 'woocommerce/all-reviews', {
apiVersion: 2,
title: __( 'All Reviews', 'woo-gutenberg-products-block' ),
icon: {
src: <Icon srcElement={ discussion } />,
Expand All @@ -32,6 +33,12 @@ registerBlockType( 'woocommerce/all-reviews', {
),
supports: {
html: false,
color: {
background: false,
},
typography: {
fontSize: true,
},
},
example: {
...example,
Expand Down Expand Up @@ -72,17 +79,6 @@ registerBlockType( 'woocommerce/all-reviews', {
],
},

/**
* Renders and manages the block.
*
* @param {Object} props Props to pass to block.
*/
edit( props ) {
return <Editor { ...props } />;
},

/**
* Save the props to post content.
*/
edit,
save,
} );
97 changes: 47 additions & 50 deletions assets/js/blocks/reviews/editor-container-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,48 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from 'react';
import PropTypes from 'prop-types';
import { debounce } from 'lodash';
import { Placeholder } from '@wordpress/components';
import { useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import EditorBlock from './editor-block.js';
import { getBlockClassName, getSortArgs } from './utils.js';

/**
* Container of the block rendered in the editor.
*/
class EditorContainerBlock extends Component {
renderHiddenContentPlaceholder() {
const { icon, name } = this.props;
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 ),
} );

if ( isAllContentHidden ) {
return (
<Placeholder icon={ icon } label={ name }>
{ __(
Expand All @@ -30,54 +54,27 @@ class EditorContainerBlock extends Component {
);
}

render() {
const { attributes, noReviewsPlaceholder } = this.props;
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;

if ( isAllContentHidden ) {
return this.renderHiddenContentPlaceholder();
}

return (
<div className={ getBlockClassName( attributes ) }>
<EditorBlock
attributes={ attributes }
categoryIds={ categoryIds }
delayFunction={ ( callback ) => debounce( callback, 400 ) }
noReviewsPlaceholder={ noReviewsPlaceholder }
orderby={ orderby }
order={ order }
productId={ productId }
reviewsToDisplay={ reviewsOnPageLoad }
/>
</div>
);
}
}
return (
<div { ...blockProps }>
<EditorBlock
attributes={ attributes }
categoryIds={ categoryIds }
delayFunction={ ( callback ) => debounce( callback, 400 ) }
noReviewsPlaceholder={ noReviewsPlaceholder }
orderby={ orderby }
order={ order }
productId={ productId }
reviewsToDisplay={ reviewsOnPageLoad }
/>
</div>
);
};

EditorContainerBlock.propTypes = {
attributes: PropTypes.object.isRequired,
icon: PropTypes.node.isRequired,
name: PropTypes.string.isRequired,
noReviewsPlaceholder: PropTypes.func.isRequired,
noReviewsPlaceholder: PropTypes.element.isRequired,
className: PropTypes.string,
};

Expand Down
7 changes: 7 additions & 0 deletions assets/js/blocks/reviews/reviews-by-category/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { example } from '../example';
* Register and run the "Reviews by category" block.
*/
registerBlockType( 'woocommerce/reviews-by-category', {
apiVersion: 2,
title: __( 'Reviews by Category', 'woo-gutenberg-products-block' ),
icon: {
src: <Icon srcElement={ review } />,
Expand All @@ -30,6 +31,12 @@ registerBlockType( 'woocommerce/reviews-by-category', {
),
supports: {
html: false,
color: {
background: false,
},
typography: {
fontSize: true,
},
},
example: {
...example,
Expand Down
7 changes: 7 additions & 0 deletions assets/js/blocks/reviews/reviews-by-product/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { example } from '../example';
* Register and run the "Reviews by Product" block.
*/
registerBlockType( 'woocommerce/reviews-by-product', {
apiVersion: 2,
title: __( 'Reviews by Product', 'woo-gutenberg-products-block' ),
icon: {
src: <Icon srcElement={ comment } />,
Expand All @@ -30,6 +31,12 @@ registerBlockType( 'woocommerce/reviews-by-product', {
),
supports: {
html: false,
color: {
background: false,
},
typography: {
fontSize: true,
},
},
example: {
...example,
Expand Down
9 changes: 8 additions & 1 deletion assets/js/blocks/reviews/save.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
Expand All @@ -7,7 +12,9 @@ import { getBlockClassName, getDataAttrs } from './utils.js';
export default ( { attributes } ) => {
return (
<div
className={ getBlockClassName( attributes ) }
{ ...useBlockProps.save( {
className: getBlockClassName( attributes ),
} ) }
{ ...getDataAttrs( attributes ) }
/>
);
Expand Down