Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: add Regions/Cities tab #97948

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( /’/, "'" ),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The required change was so small that I didn't make a statsCountryViews equivalent, like statsLocationViews, for now. Maybe this will be required when plotting the regions/cities in the geochart map, but let's do it when/if required.

countryCode: viewData.country_code,
value: viewData.views,
region: country.map_region,
Expand Down
Loading