Premium Analytics: split CSV download components - #50569
Conversation
# Conflicts: # projects/packages/premium-analytics/widgets/orders-over-time/render.tsx
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis 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. 🤷 |
There was a problem hiding this comment.
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
DownloadCsvButtonusage in widgets withReportCsvDownloadButton(server export) andRowsCsvDownloadButton(client-side row export). - Introduce
CsvDownloadButton(shared presentation/state),isCsvExportEnabled(), andtoDownloadReportParams()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). |
chihsuan
left a comment
There was a problem hiding this comment.
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!
…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
… refactor/csv-download-components
# Conflicts: # projects/packages/premium-analytics/packages/widgets-toolkit/src/components/report-page/report-records-table.module.scss
f7a203c to
2972c33
Compare

Related to WOOA7S-1671.
Proposed changes
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
pnpm jetpack build packages/premium-analytics --deps.add_filter( 'jetpack_premium_analytics_csv_exports_enabled', '__return_true' );.projects/packages/premium-analytics, run the CSV component tests andpnpm typecheck.