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

Commit

Permalink
Products by Rating: Add misc TS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldudzic committed Sep 22, 2022
1 parent 32436c8 commit 72654a4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions assets/js/blocks/rating-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useCollectionData,
} from '@woocommerce/base-context/hooks';
import { getSettingWithCoercion } from '@woocommerce/settings';
import { isBoolean } from '@woocommerce/types';
import { isBoolean, isObject, objectHasProp } from '@woocommerce/types';
import isShallowEqual from '@wordpress/is-shallow-equal';
import { useState, useCallback, useMemo, useEffect } from '@wordpress/element';
import CheckboxList from '@woocommerce/base-components/checkbox-list';
Expand Down Expand Up @@ -186,15 +186,17 @@ const RatingFilterBlock = ( {

if (
! filteredCountsLoading &&
filteredCounts.rating_counts !== undefined
objectHasProp( filteredCounts, 'rating_counts' ) &&
Array.isArray( filteredCounts.rating_counts )
) {
const orderedRatings = [ ...filteredCounts.rating_counts ].reverse();

const displayedOptions = orderedRatings.map( ( item ) => {
if ( Object.keys( item ).length > 0 ) {
const displayedOptions = orderedRatings
.filter(
( item ) => isObject( item ) && Object.keys( item ).length > 0
)
.map( ( item ) => {
return {
value: item?.rating?.toString(),
name: 'Rating',
label: (
<Rating
className={
Expand All @@ -209,10 +211,9 @@ const RatingFilterBlock = ( {
ratedProductsCount={ item?.count }
/>
),
value: item?.rating?.toString(),
};
}
return null;
} );
} );

return (
<>
Expand Down

0 comments on commit 72654a4

Please sign in to comment.