Skip to content

Premium Analytics: split CSV download components - #50569

Merged
layoutd merged 26 commits into
trunkfrom
refactor/csv-download-components
Jul 17, 2026
Merged

Premium Analytics: split CSV download components#50569
layoutd merged 26 commits into
trunkfrom
refactor/csv-download-components

Conversation

@layoutd

@layoutd layoutd commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Related to WOOA7S-1671.

Proposed changes

  • Split the CSV download action into shared presentation, server-report export, and client-row export components.
  • Move report parameter mapping and feature-gate access into focused helpers.
  • Keep download loading and errors local to the shared action.
  • Preserve compact widget defaults while allowing report pages to choose a solid, iconless presentation.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No. This is an internal component refactor and does not change the exported data or add tracking.

Testing instructions

  • Build Premium Analytics with pnpm jetpack build packages/premium-analytics --deps.
  • Enable CSV exports with add_filter( 'jetpack_premium_analytics_csv_exports_enabled', '__return_true' );.
  • Confirm Orders Over Time still downloads a complete server-generated CSV.
  • Confirm Top pages by views still downloads its currently loaded rows.
  • Confirm both actions show their loading state and keep failures local.
  • Disable the feature flag and confirm both actions are hidden.
  • From projects/packages/premium-analytics, run the CSV component tests and pnpm typecheck.

@layoutd layoutd added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Jul 16, 2026
@layoutd layoutd self-assigned this Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Jul 16, 2026

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Premium Analytics CSV download support by splitting the prior all-in-one download action into smaller components: a shared button that owns loading/error UI, plus separate “server report download” and “client rows export” wrappers, along with focused helpers for feature gating and report param mapping.

Changes:

  • Replace the old DownloadCsvButton usage in widgets with ReportCsvDownloadButton (server export) and RowsCsvDownloadButton (client-side row export).
  • Introduce CsvDownloadButton (shared presentation/state), isCsvExportEnabled(), and toDownloadReportParams() to isolate responsibilities.
  • Replace/expand unit tests to cover the new split components and helpers.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
projects/packages/premium-analytics/widgets/top-posts/render.tsx Switches Top Posts widget CSV action to RowsCsvDownloadButton (client-side rows export).
projects/packages/premium-analytics/widgets/orders-over-time/render.tsx Switches Orders Over Time widget CSV action to ReportCsvDownloadButton (server-generated export).
projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts Updates public toolkit exports to expose the split CSV helpers/components instead of the removed DownloadCsvButton.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/index.ts Re-exports the new CSV download entrypoints from the components barrel.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/to-download-report-params.ts New helper to map dashboard report params to the download API contract.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/rows-csv-download-button.tsx New wrapper for client-side CSV generation from already-loaded rows.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/report-csv-download-button.tsx New wrapper for server-side CSV exports via the report download endpoint.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/is-csv-export-enabled.ts New helper to centralize the server-provided CSV export feature gate.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/index.ts Updates the download-csv-button barrel exports to the new split API.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/download-csv-button.tsx Removes the prior combined implementation (replaced by split components).
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/csv-download-button.tsx New shared presentation component owning loading/error behavior for downloads.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/tests/to-download-report-params.test.ts Adds unit coverage for report param mapping behavior (including comparison handling).
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/tests/rows-csv-download-button.test.tsx Adds unit coverage for client-side CSV export behavior and feature gating.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/tests/report-csv-download-button.test.tsx Adds unit coverage for server-side report download behavior and graceful missing-context handling.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/tests/is-csv-export-enabled.test.ts Adds unit coverage for the feature-gate helper.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/tests/download-csv-button.test.tsx Removes tests tied to the old combined component.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/tests/csv-download-button.test.tsx Adds unit coverage for shared button presentation/state (loading, errors, iconless solid variant).
projects/packages/premium-analytics/changelog/refactor-csv-download-components Adds a changelog entry (currently missing the standard blank-line delimiter after headers).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 20 changed files in this pull request and generated no new comments.

@layoutd
layoutd marked this pull request as ready for review July 16, 2026 16:36
@layoutd
layoutd requested review from a team as code owners July 16, 2026 16:36
chihsuan
chihsuan previously approved these changes Jul 17, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for following up on the refactoring suggestion from the previous PR. @layoutd

Splitting the CSV download logic into focused components makes the code much easier to understand and review. 💯

I left two non-blocking suggestions for existing behavior I noticed while reviewing this work. Neither was introduced by this PR but it would be great to address them before merging. 🙏

Pre-approving!

layoutd added 4 commits July 17, 2026 10:39
…wnload

# Conflicts:
#	projects/packages/premium-analytics/packages/widgets-toolkit/src/components/download-csv-button/download-csv-button.module.scss
#	projects/packages/premium-analytics/widgets/top-posts/style.module.css
Base automatically changed from add/direct-report-download to trunk July 17, 2026 09:05
@layoutd
layoutd dismissed chihsuan’s stale review July 17, 2026 09:05

The base branch was changed.

chihsuan
chihsuan previously approved these changes Jul 17, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @layoutd Looks good!

Confirmed error snackbar is shown.

Image

@layoutd
layoutd force-pushed the refactor/csv-download-components branch from f7a203c to 2972c33 Compare July 17, 2026 22:38
@layoutd
layoutd merged commit 3f5e3b8 into trunk Jul 17, 2026
72 checks passed
@layoutd
layoutd deleted the refactor/csv-download-components branch July 17, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Premium Analytics [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants