Skip to content

Commit

Permalink
Exclude (not set) with helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrox committed Jan 3, 2025
1 parent a4cdb3a commit e783211
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function TopCitiesWidget( { Widget } ) {
desc: true,
},
],
limit: 3,
limit: 4,
};

const topCitiesReport = useInViewSelect(
Expand All @@ -86,6 +86,21 @@ function TopCitiesWidget( { Widget } ) {

const { rows = [], totals = [] } = topCitiesReport || {};

const filteredCities = ( cityRows ) => {
const notSetRow = cityRows.find(
( { dimensionValues } ) =>
dimensionValues[ 0 ].value === '(not set)'
);
if ( notSetRow ) {
return cityRows.filter(
( { dimensionValues } ) =>
dimensionValues[ 0 ].value !== '(not set)'
);
}

return cityRows.slice( 0, 3 );
};

const totalUsers = totals[ 0 ]?.metricValues?.[ 0 ]?.value;

const columns = [
Expand Down Expand Up @@ -117,7 +132,7 @@ function TopCitiesWidget( { Widget } ) {
Widget={ Widget }
widgetSlug={ KM_ANALYTICS_TOP_CITIES }
loading={ loading }
rows={ rows }
rows={ filteredCities( rows ) }
columns={ columns }
ZeroState={ ZeroDataMessage }
error={ error }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const reportOptions = {
desc: true,
},
],
limit: 3,
limit: 4,
};

const WidgetWithComponentProps = withWidgetComponentProps(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe( 'TopCitiesWidget', () => {
desc: true,
},
],
limit: 3,
limit: 4,
} );
const { container, waitForRegistry } = render(
<TopCitiesWidget Widget={ Widget } />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function TopCountriesWidget( { Widget } ) {
desc: true,
},
],
limit: 3,
limit: 4,
};

const topCountriesReport = useInViewSelect(
Expand All @@ -88,6 +88,21 @@ function TopCountriesWidget( { Widget } ) {

const { rows = [], totals = [] } = topCountriesReport || {};

const filteredCountries = ( countryRows ) => {
const notSetRow = countryRows.find(
( { dimensionValues } ) =>
dimensionValues[ 0 ].value === '(not set)'
);
if ( notSetRow ) {
return countryRows.filter(
( { dimensionValues } ) =>
dimensionValues[ 0 ].value !== '(not set)'
);
}

return countryRows.slice( 0, 3 );
};

const totalUsers = totals[ 0 ]?.metricValues?.[ 0 ]?.value;

const columns = [
Expand Down Expand Up @@ -119,7 +134,7 @@ function TopCountriesWidget( { Widget } ) {
Widget={ Widget }
widgetSlug={ KM_ANALYTICS_TOP_COUNTRIES }
loading={ loading }
rows={ rows }
rows={ filteredCountries( rows ) }
columns={ columns }
ZeroState={ ZeroDataMessage }
error={ error }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const reportOptions = {
desc: true,
},
],
limit: 3,
limit: 4,
};

const WidgetWithComponentProps = withWidgetComponentProps(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe( 'TopCountriesWidget', () => {
desc: true,
},
],
limit: 3,
limit: 4,
} );
const { container, waitForRegistry } = render(
<TopCountriesWidget Widget={ Widget } />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ exports[`TopCitiesWidget renders correctly with the expected metrics 1`] = `
<p
class="googlesitekit-km-widget-tile__table-plain-text"
>
(not set)
New York
</p>
</div>
<div
class="googlesitekit-table__body-item"
>
<strong>
466.7%
433.3%
</strong>
</div>
</div>
Expand Down

0 comments on commit e783211

Please sign in to comment.