diff --git a/client/my-sites/stats/features/modules/stats-locations/stats-locations.tsx b/client/my-sites/stats/features/modules/stats-locations/stats-locations.tsx index 409ef8e0dc245b..c3eb9be227c639 100644 --- a/client/my-sites/stats/features/modules/stats-locations/stats-locations.tsx +++ b/client/my-sites/stats/features/modules/stats-locations/stats-locations.tsx @@ -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; @@ -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 ); @@ -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; diff --git a/client/state/stats/lists/utils.js b/client/state/stats/lists/utils.js index 47989bca79b23d..07b93ae191a851 100644 --- a/client/state/stats/lists/utils.js +++ b/client/state/stats/lists/utils.js @@ -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,