Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Make ReviewSortSelect controlled
  • Loading branch information
Aljullu committed Jul 27, 2021
commit 08ba008dd5c5abf93ecd718748968ba02725658d
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import SortSelect from '@woocommerce/base-components/sort-select';
*/
import './style.scss';

const ReviewSortSelect = ( { defaultValue, onChange, readOnly, value } ) => {
const ReviewSortSelect = ( { onChange, readOnly, value } ) => {
return (
<SortSelect
className="wc-block-review-sort-select wc-block-components-review-sort-select"
defaultValue={ defaultValue }
label={ __( 'Order by', 'woo-gutenberg-products-block' ) }
onChange={ onChange }
options={ [
Expand Down Expand Up @@ -48,11 +47,6 @@ const ReviewSortSelect = ( { defaultValue, onChange, readOnly, value } ) => {
};

ReviewSortSelect.propTypes = {
defaultValue: PropTypes.oneOf( [
'most-recent',
'highest-rating',
'lowest-rating',
] ),
onChange: PropTypes.func,
readOnly: PropTypes.bool,
value: PropTypes.oneOf( [
Expand Down
6 changes: 3 additions & 3 deletions assets/js/blocks/reviews/frontend-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import withReviews from '@woocommerce/base-hocs/with-reviews';
* @param {function(any):any} props.onAppendReviews Function called when appending review.
* @param {function(any):any} props.onChangeOrderby
* @param {Array} props.reviews
* @param {string} props.sortSelectValue
* @param {number} props.totalReviews
*/
const FrontendBlock = ( {
attributes,
onAppendReviews,
onChangeOrderby,
reviews,
sortSelectValue,
totalReviews,
} ) => {
const { orderby } = attributes;

if ( reviews.length === 0 ) {
return null;
}
Expand All @@ -40,7 +40,7 @@ const FrontendBlock = ( {
<>
{ attributes.showOrderby !== 'false' && reviewRatingsEnabled && (
<ReviewSortSelect
defaultValue={ orderby }
value={ sortSelectValue }
onChange={ onChangeOrderby }
/>
) }
Expand Down
1 change: 1 addition & 0 deletions assets/js/blocks/reviews/frontend-container-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class FrontendContainerBlock extends Component {
orderby={ orderby }
productId={ productId }
reviewsToDisplay={ reviewsToDisplay }
sortSelectValue={ this.state.orderby }
/>
);
}
Expand Down