From 72654a48c6eb7dafa16dcd49d48ddaddccd1a6f0 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Thu, 22 Sep 2022 03:49:12 +0200 Subject: [PATCH] Products by Rating: Add misc TS fixes --- assets/js/blocks/rating-filter/block.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/assets/js/blocks/rating-filter/block.tsx b/assets/js/blocks/rating-filter/block.tsx index acd8f87880f..e90e97d22dd 100644 --- a/assets/js/blocks/rating-filter/block.tsx +++ b/assets/js/blocks/rating-filter/block.tsx @@ -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'; @@ -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: ( ), + value: item?.rating?.toString(), }; - } - return null; - } ); + } ); return ( <>