Skip to content

GITHUB-170 Added: Select All toggles to toggle lists.#292

Merged
Dan0sz merged 5 commits intodevelopfrom
select_all_toggle
Mar 26, 2026
Merged

GITHUB-170 Added: Select All toggles to toggle lists.#292
Dan0sz merged 5 commits intodevelopfrom
select_all_toggle

Conversation

@Dan0sz
Copy link
Collaborator

@Dan0sz Dan0sz commented Mar 26, 2026

Started over, because #268 had merge conflicts, and that approach was wrong anyway.

This PR properly addresses #170 and adds a Select all toggle right above any list of toggles.

7fAVmfY.1.mp4

Summary by CodeRabbit

  • New Features
    • Added a "Select All/None" bulk toggle for analytics settings sections, enabling users to quickly enable or disable multiple options simultaneously. The bulk toggle state automatically synchronizes when individual options are toggled.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 26, 2026

Warning

Rate limit exceeded

@Dan0sz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9b62b7ed-cb4a-4e50-b280-ee57c108ae2d

📥 Commits

Reviewing files that changed from the base of the PR and between 43d4d24 and a49e918.

📒 Files selected for processing (2)
  • src/Admin/Settings/API.php
  • src/Ajax.php
📝 Walkthrough

Walkthrough

The changes introduce a bulk toggle feature enabling users to select or deselect all options in a grouped checkbox field at once. The implementation includes frontend JavaScript for handling bulk toggle clicks and synchronization, backend rendering logic to display the bulk toggle UI when multiple checkboxes exist, and a new AJAX handler to process bulk toggle requests and update settings.

Changes

Cohort / File(s) Summary
Frontend bulk toggle interaction
assets/src/js/admin/main.js
Added bulkToggle(e) handler to detect bulk toggle clicks, update all grouped toggle UI states, conditionally expand/collapse collapsible sections, and send AJAX POST request. Added syncBulkToggle(container) to synchronize bulk toggle UI based on individual toggle states. Updated individual toggle handling to sync bulk toggle state after changes.
Backend bulk toggle infrastructure
src/Admin/Settings/API.php, src/Ajax.php
Modified render_group_field() to render a "Select all" bulk toggle UI when multiple checkbox fields are present, computing checked state from saved settings. Added new bulk_toggle_options() AJAX handler to validate requests, process bulk toggle updates by adding/removing option values, and persist changes to plausible_analytics_settings.

Sequence Diagram

sequenceDiagram
    actor User
    participant Client as Client-side JS
    participant Server as AJAX Handler
    participant Storage as Settings Storage
    
    User->>Client: Click bulk toggle
    Client->>Client: bulkToggle(e): Detect click,<br/>compute target state
    Client->>Client: Update all toggle UI states<br/>in .plausible-analytics-section
    Client->>Client: Conditionally open/close<br/>collapsible sections
    Client->>Server: POST plausible_analytics_bulk_toggle<br/>(options payload + nonce)
    Server->>Server: bulk_toggle_options():<br/>Validate nonce & permissions
    Server->>Server: Parse options, build<br/>settings update payload
    Server->>Storage: Update plausible_analytics_settings<br/>(add/remove values)
    Storage-->>Server: Confirm update
    Server-->>Client: wp_send_json_success()
    Client->>Client: syncBulkToggle(container):<br/>Update bulk toggle UI state
    Client-->>User: Display confirmation
Loading

Possibly related PRs

  • Toggle columns #291: Modifies the same render_group_field() function in src/Admin/Settings/API.php affecting group rendering behavior and structure.

Poem

🐰 With a click, a toggle so bright,
All checkboxes dance left and right,
Select or clear the whole cohort—
A rabbit's dream, bulk action support! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing 'Select All' toggles for toggle lists, which is reflected across all modified files (JavaScript functionality, PHP UI rendering, and AJAX handler).
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch select_all_toggle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Admin/Settings/API.php`:
- Line 614: Replace the short arrow function used in the array_filter call that
builds $option_values from $fields with a PHP 7.2-compatible anonymous function:
locate the expression using fn($f) => $f['type'] === 'checkbox' and change it to
a traditional closure (function($f) { return $f['type'] === 'checkbox'; }) so
array_filter and array_column continue to work on PHP 7.2; ensure spacing and
variable names ($option_values, $fields) remain unchanged.

In `@src/Ajax.php`:
- Line 287: The options value is being unslashed twice: $this->clean() already
calls wp_unslash() for the 'options' key, so remove the redundant wp_unslash()
call when decoding options in Ajax.php; replace json_decode( wp_unslash(
$post_data['options'] ), true ) with json_decode( $post_data['options'], true )
so json_decode receives the already-cleaned string (refer to the $this->clean()
behavior and the options handling in the Ajax class).
- Around line 293-307: The loop processing $options uses $name to index
$settings without checking existence/type, causing warnings; update the foreach
handling (the block that reads $name/$value/$status and calls in_array() and
array_search() on $settings[$name]) to first ensure isset($settings[$name]) and
is_array($settings[$name]) — either skip invalid names or initialize
$settings[$name] = [] before using in_array() or array_search(), and then
proceed to add with $settings[$name][] or unset by key; ensure you reference the
same $name/$value/$status variables and maintain the existing
sanitize_text_field calls.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 036a12f8-9d33-4bc8-80f4-dd58c363007f

📥 Commits

Reviewing files that changed from the base of the PR and between c86eb05 and 43d4d24.

📒 Files selected for processing (3)
  • assets/src/js/admin/main.js
  • src/Admin/Settings/API.php
  • src/Ajax.php

Dan0sz and others added 4 commits March 26, 2026 16:59
…y operations.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Dan0sz Dan0sz merged commit 2114992 into develop Mar 26, 2026
7 checks passed
@Dan0sz Dan0sz deleted the select_all_toggle branch March 26, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant