This repository was archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
P1 345 woo shopping data in google preview #1118
Merged
JoseeWouters
merged 25 commits into
develop
from
P1-345-Woo-shopping-data-in-google-preview
Apr 12, 2021
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1a1cf3d
introduce StarRating component
marijnyoast 7109bf8
Introduce ProductData components
marijnyoast bb1398e
pass shoppingData to Preview
marijnyoast 96d74c3
update export
marijnyoast b279617
fix typo
marijnyoast 7046bee
add translations
marijnyoast b01ce11
remove non-functioning stylesheet
marijnyoast 9eacdd4
Restructure and styling
marijnyoast 0b14ad5
fix props existency
marijnyoast 6029dc2
update snapshot
marijnyoast b9ab211
Update snaps
maartenleenders b676e93
Merge branch 'develop' into P1-345-Woo-shopping-data-in-google-preview
marijnyoast cfbb1b9
remove faulty snapshot tests
marijnyoast d678bad
Merge branch 'P1-345-Woo-shopping-data-in-google-preview' of https://…
marijnyoast 1efba0e
CS fixes in test
marijnyoast 7cf656e
remove even more snapshot testing
marijnyoast 505e6c8
remove obsolete snapshots
marijnyoast fb4ca07
limit rating input between 0 and 5
marijnyoast 987d696
update translateability and replace ternary's
marijnyoast 74e8ba7
define PropType shape
marijnyoast e487a15
simplify existence check
marijnyoast bc4cba5
fix typo
marijnyoast c98f93e
Apply suggestions from code review
marijnyoast f904659
fix object empty check
marijnyoast 0d8b89d
Merge branch 'P1-345-Woo-shopping-data-in-google-preview' of https://…
marijnyoast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
/** | ||
* Renders StarRating component. | ||
* | ||
* @param {Object} props The props. | ||
* | ||
* @returns {React.Component} The StarRating Component displays a number between 0 and 5 as (partly) colored stars. | ||
*/ | ||
function StarRating( props ) { | ||
let rating = props.rating; | ||
|
||
// As we have 5 stars, the rating should be between 0 and 5. | ||
if ( rating < 0 ) { | ||
rating = 0; | ||
} | ||
|
||
if ( rating > 5 ) { | ||
rating = 5; | ||
} | ||
|
||
const ratingPercentage = rating * 20; | ||
|
||
return ( | ||
<div | ||
aria-hidden="true" | ||
className="yoast-star-rating" | ||
> | ||
<span className="yoast-star-rating__placeholder" role="img"> | ||
<span className="yoast-star-rating__fill" style={ { width: ratingPercentage + "%" } } /> | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default StarRating; | ||
|
||
StarRating.propTypes = { | ||
rating: PropTypes.number.isRequired, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import "./star-rating.css"; | ||
|
||
export { default as StarRating } from "./StarRating.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.yoast-star-rating { | ||
width: 65px; | ||
height: 12px; | ||
display: inline-block; | ||
} | ||
|
||
.yoast-star-rating span { | ||
height: 100%; | ||
width: 100%; | ||
background-size: 13px 12px; | ||
background-repeat: repeat-x; | ||
} | ||
|
||
.yoast-star-rating__placeholder { | ||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAmCAQAAAAYCMGrAAAA+klEQVR4AcWV4cbtMBBFF0MIVUopoVSrhDDv/3gf/RFRpzdNOty1HiBO99mzeYWgCMZMKCPGrCgrxiSUhCkDeukxJKCXAUMiehkxw6FZhxEzmp0x4kCzByYISqlYdal0supS6WrVpdLEK0YSamJiJOPY0c/uOG4s6CcXfuKJaJcRzyNCQJsNiF1sRTR1hP11NNJ8RCrONOPRf+r7J+TZgQ5CNfMOYvW/2YxDqzqA/57+gVY9eiakrnyZEGXDsaE3p/4JScwPX3rtnZATDxnPWT7X16XAHaH8HWNrlxJD9TyGti5tCM84zpZe+RxNjeX9tZqLaGoMxN/P/wHP5Vw+8ZxnEQAAAABJRU5ErkJggg==); | ||
display: inline-block; | ||
overflow: hidden; | ||
position: relative; | ||
} | ||
|
||
.yoast-star-rating__fill { | ||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAmBAMAAABALxQTAAAAFVBMVEVMaXH4twP4twP4twP4twP4twP4twP7w8S/AAAAB3RSTlMAFv5uPpvQloUsTQAAAMFJREFUeAGE0TEOgzAMQFEXoDNiYC6/wFxxAsTADDkB5f6HqNRENXUi8TYiRfnY8lNXkjBOkuBWSeAhsYJOYiW9xO4MEqshkTbCSyIH7GLdgFasHHgmwkikZQD6OROZRG4Hxju8o/TNhbNhCqkOxaZDVKdxNnq/EjUS/A2o0PuXpyVeb9bjDWY9QSWXDQfBbtbjtWY9bM4sqfx+5yYt8wNcAFEzrGGkk5668KsFrKewPtQ3aFqh8WOnYZ+lIBQkgykAWk8rlAqcHfQAAAAASUVORK5CYII=); | ||
display: block; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/search-metadata-previews/src/snippet-preview/ProductDataDesktop.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { Fragment } from "react"; | ||
import PropTypes from "prop-types"; | ||
import styled from "styled-components"; | ||
import { __, sprintf } from "@wordpress/i18n"; | ||
import { round } from "lodash"; | ||
import { StarRating } from "@yoast/components"; | ||
|
||
const ProductData = styled.span` | ||
color: #70757a; | ||
`; | ||
|
||
/** | ||
* Renders ProductData component. | ||
* | ||
* @param {Object} props The props. | ||
* | ||
* @returns {React.Component} The StarRating Component. | ||
*/ | ||
function ProductDataDesktop( props ) { | ||
const { shoppingData } = props; | ||
|
||
/* Translators: %s expands to the actual rating, e.g. 8/10. */ | ||
const ratingPart = sprintf( __( "Rating: %s", "yoast-components" ), round( ( shoppingData.rating * 2 ), 1 ) + "/10" ); | ||
|
||
/* Translators: %s expands to the review count. */ | ||
const reviewPart = sprintf( __( "%s reviews", "yoast-components" ), shoppingData.reviewCount ); | ||
|
||
return ( | ||
<ProductData> | ||
{ ( shoppingData.reviewCount > 0 ) && | ||
<Fragment> | ||
<StarRating rating={ shoppingData.rating } /> | ||
<span> { ratingPart } · </span> | ||
<span>{ reviewPart } · </span> | ||
</Fragment> | ||
} | ||
{ shoppingData.price && | ||
<Fragment> | ||
<span dangerouslySetInnerHTML={ { __html: shoppingData.price } } /> | ||
</Fragment> | ||
} | ||
{ shoppingData.availability && | ||
<span> · { shoppingData.availability }</span> } | ||
</ProductData> | ||
); | ||
} | ||
|
||
export default ProductDataDesktop; | ||
|
||
ProductDataDesktop.propTypes = { | ||
shoppingData: PropTypes.shape( { | ||
rating: PropTypes.number, | ||
reviewCount: PropTypes.number, | ||
availability: PropTypes.string, | ||
price: PropTypes.string, | ||
} ).isRequired, | ||
}; |
79 changes: 79 additions & 0 deletions
79
packages/search-metadata-previews/src/snippet-preview/ProductDataMobile.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import styled from "styled-components"; | ||
import { __ } from "@wordpress/i18n"; | ||
import { round } from "lodash"; | ||
|
||
import { StarRating } from "@yoast/components"; | ||
|
||
const ProductData = styled.div` | ||
display: flex; | ||
`; | ||
|
||
const ProductDataCell50 = styled.div` | ||
flex: 1; | ||
max-width: 50%; | ||
`; | ||
|
||
const ProductDataCell25 = styled.div` | ||
flex: 1; | ||
max-width: 25%; | ||
`; | ||
|
||
const ProductDataInnerLower = styled.div` | ||
color: #70757a; | ||
`; | ||
|
||
/** | ||
* Renders ProductData component. | ||
* | ||
* @param {Object} props The props. | ||
* | ||
* @returns {React.Component} The StarRating Component. | ||
*/ | ||
function ProductDataMobile( props ) { | ||
const { shoppingData } = props; | ||
|
||
return ( | ||
<ProductData> | ||
{ ( shoppingData.rating > 0 ) && | ||
<ProductDataCell50 className="yoast-shopping-data-preview__column"> | ||
<div className="yoast-shopping-data-preview__upper">{ __( "Rating", "yoast-components" ) }</div> | ||
<ProductDataInnerLower className="yoast-shopping-data-preview__lower"> | ||
<span>{ round( ( shoppingData.rating * 2 ), 1 ) }/10 </span> | ||
<StarRating rating={ shoppingData.rating } /> | ||
<span> ({ shoppingData.reviewCount })</span> | ||
</ProductDataInnerLower> | ||
</ProductDataCell50> | ||
} | ||
{ ( shoppingData.price ) && | ||
<ProductDataCell25 className="yoast-shopping-data-preview__column"> | ||
<div className="yoast-shopping-data-preview__upper">{ __( "Price", "yoast-components" ) }</div> | ||
<ProductDataInnerLower | ||
className="yoast-shopping-data-preview__lower" | ||
dangerouslySetInnerHTML={ { __html: shoppingData.price } } | ||
/> | ||
</ProductDataCell25> | ||
} | ||
{ ( shoppingData.availability ) && | ||
<ProductDataCell25 className="yoast-shopping-data-preview__column"> | ||
<div className="yoast-shopping-data-preview__upper">{ __( "Availability", "yoast-components" ) }</div> | ||
<ProductDataInnerLower className="yoast-shopping-data-preview__lower"> | ||
{ shoppingData.availability } | ||
</ProductDataInnerLower> | ||
</ProductDataCell25> | ||
} | ||
</ProductData> | ||
); | ||
} | ||
|
||
export default ProductDataMobile; | ||
|
||
ProductDataMobile.propTypes = { | ||
shoppingData: PropTypes.shape( { | ||
rating: PropTypes.number, | ||
reviewCount: PropTypes.number, | ||
availability: PropTypes.string, | ||
price: PropTypes.string, | ||
} ).isRequired, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.