Skip to content

Stats: Update the stats map in Odyssey stats to match the map in Calypso #103822

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

Merged
merged 6 commits into from
Jun 3, 2025
Merged
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
22 changes: 19 additions & 3 deletions client/my-sites/stats/geochart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import PropTypes from 'prop-types';
import { createRef, Component } from 'react';
import { connect } from 'react-redux';
import QuerySiteStats from 'calypso/components/data/query-site-stats';
import { useGeoLocationQuery } from 'calypso/data/geo/use-geolocation-query';
import { gaRecordEvent } from 'calypso/lib/analytics/ga';
import { useSelector } from 'calypso/state';
import { getCurrentUserCountryCode } from 'calypso/state/current-user/selectors';
import { getEmailStatsNormalizedData } from 'calypso/state/stats/emails/selectors';
import { getSiteStatsNormalizedData } from 'calypso/state/stats/lists/selectors';
Expand All @@ -35,6 +37,7 @@ class StatsGeochart extends Component {
customHeight: PropTypes.number,
isRealTime: PropTypes.bool,
minutesLimit: PropTypes.number,
currentUserCountryCode: PropTypes.string,
};

static defaultProps = {
Expand Down Expand Up @@ -455,11 +458,10 @@ class StatsGeochart extends Component {
}
}

export default connect( ( state, ownProps ) => {
const ConnectedStatsGeochart = connect( ( state, ownProps ) => {
const siteId = getSelectedSiteId( state );
const statType = ownProps.statType ?? 'statsCountryViews';
const currentUserCountryCode = getCurrentUserCountryCode( state );
const { postId, query, kind } = ownProps;
const { postId, query, kind, currentUserCountryCode } = ownProps;

// Skip data fetching if it was explicitly passed as a prop
if ( ownProps.data ) {
Expand Down Expand Up @@ -491,3 +493,17 @@ export default connect( ( state, ownProps ) => {
statType,
};
} )( localize( StatsGeochart ) );

const StatsGeochartWrapper = ( props ) => {
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

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

[nitpick] StatsGeochartWrapper isn’t documented with PropTypes or a displayName. Adding PropTypes and setting StatsGeochartWrapper.displayName would improve clarity in tooling and future maintenance.

Copilot uses AI. Check for mistakes.

const { data: geoData, isLoading: isGeoLocationLoading } = useGeoLocationQuery();
const geoCountryCode = geoData?.country_short;
const userCountryCode = useSelector( getCurrentUserCountryCode );

// Use geo location fallback if user country code is not available
const geoLocationReady = ! isGeoLocationLoading && geoCountryCode;
const finalCountryCode = userCountryCode || geoLocationReady || null;

return <ConnectedStatsGeochart { ...props } currentUserCountryCode={ finalCountryCode } />;
};

export default StatsGeochartWrapper;