Skip to content

Commit 056b671

Browse files
committed
Stats: drop date segments from Emails summary CSV filename
The Emails summary export returns the latest 30 emails with no date scoping, so a period date range in the filename was misleading. Add an includeDates option to getStatsCsvFileName and turn it off for the Emails summary download.
1 parent cb37995 commit 056b671

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

client/my-sites/stats/stats-download-csv/get-stats-csv-filename.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ import moment from 'moment';
55
*
66
* When a custom date range query is present (`start_date` + `date`), those dates
77
* and the query period are used. Otherwise the legacy period object bounds are used.
8-
*
98
* @param {Object} options
109
* @param {string} options.siteSlug Site slug used as the filename prefix.
1110
* @param {string} options.path Stats module path segment (e.g. "posts").
1211
* @param {Object} options.period Period object with `period`, `startOf`, and `endOf`.
1312
* @param {Object} [options.query] Stats query; custom ranges include `start_date` and `date`.
13+
* @param {boolean} [options.includeDates] Pass false for exports that are not date-scoped
14+
* (e.g. the all-time Emails summary) to omit the period and date segments.
1415
* @returns {string} Filename ending in `.csv`.
1516
*/
16-
export function getStatsCsvFileName( { siteSlug, path, period, query } ) {
17+
export function getStatsCsvFileName( { siteSlug, path, period, query, includeDates = true } ) {
18+
if ( ! includeDates ) {
19+
return [ siteSlug, path ].join( '-' ) + '.csv';
20+
}
21+
1722
const hasCustomDateRange = Boolean( query?.start_date && query?.date );
1823
const periodLabel = hasCustomDateRange && query.period ? query.period : period.period;
1924

client/my-sites/stats/stats-download-csv/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class StatsDownloadCsv extends Component {
3333
hideIfNoData: PropTypes.bool,
3434
headers: PropTypes.array,
3535
rowModifierFn: PropTypes.func,
36+
includeDates: PropTypes.bool,
3637
};
3738

3839
processExportData = ( data ) => {
@@ -54,9 +55,9 @@ class StatsDownloadCsv extends Component {
5455

5556
downloadCsv = ( event ) => {
5657
event.preventDefault();
57-
const { siteSlug, path, period, query, data, headers } = this.props;
58+
const { siteSlug, path, period, query, data, headers, includeDates } = this.props;
5859

59-
const fileName = getStatsCsvFileName( { siteSlug, path, period, query } );
60+
const fileName = getStatsCsvFileName( { siteSlug, path, period, query, includeDates } );
6061

6162
this.props.recordGoogleEvent( 'Stats', 'CSV Download ' + titlecase( path ) );
6263

client/my-sites/stats/stats-download-csv/test/get-stats-csv-filename.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ describe( 'getStatsCsvFileName', () => {
6565
);
6666
} );
6767

68+
it( 'omits the period and date segments when includeDates is false', () => {
69+
const period = {
70+
period: 'day',
71+
startOf: moment( '2026-08-06' ),
72+
endOf: moment( '2026-08-06' ),
73+
};
74+
const query = { quantity: 30 };
75+
76+
expect(
77+
getStatsCsvFileName( { siteSlug, path: 'emails', period, query, includeDates: false } )
78+
).toBe( 'mercantile.wordpress.org-emails.csv' );
79+
} );
80+
6881
it( 'falls back to period bounds when query is omitted', () => {
6982
const period = {
7083
period: 'week',

client/my-sites/stats/stats-email-summary/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const StatsEmailSummaryInner = ( { period, query, context, breadcrumbTrail } ) =
7979
path="emails"
8080
query={ query }
8181
period={ period }
82+
includeDates={ false }
8283
headers={ [ 'title', 'opens_rate', 'unique_clicks', 'link' ] }
8384
rowModifierFn={ ( row, data ) => {
8485
if ( ! Array.isArray( row ) || row.length === 0 ) {

0 commit comments

Comments
 (0)