Skip to content

Improve the PDF Filename #13216

Closed
Closed

Description

@benbowler

Feature Description

The Design doc states the file name as:

A PDF file downloads automatically with a filename like Site Kit Dashboard - example.com - Mar 1-7 2026.pdf

Current file name:
site-kit-pdfgenerationbugbash-instawp-co-last-28-days-2026-07-29.pdf

Site Kit Dashboard isn't there and the domain should be proper without dashes in the middle.
Date doesn't match the expected format.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The exported PDF downloads with a filename in the form Site Kit Dashboard - example.com - Mar 1 – 7, 2026.pdf.
  • The site segment shows the site's domain, matching the address shown in the report header.
  • The date segment covers the same reporting period as the report header, written in the compact range format below rather than the header's two full dates.
  • A reporting period inside a single month shows the month and year once, for example Mar 1 – 7, 2026.
  • A reporting period spanning two months or two years shows both in full, for example Dec 28, 2025 – Jan 3, 2026.
  • The date segment follows the user's locale.
  • The filename no longer carries the date the report was generated.
  • Characters that filesystems reject are removed from the filename, so the download succeeds on Windows, macOS and Linux.

Implementation Brief

Files to modify:

  • Update file assets/js/components/pdf-export/pdf-utils.ts:
    • Change getPDFFilename to take the reference site URL and the report's { startDate, endDate }, returning <prefix> - <host> - <range>.pdf with the prefix Site Kit Dashboard wrapped in __().
    • Move getSiteHost here from PDFHeader.tsx and export it.
    • Format the range with Intl.DateTimeFormat( getLocale(), { month: 'short', day: 'numeric', year: 'numeric' } ).formatRange() over stringToDate, guarded by isValidDateString as formatDateString does. Omit the segment and its separator when either date is invalid, mirroring the header's dangling-separator guard.
    • Strip the characters filesystems reject (\ / : * ? " < > | and control characters) plus trailing dots and spaces, and collapse whitespace runs. Keep the existing report fallback for when no host resolves.
    • Remove slugify and getISODate with the generation date stamp.
  • Update file assets/js/components/pdf-export/shared-react-pdf-components/PDFHeader.tsx: import getSiteHost from pdf-utils and delete the local copy.
  • Update file assets/js/components/pdf-export/PDFExportOrchestrator.tsx: pass referenceSiteURL and the dates already selected for the header into getPDFFilename, and remove the getDateRange selector with the referenceName and resolvedDateRange locals it fed.

Test Coverage

  • Create file assets/js/components/pdf-export/pdf-utils.test.ts: assert the composed filename for a same-month, a cross-month and a cross-year reporting period.
  • Same file: assert the host comes from the reference URL with the scheme and path removed, and that an unparseable URL falls back to the report segment.
  • Same file: assert an invalid start or end date drops the range segment without leaving a dangling separator.
  • Same file: assert reserved characters and trailing dots and spaces are stripped from the composed name.
  • Update file assets/js/components/pdf-export/PDFExportOrchestrator.test.tsx: assert triggerDownload receives a filename in the new format built from the export's reporting period.
  • No Storybook or VRT entries: the change is a filename string and the header keeps its rendered output.

QA Brief

  • On the Site Kit dashboard, click Download PDF report in the header, then Download report in the panel. Verify the downloaded file is named Site Kit Dashboard - <your-domain> - <date range>.pdf, e.g. Site Kit Dashboard - example.com - Sep 4 – Oct 1, 2026.pdf:
    • The domain matches the site address shown in the PDF header, with no https://, path or dashes replacing dots.
    • The date range covers the same period as the PDF header, in the compact form (month and year shown once for a single-month range, e.g. Mar 1 – 7, 2026; both in full when it spans months or years).
    • The filename no longer ends with the generation date.
  • Change the dashboard date range (e.g. to the last 7 days) and export again; verify the filename's range follows.
  • Switch the site language (Settings → General → Site Language, e.g. Deutsch) and export again; verify the date range in the filename is in that language, e.g. 4. Sept. – 1. Okt. 2026.
  • Verify the file downloads and opens normally on Windows, macOS and Linux.

Changelog entry

  • Improve the exported PDF filename to name the site and the reporting period.

Activity

  1. self-assigned this
    on Jul 29, 2026
  2. self-assigned this
    on Aug 20, 2026
  3. zutigrm commented on Aug 20, 2026

    @zutigrm
    Collaborator

    Thanks @benbowler , just one thing to clarify in AC:

    The date segment shows the report's reporting period, matching the dates shown in the report header.
    A reporting period inside a single month shows the month and year once, for example Mar 1 – 7, 2026.

    This won't be a literal match. The header joins two full dates with " - "

    const endDate = formatDateString( dateRange.endDate );
    /** Avoid a dangling " - " when one (or both) of the dates is invalid. */
    const formattedDateRange =
    startDate && endDate
    ? `${ startDate } - ${ endDate }`
    : startDate || endDate;

    giving Mar 1, 2026 - Mar 7, 2026, while the filename gives Mar 1 – 7, 2026. Same reporting period, different formatting. For the different months suggested format in AC is correct, but not for the same month. Worth rewording this one, or aligning the formats.

    Image
  4. benbowler commented on Aug 20, 2026

    @benbowler
    CollaboratorAuthor

    Good catch, reworded that bullet so it no longer implies a literal match: it now says the date segment covers the same reporting period as the header but in the compact range format (Mar 1 – 7, 2026) rather than the header's two full dates. The two format bullets below it already spell out the same-month and cross-month cases.

  5. 5 remaining items

  6. removed their assignment
    on Oct 1, 2026
  7. assigned and unassigned on Oct 8, 2026
  8. removed their assignment
    on Oct 9, 2026
  9. self-assigned this
    on Oct 9, 2026
  10. kelvinballoo commented on Oct 9, 2026

    @kelvinballoo
    Collaborator

    QA Update ✅

    • Tested a couple of timeframes and it's generated fine with the file name as expected.

      Details Image Image Image Image
    • Deutsche language will have the dates recorded in that language.

      Details Image
    • I was not able to verify on Linux as I don't have a machine. That said, Claude helped to generate and verify the downloaded filename Site Kit Dashboard - oi.ie - Jul 11 – Oct 8, 2026.pdf contains no characters Linux rejects (only / and NUL are disallowed).

    • Windows - Mohit helped to verify and it's fine.

      Details Image Image Image
    • Mac (All my above tests were on Mac)

    • View dashboard downloads are also as expected.

      Details Image
  11. removed their assignment
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Low priorityTeam SIssues for Squad 1Type: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions