feat(export): add an options dialog to the CSV exports (NPPD-2231) - #1001
Open
adekbadek wants to merge 2 commits into
Open
feat(export): add an options dialog to the CSV exports (NPPD-2231)#1001adekbadek wants to merge 2 commits into
adekbadek wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsmKaHchCQjynvH3owGKDG
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an export-options modal for the admin “Export CSV” actions on Users and WooCommerce Subscriptions list tables, and unifies those options with the wp newspack export-users / wp newspack export-subscriptions CLI commands via a shared sanitization boundary.
Changes:
- Introduces a
<dialog>-based options UI (roles/statuses multi-select, date range, delimiter, date format, and user-meta columns) and posts a serialized config through each AJAX export step. - Extends the users/subscriptions exporters to apply the sanitized export config (query args + optional columns + delimiter + formatted dates) and ensures the headers-row temp file exists for ended-short runs.
- Adds/expands PHPUnit coverage around config sanitization, query-arg precedence rules, date handling, meta-key columns, and CLI flag validation.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| plugins/newspack-plugin/tests/unit-tests/export/class-users-csv-exporter.php | Adds tests for role precedence, registration date range behavior, and opt-in meta columns. |
| plugins/newspack-plugin/tests/unit-tests/export/class-user-meta-columns.php | New unit tests for available meta keys, sanitization, column naming, and value flattening/encoding. |
| plugins/newspack-plugin/tests/unit-tests/export/class-subscriptions-csv-exporter.php | Adds tests for status/date-range precedence and “cleared selection” semantics. |
| plugins/newspack-plugin/tests/unit-tests/export/class-csv-exports.php | Adds tests for export-config sanitization, date formatting, delimiter propagation, and column recomputation. |
| plugins/newspack-plugin/tests/unit-tests/export/class-csv-exports-handlers.php | Extends handler tests to verify header-row temp file existence for short runs. |
| plugins/newspack-plugin/src/csv-export/style.scss | Styles the new export options dialog and its form controls. |
| plugins/newspack-plugin/src/csv-export/index.js | Updates the export flow to open the modal, serialize options, and replay them through each AJAX step. |
| plugins/newspack-plugin/includes/export/class-users-csv-exporter.php | Applies export config to query args, adds meta columns, and formats registration dates consistently with config. |
| plugins/newspack-plugin/includes/export/class-user-meta-columns.php | New helper for discovering, sanitizing, and exporting user-meta columns. |
| plugins/newspack-plugin/includes/export/class-subscriptions-csv-exporter.php | Applies export config to status/date filters and formats date columns via shared formatting logic. |
| plugins/newspack-plugin/includes/export/class-csv-exports.php | Renders modal(s), sanitizes posted export config, and threads config into export execution + download constraints. |
| plugins/newspack-plugin/includes/export/class-csv-batch-exporter.php | Adds export-config storage, delimiter/columns recompute, date-formatting helper, and header-row file enforcement. |
| plugins/newspack-plugin/includes/cli/class-export.php | Adds CLI flags for the same export options and validates that CLI-supplied restrictions survive sanitization. |
Suppressed comments (1)
plugins/newspack-plugin/includes/export/class-csv-exports.php:487
- The helper text for the Statuses checkbox group is misleading on the Subscriptions Trash view. When the list is filtered to Trash, clearing all checkboxes still keeps the Trash filter (by design), so the copy shouldn’t claim it will export every status in all cases.
<fieldset class="newspack-csv-export-modal__field" aria-describedby="<?php echo \esc_attr( $id ); ?>-statuses-desc">
<legend><?php \esc_html_e( 'Statuses', 'newspack-plugin' ); ?></legend>
<p class="description" id="<?php echo \esc_attr( $id ); ?>-statuses-desc"><?php \esc_html_e( 'Leave all unchecked to export every status.', 'newspack-plugin' ); ?></p>
<div class="newspack-csv-export-modal__checkboxes">
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsmKaHchCQjynvH3owGKDG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
The CSV exports on the Users and Subscriptions list tables were a bare button with no options, so publishers coming off WooCommerce Memberships lost controls the member export had. "Export CSV" now opens a dialog, prefilled from the filters already applied to the list.
It holds a creation/registration date range on both exports, multi-role selection on users (core allows one role at a time), multi-status on subscriptions (the status tabs are one at a time), a delimiter choice, and a date format. A picker offers the user meta keys the site actually stores, adding one column per key — that covers the registration fields Memberships collected, and anything a form plugin writes.
Clearing every checkbox means "all", overriding the filter the dialog was opened on. A list view the dialog has no control for keeps its filter instead: core's role-less
?role=noneand the subscriptions Trash tab were never offered a box to clear, and dropping them would silently widen a PII export.The same options are on
wp newspack export-usersandwp newspack export-subscriptions. Unlike the dialog, whose values come from a list the server rendered, the CLI rejects a flag value it does not recognize rather than dropping it — a mistyped--roleused to narrow to nothing and would otherwise now widen to everything.Two behaviour changes worth knowing about:
Registered Dateis written in the site's timezone. It was UTC, which would contradict the date range that selected the row.Closes NPPD-2231.
How to test the changes in this Pull Request:
D, d M Y.wp newspack export-users --role=subscrber. The command stops with "Unrecognized --role value".wp newspack export-users --meta=<a key from the picker> --date-from=2024-01-01. The file holds that column.Other information:
Base is
releaseper the ticket's hotfix note; the forward-port tomain/alphais automatic.n test-php --group csv-exportpasses at 62 tests; the full newspack-plugin suite passes at 2929.Gate/plan and computed-access columns (the ticket's item 5), and merging the subscription columns into a single export (item 4), are follow-ups.