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

Reviews by category block #804

Merged
merged 81 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
e62f8f2
Create Reviews by Product block
Aljullu Jun 27, 2019
ae1065a
Honor Content settings
Aljullu Jun 28, 2019
f1ca809
Fix wrong className
Aljullu Jun 28, 2019
7b4e9cd
Load new wc-packages file
Aljullu Jun 28, 2019
0cb8dab
Add reviews-by-product JS files to webpack config
Aljullu Jun 28, 2019
036b726
Merge branch 'master' into add/588-reviews-by-product-block
Aljullu Jul 1, 2019
48a5ac3
Cleanup
Aljullu Jul 1, 2019
d2300e5
Remove error messages
Aljullu Jul 1, 2019
a042220
Add Reviews by Product icon
Aljullu Jul 2, 2019
b71af2e
Update sort options
Aljullu Jul 2, 2019
5df7338
Allow additional CSS classes attribute
Aljullu Jul 2, 2019
9634bf6
Refactor block styles
Aljullu Jul 3, 2019
130eb81
Fix wrong default for reviews_orderby
Aljullu Jul 4, 2019
4442afd
Don't enforce CSS chunks
Aljullu Jul 4, 2019
e5d9ce5
Add reviews count to Reviews by Product controls (#671)
Aljullu Jul 5, 2019
c8730f5
Add label to Reviews by Product controls count (#677)
Aljullu Jul 5, 2019
88887fd
Review ordering and placeholders (#688)
mikejolley Jul 5, 2019
3da6b9b
Fix some linting errors and warnings (#693)
Aljullu Jul 5, 2019
b90f3fc
Create Reviews by Product block placeholder (#691)
Aljullu Jul 8, 2019
7b796ca
Rename 'Reviewer Picture' with 'Avatar' (#702)
Aljullu Jul 9, 2019
5128cf0
Merge branch 'master' into add/588-reviews-by-product-block
mikejolley Jul 9, 2019
470e535
Lint errors
mikejolley Jul 9, 2019
6325809
Replace stringify query with addQueryArgs (#707)
Aljullu Jul 10, 2019
9227f0c
Add reviews endpoint (#705)
mikejolley Jul 11, 2019
1270073
Prevent state updates on unmounted components (#715)
Aljullu Jul 11, 2019
359cef2
Add Order by and Load more controls in Reviews by Product frontend (#…
Aljullu Jul 11, 2019
b38f3e7
Export IconReviewsByProduct (#721)
Aljullu Jul 11, 2019
1eae7ea
Fix Reviews by Product layout in IE11 (#723)
Aljullu Jul 11, 2019
56d9704
Set minimum to per page input field (#731)
Aljullu Jul 12, 2019
8200d22
Hide avatars in Reviews by Products if 'show_avatars' settings is fal…
Aljullu Jul 12, 2019
a1d6639
Blocks API - Reviews endpoint with rating sort and category filtering…
mikejolley Jul 15, 2019
86cff9c
Reviews by Product: add placeholders when loading reviews (#732)
Aljullu Jul 19, 2019
113b0db
Add placeholder animation (#733)
Aljullu Jul 22, 2019
eed01f4
Hook up Reviews by Product 'Order by' with endpoint (#736)
Aljullu Jul 24, 2019
2931845
Update from master
mikejolley Jul 24, 2019
fcd4509
Reviews by Product cleanup (#773)
Aljullu Jul 29, 2019
c3925ae
Merge branch 'master' into add/588-reviews-by-product-block
Aljullu Jul 30, 2019
724a33e
Merge branch 'master' into add/588-reviews-by-product-block
Aljullu Jul 30, 2019
c19a38b
Fix wrong method name
Aljullu Jul 31, 2019
73d9c28
Reduce the number of dependencies used in Reviews by Product (#774)
Aljullu Jul 31, 2019
a480ff4
Add formatted_date_created item schema (#788)
Aljullu Aug 1, 2019
bf553dc
Merge branch 'master' into add/588-reviews-by-product-block
Aljullu Aug 2, 2019
ec5fbdc
Update from master
mikejolley Aug 5, 2019
73bdb5f
Inital block setup
mikejolley Aug 5, 2019
e5cf69e
Fix import of WithComponentID
mikejolley Aug 5, 2019
a22f505
Merge branch 'add/588-reviews-by-product-block' into add/reviews-by-c…
mikejolley Aug 5, 2019
61347a5
Render the category reviews
mikejolley Aug 5, 2019
654d1f8
Add new settings to Reviews by Product block (#787)
Aljullu Aug 6, 2019
56c5812
Reviews by Product: prevent importing all HOCs and import only withCo…
Aljullu Aug 7, 2019
78adef1
Reviews by product: Update review styling and content (#806)
mikejolley Aug 8, 2019
9d8f74c
Add missing parameter doc in renderReview (#820)
Aljullu Aug 8, 2019
12b81b2
Fix Reviews by Product order by select not honoring default setting (…
Aljullu Aug 8, 2019
995ed9f
Merge branch 'master' into add/588-reviews-by-product-block
Aljullu Aug 8, 2019
4afb90e
Read more component - change how clamped content is shown (#821)
mikejolley Aug 12, 2019
f73f21b
Use withProduct HOC in ReviewsByProductEditor (#828)
Aljullu Aug 12, 2019
043fa6f
Reviews: only save wrapper element to post (#830)
Aljullu Aug 12, 2019
32a4d1b
Merge branch 'master' into add/588-reviews-by-product-block
mikejolley Aug 12, 2019
6a3e6cf
Merge branch 'add/588-reviews-by-product-block' into add/reviews-by-c…
mikejolley Aug 12, 2019
aee6f30
Update based on product reviews
mikejolley Aug 12, 2019
f8d14c2
Merge branch 'master' into add/reviews-by-category-block-589
mikejolley Aug 15, 2019
faf8a53
Cleanup after master merge
mikejolley Aug 15, 2019
f12b96c
Implement content hiding and placeholder states for reviews blocks
mikejolley Aug 15, 2019
62e87f2
Output product names and adjust css
mikejolley Aug 16, 2019
27c7f6f
Review permalink
mikejolley Aug 16, 2019
052865c
Merge branch 'master' into add/reviews-by-category-block-589
mikejolley Aug 16, 2019
037308f
Remove old read-more component which was moved
mikejolley Aug 16, 2019
83ab82d
showProductName is already part of passed attributes
mikejolley Aug 19, 2019
13636a9
CSS tweaks for missing elements
mikejolley Aug 19, 2019
e88b231
Move dir
mikejolley Aug 19, 2019
0c98aa0
Merge branch 'master' into add/reviews-by-category-block-589
mikejolley Aug 19, 2019
6eedebd
Move product reviews block
mikejolley Aug 19, 2019
598d75a
Move shared uitils
mikejolley Aug 19, 2019
e133619
update paths
mikejolley Aug 19, 2019
0398823
frontend paths
mikejolley Aug 19, 2019
9f9d90f
Update paths
mikejolley Aug 19, 2019
2b441db
shared attributes
mikejolley Aug 19, 2019
65d2377
switch to constants
mikejolley Aug 19, 2019
88cdac6
Shared review block code
mikejolley Aug 19, 2019
c5df56a
Replace constants
mikejolley Aug 19, 2019
b3e621b
Fix hidden content bug
mikejolley Aug 19, 2019
74de352
star alignment
mikejolley Aug 19, 2019
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
72 changes: 51 additions & 21 deletions assets/js/base/components/review-list-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,71 @@ function getReviewContent( review ) {
);
}

const ReviewListItem = ( { attributes, review = {} } ) => {
const { imageType, showReviewDate, showReviewerName, showReviewImage, showReviewRating: showReviewRatingAttr } = attributes;
const { date_created: dateCreated, formatted_date_created: formattedDateCreated, rating, reviewer = '' } = review;
function getReviewProductName( review ) {
return (
<div className="wc-block-review-list-item__product">
<a href={ review.product_permalink }>
{ review.product_name }
</a>
</div>
);
}

function getReviewerName( review ) {
const { reviewer = '' } = review;
return (
<div className="wc-block-review-list-item__author">
{ reviewer }
</div>
);
}

function getReviewDate( review ) {
const { date_created: dateCreated, formatted_date_created: formattedDateCreated } = review;
return (
<time className="wc-block-review-list-item__published-date" dateTime={ dateCreated }>
{ formattedDateCreated }
</time>
);
}

function getReviewRating( review ) {
const { rating } = review;
const starStyle = {
width: ( rating / 5 * 100 ) + '%', /* stylelint-disable-line */
};
return (
<div className="wc-block-review-list-item__rating">
<div className="wc-block-review-list-item__rating__stars" role="img">
<span style={ starStyle }>{ sprintf( __( 'Rated %d out of 5', 'woo-gutenberg-products-block' ), rating ) }</span>
</div>
</div>
);
}

const ReviewListItem = ( { attributes, review = {}, showProductName } ) => {
const { imageType, showReviewDate, showReviewerName, showReviewImage, showReviewRating: showReviewRatingAttr, showReviewContent } = attributes;
const { rating } = review;
const isLoading = ! Object.keys( review ).length > 0;
const showReviewRating = Number.isFinite( rating ) && showReviewRatingAttr;
const classes = getReviewClasses( isLoading );
const starStyle = {
width: ( rating / 5 * 100 ) + '%',
};

return (
<li className={ classes } aria-hidden={ isLoading }>
{ ( showReviewDate || showReviewerName || showReviewImage || showReviewRating ) && (
<div className="wc-block-review-list-item__info">
{ showReviewImage && getReviewImage( review, imageType, isLoading ) }
{ ( showReviewerName || showReviewRating || showReviewDate ) && (
{ ( showProductName || showReviewerName || showReviewRating || showReviewDate ) && (
<div className="wc-block-review-list-item__meta">
{ showReviewerName && (
<strong className="wc-block-review-list-item__author">{ reviewer }</strong>
) }
{ showReviewRating && (
<div className="wc-block-review-list-item__rating">
<div className="wc-block-review-list-item__rating__stars" role="img">
<span style={ starStyle }>{ sprintf( __( 'Rated %d out of 5', 'woo-gutenberg-products-block' ), rating ) }</span>
</div>
</div>
) }
{ showReviewDate && (
<time className="wc-block-review-list-item__published-date" dateTime={ dateCreated }>{ formattedDateCreated }</time>
) }
{ showReviewRating && getReviewRating( review ) }
{ showProductName && getReviewProductName( review ) }
{ showReviewerName && getReviewerName( review ) }
{ showReviewDate && getReviewDate( review ) }
mikejolley marked this conversation as resolved.
Show resolved Hide resolved
</div>
) }
</div>
) }
{ getReviewContent( review ) }
{ showReviewContent && getReviewContent( review ) }
</li>
);
};
Expand Down
59 changes: 49 additions & 10 deletions assets/js/base/components/review-list-item/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
width: 80px;
}

.wc-block-review-list-item__product {
display: none;
}

.wc-block-review-list-item__rating {
.wc-block-review-list-item__rating__stars > span {
display: none;
Expand All @@ -32,6 +36,7 @@
}
}

.editor-styles-wrapper .wc-block-review-list-item__item,
.wc-block-review-list-item__item {
margin: 0 0 $gap-large * 2;
list-style: none;
Expand Down Expand Up @@ -91,15 +96,56 @@
}
}

.wc-block-review-list-item__meta {
display: flex;
align-items: center;
flex-flow: row wrap;

&::after {
// Force wrap after star rating.
order: 3;
content: "";
flex-basis: 100%;
}
}

.wc-block-review-list-item__product {
display: block;
font-weight: bold;
order: 1;
}

.wc-block-review-list-item__author {
display: block;
font-weight: bold;
order: 1;
}

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

&::after {
content: "";
display: inline-block;
margin-left: $gap/2;
margin-right: $gap/2;
border-right: 1px solid #ddd;
height: 1em;
vertical-align: middle;
}
}

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

.wc-block-review-list-item__rating {
display: inline-block;
vertical-align: middle;
margin-right: $gap;
margin-left: $gap;
height: 1em;
order: 2;

> .wc-block-review-list-item__rating__stars {
display: inline-block;
Expand Down Expand Up @@ -140,10 +186,3 @@
color: #e6a237;
}
}

.wc-block-review-list-item__published-date {
display: inline-block;
vertical-align: middle;
color: #808080;
font-size: 0.875em;
}
5 changes: 3 additions & 2 deletions assets/js/base/components/review-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
import ReviewListItem from '../review-list-item';
import './style.scss';

const ReviewList = ( { attributes, componentId, reviews } ) => {
const ReviewList = ( { attributes, componentId, reviews, showProductName } ) => {
mikejolley marked this conversation as resolved.
Show resolved Hide resolved
const showReviewImage = ( wc_product_block_data.showAvatars || attributes.imageType === 'product' ) && attributes.showReviewImage;
const showReviewRating = wc_product_block_data.enableReviewRating && attributes.showReviewRating;
const attrs = {
Expand All @@ -28,7 +28,7 @@ const ReviewList = ( { attributes, componentId, reviews } ) => {
<ReviewListItem attributes={ attrs } />
) : (
reviews.map( ( review, i ) => (
<ReviewListItem key={ review.id || i } attributes={ attrs } review={ review } />
<ReviewListItem key={ review.id || i } attributes={ attrs } review={ review } showProductName={ showProductName } />
) )
)
}
Expand All @@ -40,6 +40,7 @@ ReviewList.propTypes = {
attributes: PropTypes.object.isRequired,
componentId: PropTypes.number.isRequired,
reviews: PropTypes.array.isRequired,
showProductName: PropTypes.bool,
};

export default ReviewList;
Loading