Skip to content

Commit

Permalink
Stats: add regions/cities tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Jan 6, 2025
1 parent 0749f93 commit 72417e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ const OPTION_KEYS = {
CITIES: 'cities',
};

type StatQueryType = 'country' | 'region' | 'city';

const STAT_QUERY_TYPES: Record< string, StatQueryType > = {
[ OPTION_KEYS.COUNTRIES ]: 'country',
[ OPTION_KEYS.REGIONS ]: 'region',
[ OPTION_KEYS.CITIES ]: 'city',
};

type SelectOptionType = {
label: string;
value: string;
Expand All @@ -48,12 +56,6 @@ const StatsLocations: React.FC< StatsModuleLocationsProps > = ( { query, summary
const isOdysseyStats = config.isEnabled( 'is_running_in_jetpack_site' );
const supportUrl = isOdysseyStats ? JETPACK_SUPPORT_URL_TRAFFIC : SUPPORT_URL;

const {
data = [],
isLoading: isRequestingData,
isError,
} = useLocationViewsQuery< StatsLocationViewsData >( siteId, 'country', query );

// Use StatsModule to display paywall upsell.
const shouldGateStatsModule = useShouldGateStats( statType );

Expand All @@ -76,6 +78,14 @@ const StatsLocations: React.FC< StatsModuleLocationsProps > = ( { query, summary
},
};

const statQueryType = STAT_QUERY_TYPES[ selectedOption ];

const {
data = [],
isLoading: isRequestingData,
isError,
} = useLocationViewsQuery< StatsLocationViewsData >( siteId, statQueryType, query );

const changeViewButton = ( selection: SelectOptionType ) => {
const filter = selection.value;

Expand Down
2 changes: 1 addition & 1 deletion client/state/stats/lists/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export const normalizers = {

// ’ in country names causes google's geo viz to break
return {
label: country.country_full.replace( //, "'" ),
label: viewData.location || country.country_full.replace( //, "'" ),
countryCode: viewData.country_code,
value: viewData.views,
region: country.map_region,
Expand Down

0 comments on commit 72417e7

Please sign in to comment.