fix(newsletters): hide abandoned auto-drafts from lists (DSGNEWS-213) - #853
fix(newsletters): hide abandoned auto-drafts from lists (DSGNEWS-213)#853thomasguillot wants to merge 4 commits into
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the Newspack Newsletters admin-shell lists (Newsletters, Ads, Layouts) and related REST/query plumbing to exclude auto-draft rows, preventing abandoned “Add New” auto-drafts from appearing as (no subject) / (no title) entries. It also updates advertiser term counting to match the new ads list semantics and adds/adjusts tests to lock in the behavior.
Changes:
- Remove
auto-draftfrom default status sets and “Draft” bucket/status widening logic in both JS list queries and PHP REST query helpers. - Update ads advertiser term counting (and its recount sentinel) to exclude
auto-draftrows so counts match what the UI lists. - Expand and adjust PHPUnit/Jest coverage to ensure
auto-draftdoes not re-enter via filters/widening.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| plugins/newspack-newsletters/tests/test-newsletters-list-rest.php | Updates REST alignment tests and adds coverage ensuring auto-draft never re-enters Draft/default status queries. |
| plugins/newspack-newsletters/tests/test-advertisers-list-rest.php | Updates advertiser count tests for the new “exclude auto-draft” semantics and sentinel bump. |
| plugins/newspack-newsletters/tests/test-ads-list-rest.php | Updates Ads REST bucketing tests to ensure Draft kind excludes auto-draft. |
| plugins/newspack-newsletters/src/admin-shell/screens/newsletters-list/initial-filters.test.js | Updates expected draft filter mapping for legacy post_status=auto-draft deep links. |
| plugins/newspack-newsletters/src/admin-shell/screens/newsletters-list/initial-filters.js | Keeps legacy auto-draft deep-link mapping but maps it to draft,pending. |
| plugins/newspack-newsletters/src/admin-shell/screens/newsletters-list/fields.js | Updates the Draft status filter option to draft,pending. |
| plugins/newspack-newsletters/src/admin-shell/screens/newsletters-list/build-query.test.js | Adds assertions that default and filtered queries never include auto-draft. |
| plugins/newspack-newsletters/src/admin-shell/screens/newsletters-list/build-query.js | Removes auto-draft from the default newsletters list status set. |
| plugins/newspack-newsletters/src/admin-shell/screens/layouts-list/use-layouts-data.js | Removes auto-draft from layouts list default status set. |
| plugins/newspack-newsletters/src/admin-shell/screens/ads-list/build-query.test.js | Adds assertion that ads list default status set excludes auto-draft. |
| plugins/newspack-newsletters/src/admin-shell/screens/ads-list/build-query.js | Removes auto-draft from the default ads list status set. |
| plugins/newspack-newsletters/includes/ads/class-ads.php | Updates advertiser term count query and recount sentinel to drop auto-draft. |
| plugins/newspack-newsletters/includes/admin/class-newsletters-list-rest.php | Updates status widening/bucketing logic to ensure Draft no longer includes auto-draft. |
| plugins/newspack-newsletters/includes/admin/class-ads-list-rest.php | Updates Draft-kind bucketing to exclude auto-draft in Ads list REST filtering. |
💡 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 (1M context) <noreply@anthropic.com>
Code reviewRelease risk: LOW. Approve with comments. The part I most wanted to put under test was the three-way coupling, and it held. The JS status sets, both REST draft buckets, and the advertiser count query all move together, so the claim in the description that changing the JS alone would have been a no-op is correct: Verified on a local site with four pre-existing abandoned auto-drafts. Before the change, the All Newsletters heading read 117 with four Concerns ruled out:
Seven findings, none blocking. SuggestionsSeverity: suggestion · A status request of only Severity: suggestion · The re-armed recount is an uncapped per-term loop whose sentinel is written last. The Risk if not addressed: if a site with a large advertiser taxonomy takes a burst of traffic to Consider: claiming the sentinel before the loop instead of after it, and skipping the work for requests that cannot manage the taxonomy, so a burst of concurrent requests during the upgrade window does the recount once rather than once each. Severity: suggestion · The counted status set is hand-duplicated in three places. Consider: deriving the counted status set from a single shared constant used by the count query, the REST draft bucket, and the JavaScript default. As written, a later change to one of the three leaves the advertiser counts disagreeing with the Ads list, and because counts are only recomputed when a term is edited, that disagreement persists silently until someone bumps the sentinel again. NitsSeverity: nit · Stale Severity: nit · The query half of Severity: nit · Layouts is the only changed list with nothing locking the new behaviour. Newsletters and Ads each got a JS assertion that the default set does not contain Severity: nit · The superseded Spec alignmentDSGNEWS-213 asked for the abandoned auto-draft to be discarded on abandonment, and cautioned against changing what the list displays because "other in-progress auto-drafts still need to show". This PR takes the opposite route and says why: any save promotes an auto-draft to |
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Final passAll seven findings are addressed in A status request of only The recount claims its sentinel before doing the work, and skips requests that cannot manage the taxonomy. The counted status set has a single source. The superseded The unreachable Layouts has a test seam.
On the comments: the same "an abandoned Add new is empty by construction" note had been repeated in five files. It now appears once, next to the newsletters Verification: JS 253/253 across 30 suites, PHP 738/738 with 3042 assertions, |
All Submissions:
Changes proposed in this Pull Request:
"Add Newsletter" links to
post-new.php, and WordPress inserts an auto-draft as soon as that page loads, before the layout picker opens. Leaving the picker without choosing a layout left that row in the Newsletters list as a(no subject)entry, because the list queriedauto-draftalongside the writable statuses.All three admin-shell lists (Newsletters, Newsletter Ads, Layouts) now exclude
auto-draft, matching core's own Posts and Pages lists. Nothing is deleted here; core's daily cron force-deletes auto-drafts after 7 days.Any save promotes an auto-draft to
draft(core-data'sprePersistPostTypeforces the status and clears the placeholder title), so a row still sitting inauto-drafthas never been saved and its stored content is always empty. There is no in-progress newsletter to lose.Two coupled pieces move with it. The REST draft buckets re-widened
auto-draftback intopost_status, so changing the JS alone would have done nothing. And advertiser term counts deliberately counted auto-draft ads to match the Ads draft bucket, so they drop it too, with the recount sentinel bumped so existing sites refresh.Closes DSGNEWS-213.
How to test the changes in this Pull Request:
(no subject)row appears and the count is unchanged.(no subject).Other information:
Have you added an explanation of what your changes do and why you'd like us to include them?
Have you written new tests for your changes, as applicable?
Have you successfully run tests with your changes locally?
No deletion path ships here. Existing stray rows stay in the database, invisible, until core's 7-day cron clears them.
The advertiser recount is a one-time pass per site, triggered on the first
admin_initafter this deploys.