GITHUB-170 Added: Select All toggles to toggle lists.#292
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe 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
Sequence DiagramsequenceDiagram
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
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
assets/src/js/admin/main.jssrc/Admin/Settings/API.phpsrc/Ajax.php
…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>
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