Add AI feature toggles and summary UI#301
Conversation
|
Warning Review limit reached
Next review available in: 46 minutes Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable usage-based reviews in Billing to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information, and refer to the rate limits docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds server-side sanitization for AI feature toggles and a frontend overhaul introducing PRO-gated AI Doc Summary controls, provider/model selection, API key handling, and summary display-mode options (summary or highlights). Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/components/Settings/AiSettings.js (1)
604-608: Make PRO overlay trigger keyboard-accessible too.The overlay is currently hover-only (
onMouseEnter/onMouseLeave), so keyboard users won’t get the same upgrade prompt.Suggested refinement
<div className="col-span-4 relative" onMouseEnter={ () => ! isPro && setShowSummaryOverlay( true ) } onMouseLeave={ () => setShowSummaryOverlay( false ) } + onFocusCapture={ () => ! isPro && setShowSummaryOverlay( true ) } + onBlurCapture={ (e) => { + if ( ! e.currentTarget.contains( e.relatedTarget ) ) { + setShowSummaryOverlay( false ); + } + } } >Also applies to: 726-726
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Settings/AiSettings.js` around lines 604 - 608, The PRO overlay is triggered only by mouse events (onMouseEnter/onMouseLeave) so keyboard users miss it; make the same element keyboard-accessible by also handling focus and blur (add onFocus and onBlur to call setShowSummaryOverlay(true/false)) and handle activation via keyboard (add onKeyDown handler on the same element to toggle or open the upgrade prompt when Enter/Space is pressed, respecting isPro and using setShowSummaryOverlay/open-upgrade logic). Update the element that currently uses onMouseEnter/onMouseLeave and the other similar occurrence (the one referencing setShowSummaryOverlay and isPro) to include these keyboard handlers and appropriate aria attributes (e.g., tabIndex and aria-haspopup/aria-expanded) so screen reader and keyboard users receive the same prompt.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@includes/API/SettingsApi.php`:
- Around line 259-279: When persisting $ai_settings['features'] ensure
server-side PRO enforcement for the 'ai_summaries' feature: inside the foreach
over $allowed_features (where $feature === 'ai_summaries') check the plugin's
PRO status (call the existing PRO-check helper — e.g. is_pro_active() or
$this->is_pro_active()) and if the site is not PRO force
$sanitized['features']['ai_summaries']['enabled'] = false and set a safe default
for $sanitized['features']['ai_summaries']['display_mode'] (e.g. 'summary')
instead of trusting the incoming $ai_settings values; keep using
sanitize_text_field for display_mode but only accept it when PRO is active.
In `@src/components/Settings/AiSettings.js`:
- Around line 694-712: The label and the input both call handleSummaryModeChange
(label onClick and input onChange), causing duplicate updates; remove the
onClick from the label and rely on the radio input's onChange (input name
"ai_summaries_display_mode", value opt.value, checked isSelected) to perform the
change, keeping the disabled logic (disabled={!isPro}) on the input and
preserving the visual/conditional classes on the label so clicks on the label
still activate the input without invoking handleSummaryModeChange twice.
---
Nitpick comments:
In `@src/components/Settings/AiSettings.js`:
- Around line 604-608: The PRO overlay is triggered only by mouse events
(onMouseEnter/onMouseLeave) so keyboard users miss it; make the same element
keyboard-accessible by also handling focus and blur (add onFocus and onBlur to
call setShowSummaryOverlay(true/false)) and handle activation via keyboard (add
onKeyDown handler on the same element to toggle or open the upgrade prompt when
Enter/Space is pressed, respecting isPro and using
setShowSummaryOverlay/open-upgrade logic). Update the element that currently
uses onMouseEnter/onMouseLeave and the other similar occurrence (the one
referencing setShowSummaryOverlay and isPro) to include these keyboard handlers
and appropriate aria attributes (e.g., tabIndex and aria-haspopup/aria-expanded)
so screen reader and keyboard users receive the same prompt.
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/components/Settings/AiSettings.js`:
- Around line 780-806: The radio inputs and label styling are only gated by
isPro but need to also be disabled when the API key is missing; update the label
class and the input's disabled prop to include the API-key presence check (e.g.,
disabled={!isPro || !hasApiKey}) and adjust the label conditional that adds
'opacity-50 pointer-events-none' to use the same combined condition so the
visual and interactive gating matches the summary toggle (affecting the label
wrapper, the <input> radio, and the handleSummaryModeChange usage).
- Around line 34-37: The code assumes provider.models exists when iterating
configs and choosing a default model; update the logic that uses
Object.keys(provider.models) (inside the configs forEach using
providerKey/provider) and the later access that sets firstModel to first element
to first defensively validate provider?.models is an object, e.g. treat
provider.models as (typeof provider?.models === 'object' ? provider.models :
{}), then call Object.keys(...) on that safe object and set firstModel to the
first key or '' when none exist; apply the same defensive fallback at both
places where provider.models is accessed.
- Around line 684-712: The Switch for ai_summaries has no programmatic label;
update the Switch component (the element using
checked={!!aiSettings.features?.ai_summaries?.enabled} and onChange={val =>
handleFeatureToggle('ai_summaries', val)}) to include an accessible name by
adding an aria-label (e.g., aria-label="AI document summary toggle" or similar
descriptive text) so screen readers can identify the control; ensure the
aria-label accurately reflects the feature being toggled.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
includes/API/SettingsApi.phpsrc/components/Settings/AiSettings.js
🚧 Files skipped from review as they are similar to previous changes (1)
- includes/API/SettingsApi.php
0e9f3b9 to
2246f3f
Compare
2246f3f to
ca25d78
Compare
PR Description — Free plugin (
wedocs)Summary
Adds the AI Doc Summary settings section to the AI Control Settings panel. The section is gated behind a PRO upgrade overlay for free users. Includes a "Default Display Mode" option to force all docs into either Summary or Highlights mode.
What's new
Removed duplicate
ai-summaryendpoint fromincludes/API/API.phpGET /wp/v2/docs/{id}/ai-summary— this is PRO-onlyAI Doc Summary settings section (
AiSettings.js)onMouseEnterwhen!isProSettings sanitization (
includes/API/SettingsApi.php)sanitize_ai_settings()now savesdisplay_modeforai_summaries['summary', 'highlights'], defaults tosummaryFiles changed
Related PRO PR
Close 171
Summary by CodeRabbit
New Features
Improvements