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: use Redux for Post Trends #5847

Merged
merged 13 commits into from
Jun 10, 2016
Merged

Stats: use Redux for Post Trends #5847

merged 13 commits into from
Jun 10, 2016

Conversation

timmyc
Copy link
Contributor

@timmyc timmyc commented Jun 7, 2016

Part of moving stats away from the stats-list and localStore - this branch moves the Post Trends visualization on the insights page to use redux-backed data. In order to do so, a new data component QuerySiteStats has been added here, which will be utilized throughout the rest of the stats components to fetch data from the API.

Alongside the addition of QuerySiteStats, I realized the initial approach taken in #5743 WRT the response structure of the stats streak data was incorrect. The updates to the selectors and tests to fix this can be seen in 7c11823.

Integrating the new query component, and associated selector logic can be seen in b668a54.

To Test

  • Open up the stats insights page, validate the "Posting Activity" component up top looks/functions as it does in production
  • Switch sites to verify loading state and data updates between site changes

There is quite a bit more ES6-ification that can happen throughout the post-trends/*.jsx files, but I tried to keep this focused on the task at hand.

Test live: https://calypso.live/?branch=update/stats/insights-streak

@timmyc timmyc added [Feature] Stats Everything related to our analytics product at /stats/ [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. State labels Jun 7, 2016
@timmyc timmyc self-assigned this Jun 7, 2016
@timmyc
Copy link
Contributor Author

timmyc commented Jun 7, 2016

Ping @nylen if you are keen to dabble in stats land. Let me know if you want a walk through at all.

className="chart__tooltip is-streak"
onClose={ noop }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the relocation an indication that you'd tried to remove the prop altoghether? 😉 That was my first thought, though looks like this is required in <Popover />. Don't see any reason why we couldn't make it optional... side-concern of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed I did try to remove this, and of course eslint complains about the () => {} here. I agree we should make this an optional prop with a default of a noop in the base component. Are you okay with doing this in a follow-up?

Copy link
Contributor

Choose a reason for hiding this comment

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

#5959

@aduth aduth added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 8, 2016
@timmyc
Copy link
Contributor Author

timmyc commented Jun 8, 2016

Thanks for the review @aduth. Applied most of the updates in d110b64 - including simplifying the popover and only persisting the data object from the API response in the state tree.

In e4f2b80 the old streakList logic was removed from the controller and upstream files.

@@ -53,7 +48,7 @@ export function requestSiteStats( siteId, statType, query ) {
} );

return wpcom.site( siteId )[ statType ]( query ).then( data => {
dispatch( receiveSiteStats( siteId, statType, query, omit( data, '_headers' ) ) );
dispatch( receiveSiteStats( siteId, statType, query, data.data ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Data Domination.

@timmyc timmyc added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Jun 8, 2016
var i18n = require( 'lib/mixins/i18n' ),
Popover = require( 'components/popover' ),
Tooltip = require( 'components/chart/tooltip' );
import i18n from 'lib/mixins/i18n';
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi there, i18n usage has just changed recently. please use:

import i18n from 'i18n-calypso';

instead

@timmyc timmyc force-pushed the update/stats/insights-streak branch from e4f2b80 to f3c5c6f Compare June 8, 2016 16:40
nylen added 3 commits June 8, 2016 13:31
JS sort() uses string comparisons by default, also looping over the
object is quicker than doing a sort.
@nylen
Copy link
Contributor

nylen commented Jun 8, 2016

We've been iterating on this a bit, and I think it is looking good and working well.

One change we discussed is adding max: 3000 to the query objects in post-trends/index.jsx and post-trends/day.jsx. This only makes a difference for sites with very large numbers of posts but this way it will match the old behavior.

Since these query objects are duplicated, and must be the same between these two files for everything to work correctly, we should move them into a common function - perhaps state/stats/lists/utils.js is an appropriate location for that.

@timmyc
Copy link
Contributor Author

timmyc commented Jun 8, 2016

Thanks for the sleuthing @nylen - I will add a util method and update the branch.

@timmyc timmyc added [Status] In Progress and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 8, 2016
@nylen
Copy link
Contributor

nylen commented Jun 8, 2016

As far as I'm concerned, feel free to ship after that - I'm satisfied with how this works, unless @aduth wants to give the reduxy bits another pass.

@timmyc
Copy link
Contributor Author

timmyc commented Jun 8, 2016

getStatsStreakQuery and tests added in a5af2ef

@timmyc timmyc added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Jun 8, 2016

describe( 'getStatsStreakQuery()', () => {
it( 'should return the correct default query', () => {
const streakQuery = getStatsStreakQuery( {} );
Copy link
Contributor

Choose a reason for hiding this comment

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

Could omit the {} here so that we test the default parameter value.

@timmyc
Copy link
Contributor Author

timmyc commented Jun 9, 2016

@nylen in 97e3526 I removed the statsStreak query logic, and made <Day /> a pure component. Only one connect now is happening in the parent component, and the streakData is passed down. Granted this removes the ability to have <Month /> and <Week /> be pure, it will result in fewer re-renders when a new payload arrives.


for ( let i = 0; i < 7; i++ ) {
const dayDate = i18n.moment( startDate ).add( i, 'day' );
const postCount = streakData[ dayDate.format( 'YYYY-MM-DD' ) ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably add || 0 here since postCount is a number prop of Day.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a default prop value set to 0 for postCount on <Day />, but I suppose I could do that here too.

@nylen
Copy link
Contributor

nylen commented Jun 10, 2016

Still working well, a couple of minor notes but otherwise LGTM

@timmyc
Copy link
Contributor Author

timmyc commented Jun 10, 2016

Changed up those items in 02a490a @nylen - good to merge this then?

@nylen nylen added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 10, 2016
@timmyc timmyc merged commit cf69f56 into master Jun 10, 2016
@timmyc timmyc deleted the update/stats/insights-streak branch June 10, 2016 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Stats Everything related to our analytics product at /stats/ State
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants