-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
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 } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
→ #5959
@@ -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 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data Domination.
var i18n = require( 'lib/mixins/i18n' ), | ||
Popover = require( 'components/popover' ), | ||
Tooltip = require( 'components/chart/tooltip' ); | ||
import i18n from 'lib/mixins/i18n'; |
There was a problem hiding this comment.
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
e4f2b80
to
f3c5c6f
Compare
JS sort() uses string comparisons by default, also looping over the object is quicker than doing a sort.
We've been iterating on this a bit, and I think it is looking good and working well. One change we discussed is adding 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 |
Thanks for the sleuthing @nylen - I will add a util method and update the branch. |
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. |
|
|
||
describe( 'getStatsStreakQuery()', () => { | ||
it( 'should return the correct default query', () => { | ||
const streakQuery = getStatsStreakQuery( {} ); |
There was a problem hiding this comment.
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.
@nylen in 97e3526 I removed the |
|
||
for ( let i = 0; i < 7; i++ ) { | ||
const dayDate = i18n.moment( startDate ).add( i, 'day' ); | ||
const postCount = streakData[ dayDate.format( 'YYYY-MM-DD' ) ]; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Still working well, a couple of minor notes but otherwise LGTM |
Part of moving stats away from the
stats-list
andlocalStore
- this branch moves the Post Trends visualization on the insights page to use redux-backed data. In order to do so, a new data componentQuerySiteStats
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
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