Skip to content

Commit

Permalink
Stats: Trash pickup of old localStore usage. (#8338)
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyc authored Sep 30, 2016
1 parent 80ab48f commit e5d252a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 69 deletions.
51 changes: 1 addition & 50 deletions client/my-sites/stats/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External Dependencies
*/
import React from 'react';
import store from 'store';
import page from 'page';
import i18n from 'i18n-calypso';

Expand All @@ -25,26 +24,6 @@ const user = userFactory();
const sites = sitesFactory();
const analyticsPageTitle = 'Stats';

function getVisitDates() {
const statsVisitDates = store.get( 'statVisits' ) || [];
return statsVisitDates;
}

function recordVisitDate() {
let statsVisitDates = getVisitDates();
const visitDate = i18n.moment().format( 'YYYY-MM-DD' );

if ( statsVisitDates.indexOf( visitDate ) === -1 ) {
statsVisitDates.push( visitDate );
}

if ( statsVisitDates.length > 10 ) {
statsVisitDates = statsVisitDates.slice( statsVisitDates.length - 10 );
}

store.set( 'statVisits', statsVisitDates );
}

function rangeOfPeriod( period, date ) {
const periodRange = {
period: period,
Expand Down Expand Up @@ -198,7 +177,6 @@ module.exports = {
{ title: i18n.translate( 'Years' ), path: '/stats/year', id: 'stats-year', period: 'year' }
];
};
const queryOptions = context.query;
const basePath = route.sectionify( context.path );

window.scrollTo( 0, 0 );
Expand All @@ -214,18 +192,11 @@ module.exports = {
if ( 0 === activeFilter.length ) {
next();
} else {
if ( queryOptions.from ) {
// For setting the oldStatsLink back to my-stats or wp-admin, depending on source
store.set( 'oldStatsLink', queryOptions.from );
}

activeFilter = activeFilter.shift();

analytics.mc.bumpStat( 'calypso_stats_overview_period', activeFilter.period );
analytics.pageView.record( basePath, analyticsPageTitle + ' > ' + titlecase( activeFilter.period ) );

recordVisitDate();

renderWithReduxStore(
React.createElement( StatsComponent, {
period: activeFilter.period,
Expand Down Expand Up @@ -331,38 +302,18 @@ module.exports = {
analytics.mc.bumpStat( 'calypso_stats_site_period', activeFilter.period + numPeriodAgo );
analytics.pageView.record( baseAnalyticsPath, analyticsPageTitle + ' > ' + titlecase( activeFilter.period ) );

recordVisitDate();

period = rangeOfPeriod( activeFilter.period, date );
chartPeriod = rangeOfPeriod( activeFilter.period, chartDate );
endDate = period.endOf.format( 'YYYY-MM-DD' );
chartEndDate = chartPeriod.endOf.format( 'YYYY-MM-DD' );

if ( queryOptions.from ) {
// For setting the oldStatsLink back to my-stats or wp-admin, depending on source
store.set( 'oldStatsLink', queryOptions.from );
}

// If there is saved tab in store, use it then remove
if ( store.get( 'statTab' + siteId ) ) {
chartTab = store.get( 'statTab' + siteId );
store.remove( 'statTab' + siteId );
} else {
chartTab = 'views';
}

chartTab = queryOptions.tab || 'views';
visitsListFields = chartTab;
// If we are on the default Tab, grab visitors too
if ( 'views' === visitsListFields ) {
visitsListFields = 'views,visitors';
}

if ( queryOptions.tab ) {
store.set( 'statTab' + siteId, queryOptions.tab );
// We don't want to persist tab throughout navigation, it's only for selecting original tab
page.redirect( context.pathname );
}

switch ( activeFilter.period ) {
case 'day':
chartQuantity = 30;
Expand Down
13 changes: 0 additions & 13 deletions client/my-sites/stats/site.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import page from 'page';
import React from 'react';
import store from 'store';
import debugFactory from 'debug';

/**
Expand Down Expand Up @@ -65,16 +64,10 @@ module.exports = React.createClass( {

componentDidMount: function() {
const scrollPosition = this.state.scrollPosition;
const localKey = 'statsHide' + this.props.siteId;
const hiddenSiteModules = store.get( localKey ) || [];

setTimeout( function() {
window.scrollTo( 0, scrollPosition );
} );

if ( hiddenSiteModules.length ) {
analytics.mc.bumpStat( 'calypso_stats_mod_hidden', hiddenSiteModules.length );
}
},

updateScrollPosition: function() {
Expand All @@ -87,12 +80,6 @@ module.exports = React.createClass( {
page.redirect( this.props.path + '?startDate=' + bar.period );
},

trackOldStats: function() {
const oldStatsLocation = ( 'wp-admin' === store.get( 'oldStatsLink' ) ) ? 'wp-admin' : 'my-stats';
analytics.mc.bumpStat( 'calypso_stats_return', oldStatsLocation );
analytics.ga.recordEvent( 'Stats', 'Clicked Visit Old Stats Page Button', oldStatsLocation );
},

barClick: function( bar ) {
analytics.ga.recordEvent( 'Stats', 'Clicked Chart Bar' );
page.redirect( this.props.path + '?startDate=' + bar.data.period );
Expand Down
10 changes: 4 additions & 6 deletions client/my-sites/stats/stats-chart-tabs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import React from 'react';
import classNames from 'classnames';
import { find } from 'lodash';

/**
* Internal dependencies
Expand All @@ -22,7 +23,7 @@ export default React.createClass( {

getInitialState: function() {
var activeTab = this.getActiveTab(),
activeCharts = activeTab.legendOptions.slice() || [];
activeCharts = activeTab.legendOptions ? activeTab.legendOptions.slice() : [];

return {
activeLegendCharts: activeCharts,
Expand Down Expand Up @@ -157,11 +158,8 @@ export default React.createClass( {
},

getActiveTab: function( nextProps ) {
var props = nextProps || this.props;

return props.charts.filter( function( chart ) {
return chart.attr === props.chartTab;
}, this ).shift();
const props = nextProps || this.props;
return find( props.charts, { attr: props.chartTab } ) || props.charts[ 0 ];
},

buildChartData: function() {
Expand Down

0 comments on commit e5d252a

Please sign in to comment.