fix(comments): clear table selection after bulk moderation#293
Merged
Conversation
After a bulk action, the acted-on rows leave the current tab but <wpd-table> intentionally preserves its selection set across data refreshes (stale ids are only hidden at paint time). The stale ids lingered in table.selection, so the next row the user selected showed "2 selected" and a follow-up bulk action operated on the phantom id too: trashing a comment then spamming a different one also spammed the already-trashed comment. Reset the selection after a successful bulk action via table.clearSelection(), which also emits wpd-table-selection-change to refresh the "N selected" chip and hide the bulk bar. This covers every moderation path, since the bulk buttons and the j/k/a/s/d keyboard shortcuts all route through runBulk.
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.
Summary
Fixes a selection-state bug in the Comments window: after a bulk action, the acted-on comment's id stayed in the table's selection set, so the next selection read as "2 selected" and the following bulk action also hit the previously-actioned comment.
Steps to reproduce
Root cause
<wpd-table>deliberately keeps its selection acrossdatarefreshes (stale ids are filtered out only at paint time, to support cross-page selection). The Comments window never cleared the selection after a bulk action, so trashed/spammed ids lingered intable.selection. Setting.datadoesn't emitwpd-table-selection-change, so the "N selected" chip didn't refresh either.Fix
After a successful bulk action,
runBulkcallsstate.table.clearSelection(). That emitswpd-table-selection-change, which resets the "N selected" chip and hides the bulk bar. This covers every moderation path (the bulk buttons and thej/k/a/s/dkeyboard shortcuts all route throughrunBulk).Testing
npm run build,npm run lint,npm run typecheck, andnpm run test:js(1519 tests) all pass.