Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/components/Settings/AiSettings.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
/**
* AI Settings Component
*
*
* Centralized AI Control Settings panel for weDocs that allows admins to configure
* and manage API integrations with multiple AI providers.
*
*
* Available WordPress Filters:
*
*
* @filter wedocs_ai_provider_configs
* Allows customization of AI provider configurations including available models.
* Used in the settings UI to display provider options and model selections.
*
* @filter wedocs_ai_service_providers
*
* @filter wedocs_ai_service_providers
* Allows customization of AI service provider configurations for the AI service utility.
* Used for API calls and provider management in the backend.
*
*
* @filter wedocs_ai_settings_fields
* Allows injection of additional settings fields into the AI Settings panel.
* Receives: (fields, settingsData, aiSettingsData, setSettings)
* Return: JSX elements to render additional fields.
Comment on lines +17 to +20

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Pass the live aiSettings state through this hook.

Line 767 currently exposes aiSettingsData, but this panel edits and renders from local aiSettings. That makes injected fields one render behind after handleProviderChange / handleDefaultProviderChange, and a callback that writes back through setSettings can clobber a just-made provider/model change with the stale snapshot. Keep this extension point aligned with wedocs_ai_settings_after_model by passing aiSettings here and documenting that contract.

Suggested fix
- * Receives: (fields, settingsData, aiSettingsData, setSettings)
+ * Receives: (fields, settingsData, aiSettings, setSettings)
...
                         {wp.hooks.applyFilters(
                           'wedocs_ai_settings_fields',
                           null,
                           settingsData,
-                          aiSettingsData,
+                          aiSettings,
                           setSettings
                         )}

Also applies to: 767-773

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/Settings/AiSettings.js` around lines 17 - 20, The
wedocs_ai_settings_fields hook is still receiving aiSettingsData instead of the
live aiSettings state, so injected fields can render one step behind and
overwrite recent provider/model changes. Update the hook invocation inside
AiSettings to pass aiSettings through this extension point, and align the hook
contract/docs with wedocs_ai_settings_after_model so consumers know they receive
the current local state.

* @since 2.0.1
*
* @since 2.0.0
*/

Expand Down Expand Up @@ -756,6 +762,15 @@ const AiSettings = ({
{!wp.hooks.applyFilters('wedocs_pro_loaded', false) && (
<AiImageAnalysisPreview />
)}

{/* Additional fields injected via hook */}
{wp.hooks.applyFilters(
'wedocs_ai_settings_fields',
null,
settingsData,
aiSettingsData,
setSettings
)}
</div>
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions src/components/Settings/GeneralSettings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* General Settings Component
*
* Provides the main settings panel for weDocs including documentation home,
* email feedback, searchbar, helpful feedback, comments, and printing options.
*
* Available WordPress Filters:
*
* @filter wedocs_general_settings_fields
* Allows injection of additional settings fields into the General Settings panel.
* Receives: (fields, settingsData, generalSettingsData, setSettings)
* Return: JSX elements to render additional fields.
*
* @since 2.0.1
*/

import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import Switcher from '../Switcher';
Expand Down Expand Up @@ -526,6 +542,14 @@ const GeneralSettings = ( {
</div>
</div>
</div>
{/* Additional fields injected via hook */}
{wp.hooks.applyFilters(
'wedocs_general_settings_fields',
null,
settingsData,
generalSettingsData,
setSettings
)}
</div>
</div>
</div>
Expand Down
Loading