From af58eb848663c96816db5d7e4dce582c40888b6f Mon Sep 17 00:00:00 2001 From: Ankit Gade Date: Fri, 3 Jan 2025 11:51:10 +0530 Subject: [PATCH] Optimize utility functions. --- .../components/widgets/TopCitiesWidget.js | 20 ++++++++----------- .../components/widgets/TopCountriesWidget.js | 20 ++++++++----------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/assets/js/modules/analytics-4/components/widgets/TopCitiesWidget.js b/assets/js/modules/analytics-4/components/widgets/TopCitiesWidget.js index 6ea251aaf59..7eed233f601 100644 --- a/assets/js/modules/analytics-4/components/widgets/TopCitiesWidget.js +++ b/assets/js/modules/analytics-4/components/widgets/TopCitiesWidget.js @@ -86,20 +86,16 @@ function TopCitiesWidget( { Widget } ) { const { rows = [], totals = [] } = topCitiesReport || {}; - const filteredCities = ( cityRows ) => { - const notSetRow = cityRows.find( + const filteredCities = ( cityRows ) => + cityRows.some( ( { dimensionValues } ) => dimensionValues[ 0 ].value === '(not set)' - ); - if ( notSetRow ) { - return cityRows.filter( - ( { dimensionValues } ) => - dimensionValues[ 0 ].value !== '(not set)' - ); - } - - return cityRows.slice( 0, 3 ); - }; + ) + ? cityRows.filter( + ( { dimensionValues } ) => + dimensionValues[ 0 ].value !== '(not set)' + ) + : cityRows.slice( 0, 3 ); const totalUsers = totals[ 0 ]?.metricValues?.[ 0 ]?.value; diff --git a/assets/js/modules/analytics-4/components/widgets/TopCountriesWidget.js b/assets/js/modules/analytics-4/components/widgets/TopCountriesWidget.js index 2e78b0f39b3..5147b36cdee 100644 --- a/assets/js/modules/analytics-4/components/widgets/TopCountriesWidget.js +++ b/assets/js/modules/analytics-4/components/widgets/TopCountriesWidget.js @@ -88,20 +88,16 @@ function TopCountriesWidget( { Widget } ) { const { rows = [], totals = [] } = topCountriesReport || {}; - const filteredCountries = ( countryRows ) => { - const notSetRow = countryRows.find( + const filteredCountries = ( countryRows ) => + countryRows.some( ( { dimensionValues } ) => dimensionValues[ 0 ].value === '(not set)' - ); - if ( notSetRow ) { - return countryRows.filter( - ( { dimensionValues } ) => - dimensionValues[ 0 ].value !== '(not set)' - ); - } - - return countryRows.slice( 0, 3 ); - }; + ) + ? countryRows.filter( + ( { dimensionValues } ) => + dimensionValues[ 0 ].value !== '(not set)' + ) + : countryRows.slice( 0, 3 ); const totalUsers = totals[ 0 ]?.metricValues?.[ 0 ]?.value;