Skip to content

Add AI feature toggles and summary UI#301

Open
arifulhoque7 wants to merge 7 commits intoweDevsOfficial:developfrom
arifulhoque7:feature/ai-settings-summary-pro-gate
Open

Add AI feature toggles and summary UI#301
arifulhoque7 wants to merge 7 commits intoweDevsOfficial:developfrom
arifulhoque7:feature/ai-settings-summary-pro-gate

Conversation

@arifulhoque7
Copy link
Copy Markdown
Contributor

@arifulhoque7 arifulhoque7 commented Mar 2, 2026

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

Sanitize AI feature toggles server-side and add client UI for AI Doc Summary. SettingsApi: validate and normalize ai_settings.features (allowed features list), coerce enabled flags and whitelist ai_summaries.display_mode to allowed values. AiSettings.js: import Switch and Overlay, add handlers (handleFeatureToggle, handleSummaryModeChange), isPro/hasApiKey checks, and state for a pro-only overlay. Add a new settings block with a switch to enable AI Doc Summary (API-key and pro gated), radio-like controls for default display mode (summary/highlights), and update settings state when changes are made.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 2, 2026

Warning

Rate limit exceeded

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

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ 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: c9357ed9-f8d0-408a-a0e1-889278b8fcf9

📥 Commits

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

📒 Files selected for processing (1)
  • tailwind.config.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
Review rate limit: 0/1 reviews remaining, refill in 57 minutes and 58 seconds.

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

Copy link
Copy Markdown
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: 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
Server-side: enforce that ai_summaries is a PRO-only feature — if pro is inactive the feature is disabled and display_mode forced to 'summary'; when pro is active the display_mode is sanitized. Frontend: large refactor of the AiSettings component — centralize provider config retrieval, apply wp filter for provider configs, normalize state initialization and handlers (setAiSettings + setSettings), update/move AiProviderSelect and AiModelSelect to improved Listbox components, add API key presence checks, improved maskApiKey logic, disable summary controls when no API key or not PRO, and add overlay UX for PRO preview. Misc: various formatting and small UI/UX tweaks.
Copy link
Copy Markdown
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/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
Make AiSettings robust to missing or non-object provider.models by introducing a safeModels fallback and defaulting firstModel to an empty string. Use safeModels when building model option lists and labels to avoid runtime errors. Add an aria-label to the AI summaries toggle and ensure summary mode options/inputs are disabled when there is no API key as well as when not Pro, with corresponding opacity/pointer-events styling to indicate disabled state. These changes improve stability and accessibility in the AI settings UI.
Replace the ESM import and createRequire usage with a CommonJS require destructuring to import scopedPreflightStyles and isolateInsideOfContainer from 'tailwindcss-scoped-preflight'. No functional changes to rootClass; this simplifies the import and removes the need for createRequire.
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.

3 participants