Skip to content

Add AI feature toggles and summary UI#301

Open
arifulhoque7 wants to merge 1 commit into
weDevsOfficial:developfrom
arifulhoque7:feature/ai-settings-summary-pro-gate
Open

Add AI feature toggles and summary UI#301
arifulhoque7 wants to merge 1 commit into
weDevsOfficial:developfrom
arifulhoque7:feature/ai-settings-summary-pro-gate

Conversation

@arifulhoque7

@arifulhoque7 arifulhoque7 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

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-summary endpoint from includes/API/API.php

    • The free plugin no longer registers GET /wp/v2/docs/{id}/ai-summary — this is PRO-only
  • AI Doc Summary settings section (AiSettings.js)

    • Enable/disable toggle (disabled when no API key or not PRO)
    • "Default Display Mode" radio buttons: Summary only (default) | Highlights only
    • Custom-styled radio buttons matching the indigo design system (no native OS controls)
    • PRO upgrade overlay on onMouseEnter when !isPro
  • Settings sanitization (includes/API/SettingsApi.php)

    • sanitize_ai_settings() now saves display_mode for ai_summaries
    • Validates against allowlist ['summary', 'highlights'], defaults to summary

Files changed

src/components/Settings/AiSettings.js   — added PRO overlay + display mode radio buttons
includes/API/API.php                     — removed ai-summary route + method (~80 lines)
includes/API/SettingsApi.php             — sanitize display_mode for ai_summaries

Related PRO PR
Close 171

Summary by CodeRabbit

  • New Features

    • Configurable AI summary display modes: Summary or Highlights-only
    • Provider and model selection for AI features
  • Improvements

    • PRO gating for premium AI capabilities with gated visuals and overlays
    • Server-side enforcement that disables Pro-only summary features when not on Pro
    • Improved API key handling with masking and clearer absence messaging
    • Streamlined AI settings UI for easier configuration and defaults handling

@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@arifulhoque7, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b906851-973e-4ff1-b03e-62626775a556

📥 Commits

Reviewing files that changed from the base of the PR and between 96cfd9b and ca25d78.

📒 Files selected for processing (2)
  • includes/API/SettingsApi.php
  • src/components/Settings/AiSettings.js

Walkthrough

Adds 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

Cohort / File(s) Summary
Backend Sanitization
includes/API/SettingsApi.php
Adds features sanitization in sanitize_ai_settings: whitelists feature keys, normalizes each to { enabled: <bool> }, enforces ai_summaries Pro-only rule (force enabled: false and display_mode: summary if Pro inactive), and restricts display_mode to summary or highlights.
Frontend UI Controls
src/components/Settings/AiSettings.js
Large refactor adding provider/model selects, feature toggles with PRO gating (notably ai_summaries), display-mode control (Summary / Highlights), API key masking/handling, Overlay and Switch UI, state/effect wiring, and default provider/model initialization.
Manifest & Dependencies
manifest_file, package.json
Updates manifest and package metadata/dependencies to support new frontend components and UI behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Feature/ai image analysis pro #287 — Modifies the same sanitize_ai_settings area to add server-side sanitization for AI features (image_analysis), indicating related sanitization work on feature blocks.

Suggested reviewers

  • iftakharul-islam
  • sapayth

Poem

🐰 I hopped through settings with a careful twitch,
Tucked toggles and providers into a neat switch.
Summary or highlights — the choice now stays bright,
PRO locks a carrot gate, keys glint in the night.
Hooray for features, all tidy and light! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding AI feature toggles and a summary UI for the settings panel with PRO gating.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef4f030 and e3304e2.

📒 Files selected for processing (2)
  • includes/API/SettingsApi.php
  • src/components/Settings/AiSettings.js

Comment thread includes/API/SettingsApi.php
Comment thread src/components/Settings/AiSettings.js Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/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

📥 Commits

Reviewing files that changed from the base of the PR and between e3304e2 and 3d27b4e.

📒 Files selected for processing (2)
  • includes/API/SettingsApi.php
  • src/components/Settings/AiSettings.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/API/SettingsApi.php

Comment thread src/components/Settings/AiSettings.js Outdated
Comment thread src/components/Settings/AiSettings.js Outdated
Comment thread src/components/Settings/AiSettings.js Outdated
@arifulhoque7 arifulhoque7 force-pushed the feature/ai-settings-summary-pro-gate branch from 2246f3f to ca25d78 Compare June 29, 2026 06:05
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.

2 participants