-
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
Post Anniversaries #14991
Post Anniversaries #14991
Conversation
|
||
const EmptyMessage = localize( ( { translate } ) => ( | ||
<ErrorPanel | ||
message={ translate( 'No anniversaries today!', { |
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.
ℹ️ This context is really long. Are you sure you don't want to use a translator comment instead?
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.
+1
<div> | ||
<StatsContentText> | ||
<p> | ||
{ translate( 'Published on this day in the past years:', { |
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.
ℹ️ This string is probably long enough that it doesn't need a context. Are you sure you don't want to use a translator comment instead?
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.
+1
return ( | ||
<div> | ||
<SectionHeader | ||
label={ translate( 'Anniversaries', { |
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! I've found a possible matching string that has already been translated 27 times:
translate( 'Happy Anniversary!' )
ES Score: 11
Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).
be022e6
to
6f176a9
Compare
Awesome stuff -- thanks for taking the time to think this through @bpierre -- as well as for so clearly laying out the thought process behind the decisions you've made.
That's an interesting approach. It might also be cool to see the post that is the most notable anniversary (based on views or some other metric).
I believe you are correct. In fact, for the first year of a user's life, this module wouldn't show any aniversaries. It might be interesting to see the module only appear when anniversaries exist, as opposed to having a "zero state".
I agree with your reasoning for placing the module on Insights.
Ideally we'd have a way for you to see stats for any day (currently you can only navigate as far back as the calendar allows), which would make anniversaries on a specific day a little less notable. |
I agree would be really nice. The approach I'd take is to do this first, then to iterate with the more entertaining one. You raise also some good questions and considerations, I'll try to summarize it:
In general, I'd also suggest to not "pack" multiple extra things in a PR. Try to keep the PRs focused on a single thing. ;) |
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.
Some changes
@@ -210,6 +210,9 @@ module.exports = React.createClass( { | |||
} | |||
|
|||
switch ( valueData.type ) { | |||
case 'raw': | |||
value = valueData.value; | |||
break; |
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.
Can you detail why this?
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.
This is required to disable the formatting on the right column of the table. Without this, the value would be formatted as a number, e.g. 2,017
instead of 2017
.
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.
👍
}; | ||
|
||
const CalendarIcon = () => ( | ||
<span style={ { position: 'relative', top: '-2px' } }> |
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.
Please don't do this, and don't inline style. Style should be in its separate SCSS file.
If it's a more general issue, just open a separate issue.
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.
Understood.
Thank you for your feedback and suggestions!
Good idea! I am adding this.
Are you suggesting to remove it from Insights, or to also add it in these tabs? How do you see it for the Weeks and Months tabs? A few options I have in mind:
I agree, I’ll modify this.
I will try to do that, thanks. |
6f176a9
to
4996efb
Compare
: <div> | ||
<SectionHeader | ||
label={ translate( | ||
'Anniversaries', |
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! I've found a possible matching string that has already been translated 27 times:
translate( 'Happy Anniversary!' )
ES Score: 11
Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).
Remove from insights. Insights should be just "overviews", not tied to a definite timeframe.
Should show "all in the timeframe", so no to any arbitrary selection of day (the other options listed). This last option is the one we should frame, and I agree might be many posts. A simple way to approach this is to just show "top 3" and then a counter or link that expands on a separate page. The MVP of this is probably to just rename the title to "Top Three Anniversaries" if there are more than X, and show top X in the box, where "Top" is by view count (we should have already the data in the API judging from |
7c8fb09
to
e896d74
Compare
const date = period.startOf.clone(); | ||
|
||
if ( period.period === 'week' ) { | ||
return translate( '%(startDate)s - %(endDate)s', { |
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! I've found a possible matching string that has already been translated 32 times:
translate( '%(startDate)s - %(endDate)s', { context: 'Date range for which stats are being displayed'} )
ES Score: 27
Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).
ℹ️ This string is probably long enough that it doesn't need a context. Are you sure you don't want to use a translator comment instead?
@@ -186,6 +187,15 @@ class StatsSummary extends Component { | |||
statType="statsSearchTerms" | |||
summary />; | |||
break; | |||
|
|||
case 'anniversaries': | |||
title = translate( 'Anniversaries' ); |
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! I've found a possible matching string that has already been translated 27 times:
translate( 'Happy Anniversary!' )
ES Score: 11
Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).
return translate( 'this week' ); | ||
} | ||
if ( period.period === 'month' ) { | ||
return translate( 'this month' ); |
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! I've found a possible matching string that has already been translated 41 times:
translate( 'This Month' )
ES Score: 12
See 1 additional suggestion in the PR translation status page
Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).
return translate( 'this day' ); | ||
} | ||
if ( period.period === 'week' ) { | ||
return translate( 'this week' ); |
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! I've found a possible matching string that has already been translated 69 times:
translate( 'This week' )
ES Score: 13
See 1 additional suggestion in the PR translation status page
Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).
e896d74
to
9123cf7
Compare
9123cf7
to
0594adb
Compare
0594adb
to
bf2e59e
Compare
bf2e59e
to
01cfb82
Compare
Changes following the suggestions on #14991: - Dedicated module page. - Move the module from the Insights tab to Days, Weeks and Months. - Shows all the anniversaries in the selected range. - Only display the top (by views) three posts anniversaries if more exist. The top three posts are selected by views count, but they are sorted by date and not by views count. - Open the post stat page when the link is clicked (consistency with other modules). - Move the module internal components in separate files.
@folletto @jonathansadowski I pushed some changes, here is a description of the main things: The module has been moved from the Insights tabs to the Days, Weeks and Months tabs. The anniversaries displayed in the module correspond to the selected date range. The module now provides a dedicated page, that allows the user to see all the anniversary posts for a given Day, Week or Month. The page can be accessed using the module title: When there are more than three posts in the module, only the three most viewed posts are displayed, the title becomes “Top 3 anniversaries”, and a “View All” footer link appears, which links to the page: Dedicated page (for a month here): Some notesRequesting the posts views is made in a different way than the “Posts & Pages” modules, as we already have a precise list of posts for which the views need to be fetched. The solution is to make one The posts now link to the stats page of the post, for consistency with the other modules. The post itself is still accessible with an “View” / external icon link (matching the other modules too). Some components are imported from the |
I agree with you it's kinda nice when it's just one, without the repetition. It also doesn't limit the title length in that format, so it's good. 👍 |
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.
Gave a look through the code and quickly tested the branch (not exhaustively). Left a few comments for things that I'd like to see addressed.
|
||
const label = ( translate, period ) => { | ||
if ( period.period === 'day' ) { | ||
return translate( 'Published on this day in the past years:', { |
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.
Change to "Published on this day in the past:"
} ); | ||
} | ||
if ( period.period === 'week' ) { | ||
return translate( 'Published on this week in the past years:', { |
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.
Change to "Published on this week in the past:"
} ); | ||
} | ||
if ( period.period === 'month' ) { | ||
return translate( 'Published on this month in the past years:', { |
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.
Change to "Published on this month in the past:"
<StatsListLegend label={ translate( 'Title' ) } value={ translate( 'Year' ) } /> | ||
<StatsList | ||
moduleName={ 'postAnniversaries' } | ||
data={ postsByYear.reduce( |
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.
Move this generation of the data to a separate function -- will make the JSX clearer to read.
|
||
const oldestPostQuery = { number: 1, order: 'ASC' }; | ||
|
||
const mapStateToProps = ( state, props ) => { |
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.
This method is too long, please refactor to split up.
if ( postsByYear[ i ] !== result ) { | ||
postsByYear[ i ] = result || []; | ||
postsByYear = [ ...postsByYear ]; | ||
} |
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 find this code section confusing. Please consider reworking to make it a bit more understandable at a glance.
<Gridicon icon="calendar" size={ 18 } /> | ||
{ translate( | ||
'%(yearsAgo)d year ago on %(period)s, {{href}}%(title)s{{/href}} was published.', | ||
'%(yearsAgo)d years ago on %(period)s, {{href}}%(title)s{{/href}} was published.', |
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.
Concatenating translated strings (%period
) like this can result in issues for some languages. Please rework to avoid inserting translated strings instead other translated strings.
? null | ||
: <div> | ||
{ topPostsOnly | ||
? allPosts.map( |
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.
This worries me. Sure, HTTP2 requests are slimmer for the client, but won't the server still have to process these requests? How is this bounded?
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, thanks for noticing this. The maximum amount of requests is set 10 to fetch the posts, but to create the top 3, a single request need to be created for each individual post, and even a single day can have an infinite amount of posts. I just opened a pull request that will add the possibility to fetch the top posts for a period of time, which will allow to make a single request per period of time in order to get the most viewed posts.
status: 'publish', | ||
} ); | ||
|
||
export default connect( () => { |
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.
Having lots of logic in here indicates a code smell to me, and makes me think certain logic belongs in selectors?
Stats: add a module to display the post anniversaries for the current day. The stats-list-item module has also been modified to display a value without formatting.
Changes following the suggestions on #14991: - Dedicated module page. - Move the module from the Insights tab to Days, Weeks and Months. - Shows all the anniversaries in the selected range. - Only display the top (by views) three posts anniversaries if more exist. The top three posts are selected by views count, but they are sorted by date and not by views count. - Open the post stat page when the link is clicked (consistency with other modules). - Move the module internal components in separate files.
- Removed nested translations - Made some parts easier to understand
b8b8b11
to
5140391
Compare
@mattsherman Thanks for your feedback! I made the requested changes, apart from the |
Hi!
This is my first pull request on the project, its goal is to add a module in the stats section that will display the post anniversaries corresponding to the current day. Please let me know what you think! 😊
Screenshots
Here are some visuals of the module in its current state, including zero / one / two / more posts:
Rationale
The first approach I followed was to provide a full completeness: the module displays all the posts found for the last ten years [1].
Another approach that I would like to discuss would be to see this module as something more “entertaining” than informative, which would allow it to display only one (random) anniversary if several exist. It could also visually be identified as something special (e.g. using an icon representing a birthday cake), the same way “Best Views Ever” is using a cup icon with a yellow color.
Display modes
I believe (maybe this information can be found somewhere?) that having only one or zero anniversaries would be the most common cases, and decided to display the single anniversary case as a simple sentence, following the pattern of the “Latest Post Summary” module:
When several anniversaries exist, a table is used to display the list of posts, reusing a component found in other stats modules like “Posts & Pages”:
While having the advantage of reusing an existing component, I am not sure a table is the best way to display this data. Another way could be to only display the first year containing anniversaries, and to add buttons that would allow the user to navigate through the years containing anniversaries. The posts could also be grouped by year as a series of lists. If so, a solution could be to expand it vertically using a “more” button.
Emplacement
At the moment, the module appears in the Insights tab of the stats section. I am still unsure about this, as my first instinct was to put it in the Days tab.
Some reasons for not displaying it in the Days tab:
But an important reason for doing it would be to allow the user to display the post anniversaries of any day, not only today.
Additional Notes
stats/stats-list/stats-list-item.jsx
to allow it to display a year without formatting it as a number.<Gridicon/>
component to fix its alignment. It is a temporary fix that I only applied to the single anniversary mode. The problem is present with other modules of the stats section and I will open a separate issue to discuss this, so this fix can be removed.cc @ehg
[1] This limitation exists because the WordPress.com API doesn’t allow a query on multiple date ranges, which means that each year need to be queried separately. The module tries to optimize this by fetching the oldest post first. Then, if the blog is younger than ten years, only the relevant years will be queried. This optimization can easily be removed in the future whenever / if the WordPress.com API implements the feature.