Skip to content

Forms: scope-aware Delete Spam button (selection, filter, all)#48130

Open
enejb wants to merge 3 commits intotrunkfrom
add/form-trash-spam-flow
Open

Forms: scope-aware Delete Spam button (selection, filter, all)#48130
enejb wants to merge 3 commits intotrunkfrom
add/form-trash-spam-flow

Conversation

@enejb
Copy link
Copy Markdown
Member

@enejb enejb commented Apr 16, 2026

Fixes FORMS-678

Proposed changes

  • Make the "Delete spam" button scope-aware — it now respects selected items, active filters (search, source, date range, read/unread), or falls back to deleting all spam (legacy behavior).
  • The button label adapts: shows Delete spam when unfiltered, or Delete spam (N) when filters or selection are active, reflecting how many responses will be affected.
  • The confirmation modal now shows the exact count of affected responses in a scope-aware title (e.g. "Delete 42 matching spam responses?") using VStack/Heading/Text components for consistent styling.
  • Backend: extended DELETE /wp/v2/feedback/trash to accept post_ids[] and filter params (search, parent, source, before, after, is_unread), with batched processing (1000 IDs per iteration) and source-filter hook lifecycle managed outside the batch loop.

Related product discussion/links

  • p1776216218689629-slack-C086RGTJT1D

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

The existing jetpack_forms_empty_spam_click analytics event now includes scope (selection|filtered|all) and count properties.

Testing instructions

  1. Go to a site with Jetpack Forms and seed some spam responses (at least 20, spread across 2+ forms, some containing a known substring like "BUYCHEAP").
  2. Navigate to Forms → Responses → Spam tab.

Test: unfiltered (legacy behavior)

  1. With no filters or selection active, the button should read "Delete spam" (no count).
  2. Click it → modal should show total spam count in the title (e.g. "Delete all 20 spam responses?") and "This action cannot be undone." body text.
  3. Click "Delete forever" → all spam is deleted, snackbar confirms count.

Test: filtered scope

  1. Re-seed spam. Type a search string (e.g. "BUYCHEAP") that matches a subset.
  2. Button should now read "Delete spam (N)" where N is the matching count.
  3. Click → modal title shows "Delete N matching spam responses?".
  4. Confirm → only matching spam is deleted; non-matching spam remains.

Test: source filter

  1. Re-seed spam. Use the source/form dropdown to filter to one form.
  2. Confirm the button count matches, and deletion only affects that form's spam.

Test: selection scope

  1. Re-seed spam. Select 3 specific rows manually.
  2. Button should read "Delete spam (3)".
  3. Click → modal title shows "Delete 3 selected spam responses?".
  4. Confirm → exactly those 3 are deleted; rest untouched.

Test: zero matches

  1. Search for a string with no matches → button should be disabled.

Test: existing Empty Trash behavior

  1. Go to the Trash tab → "Delete trash" button should still work as before (no regression).

enejb and others added 2 commits April 16, 2026 08:55
The "Delete spam" button previously ignored the user's current context
and permanently deleted every spam response. Now it respects:

- Selected items (post_ids) — deletes only the selected rows
- Active filters (search, source, date range, read/unread) — deletes
  every spam response matching the current view across all pages
- No selection or filter — deletes all spam (legacy behavior)

Backend: extended DELETE /wp/v2/feedback/trash to accept post_ids[] and
filter params (search, parent, source, before, after, is_unread).
Added fetch_bulk_scope_batch() helper with source-filter hook lifecycle
managed outside the batch loop for efficiency.

Frontend: useEmptySpam now computes scope (selection > filtered > all),
button label shows count when filters are active, and the confirmation
modal displays the affected count in a scope-aware title using
VStack/Heading/Text components.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@enejb enejb added the [Status] Needs Review This PR is ready for review. label Apr 16, 2026
@enejb enejb self-assigned this Apr 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/form-trash-spam-flow branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/form-trash-spam-flow

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@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!

Update the second call site in use-page-header-details.tsx to use the
new scopeMode/count props instead of the removed totalItemsSpam and
selectedResponsesCount props. Also update the useMemo dependency array.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control bot commented Apr 16, 2026

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant