Skip to content

Commit

Permalink
Optimize utility functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrox committed Jan 3, 2025
1 parent 5d5f75e commit af58eb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit af58eb8

Please sign in to comment.