Skip to content

Conversation

ananzh
Copy link
Member

@ananzh ananzh commented Oct 3, 2025

Description

We want to disable contextProvider and chat completely from browser and server side when no explore or when not config/ Need to use contextProvider as optionalPlugins not requiredBundles. Otherwise contextProvider will be loaded into browser. In this PR we change to use dependency injection for contextProvider. The challenge is that React hooks can't be passed through dependency injection in the traditional way because they need to be called at the component level and follow the rules of hooks. Therefore, we need to update the contextProvider plugin to 1) expose its hooks through the plugin's start interface, so they can be accessed via dependency injection 2) add a server side. Otherwise no way to read configuration from opensearch_dashboards.yml so plugin always loaded in browser regardless of settings. Also without server we could not use optionalPlugins pattern (requires server component). No change on how we use the hooks, only change how we import them.

  • Fixed chat.enabled to properly disable plugin when set to false or when chat.agUiUrl is missing
  • Added contextProvider.enabled with server-side validation and dependency injection pattern

Both server side and browser:

No chat when explore is enabled but chat.enabled is false or no chat.agUiUrl.
No contextProvider when explore is enabled but contextProvider.enable is false
Screenshot 2025-10-02 at 9 34 13 PM
Screenshot 2025-10-02 at 9 33 49 PM

Setup chat when explore is enabled and both chat.enabled and chat.agUiUrl are configed.
Setup contextProvider when explore is enabled and contextProvider.enable is true
Screenshot 2025-10-02 at 9 33 39 PM

Screenshot 2025-10-02 at 9 30 34 PM

No chat or contextProvider when no explore
Screenshot 2025-10-02 at 9 34 56 PM

Issues Resolved

NA

Changelog

  • feat: chat(feat): implement plugin configuration controls for chat and context_provider plugins

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

…ext_provider plugins

Fixed chat.enabled to properly disable plugin when set to false or when agUiUrl is missing
Added contextProvider.enabled with server-side validation and dependency injection pattern

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
opensearch-changeset-bot bot added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Oct 3, 2025
Copy link

codecov bot commented Oct 3, 2025

Codecov Report

❌ Patch coverage is 35.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.17%. Comparing base (81d5f81) to head (05a88fe).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/plugins/context_provider/public/plugin.ts 0.00% 11 Missing ⚠️
src/plugins/context_provider/public/index.ts 0.00% 1 Missing ⚠️
...s/query_panel/actions/ppl_execute_query_action.tsx 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10639      +/-   ##
==========================================
- Coverage   60.18%   60.17%   -0.01%     
==========================================
  Files        4428     4428              
  Lines      118504   118519      +15     
  Branches    19456    19460       +4     
==========================================
- Hits        71319    71318       -1     
- Misses      42269    42279      +10     
- Partials     4916     4922       +6     
Flag Coverage Δ
Linux_1 26.65% <ø> (ø)
Linux_2 38.83% <ø> (ø)
Linux_3 38.71% <20.00%> (+<0.01%) ⬆️
Linux_4 ?
Windows_1 26.66% <ø> (ø)
Windows_2 38.80% <ø> (ø)
Windows_3 38.72% <20.00%> (-0.01%) ⬇️
Windows_4 32.71% <80.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ashwin-pc ashwin-pc added v3.3.0 Issues targeting release v3.3.0 backport 3.3 labels Oct 3, 2025
ashwin-pc
ashwin-pc previously approved these changes Oct 3, 2025
Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

Im generally okay with this approach, but can you have @Maosaic review the prop drilling of the services and if that impacts the page performance.

Maybe we can skip moving the code to an optional plugin.I dont like exposing hooks as a part of the service. The context framework plugin can be bundled with the code, just ignored in all codepaths except explore since it is not imported anywhere else

Comment on lines 33 to 37
const ExplorePageContextProvider: React.FC<{
children: React.ReactNode;
}> = ({ children }) => {
services: ExploreServices;
}> = ({ children, services }) => {
const usePageContext = services.contextProvider?.hooks?.usePageContext || (() => {});

Copy link
Collaborator

Choose a reason for hiding this comment

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

we sould only pass usePageContext into ExplorePageContextProvider to minimal rerender.

Also, we are not creating any context here, is this intended? Why we are calling it ContextProvider?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could pass usePageContext into that. But I don't think it would causes any re-render as it is only used once in the component and not passed to child components as props. Also the usePageContext hook itself handles the function internally.

Copy link
Member Author

Choose a reason for hiding this comment

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

The ExplorePageContextProvider component is not creating a React Context Instead, it just uses the hook which can automatically capture page context from URL state. Basically it is to convert the URL state to the format needed. I could re-name it as ExplorePageContextRegister.

scrollToTop={scrollToTop}
onAddColumn={onAddColumn}
onRemoveColumn={onRemoveColumn}
services={services}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why drilling services prop? can we use useOpenSearchDashboards<ExploreServices>() in child component when we need services`?

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 will update

@Maosaic
Copy link
Collaborator

Maosaic commented Oct 3, 2025

Should we split the changes that consuming context_provider plugin in Explore into a different PR?

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants