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: Fix the graph timeframe when navigating to old periods #10968

Merged
merged 1 commit into from
Jan 27, 2017
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
19 changes: 10 additions & 9 deletions client/my-sites/stats/stats-chart-tabs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ class StatModuleChartTabs extends Component {
}

const connectComponent = connect(
( state, { moment, period: periodObject, chartTab } ) => {
( state, { moment, period: periodObject, chartTab, queryDate } ) => {
const siteId = getSelectedSiteId( state );
const { period } = periodObject;
const timezoneOffset = getSiteOption( state, siteId, 'gmt_offset' ) || 0;
const momentSiteZone = moment().utcOffset( timezoneOffset );
const queryDate = rangeOfPeriod( period, momentSiteZone.locale( 'en' ) ).endOf;
let date = rangeOfPeriod( period, momentSiteZone.locale( 'en' ) ).endOf;

let quantity;
let quantity = 10;
switch ( period ) {
case 'day':
quantity = 30;
Expand All @@ -272,20 +272,21 @@ const connectComponent = connect(
case 'week':
quantity = 13;
break;
case 'year':
break;
default:
quantity = 10;
break;
}
const periodDifference = moment( date ).diff( moment( queryDate ), period );
if ( periodDifference >= quantity ) {
date = moment( date ).subtract( Math.floor( periodDifference / quantity ) * quantity, period ).format( 'YYYY-MM-DD' );
}

let quickQueryFields = chartTab;
// If we are on the default Tab, grab visitors too
if ( 'views' === quickQueryFields ) {
quickQueryFields = 'views,visitors';
}

const query = {
unit: period,
date: queryDate,
date,
quantity
};
const quickQuery = {
Expand Down