Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide the assistant entry when there isn't data2summary agent #417

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Qxisylolo
Copy link
Contributor

@Qxisylolo Qxisylolo commented Jan 27, 2025

Description

This pr hides the assistant entry when there isn't data2summary agent
!! This pr is a hard dependency that should be merged after opensearch-project/OpenSearch-Dashboards#9277 has been merged.

has agent:
截屏2025-01-27 13 45 13
no agent:
截屏2025-01-27 13 44 44

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test.
  • New functionality has user manual doc added.
  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Qxisylolo <[email protected]>
// The action button should be not displayed when there is no action and result summary disabled.
if (actionsRef.current.length === 0 && !resultSummaryEnabled) {
// The action button should be not displayed when there is no action and result summary disabled or there is no data2Summary agent
if (!isSummaryAgentAvailable || (actionsRef.current.length === 0 && !resultSummaryEnabled)) {
Copy link
Member

@SuZhou-Joe SuZhou-Joe Jan 27, 2025

Choose a reason for hiding this comment

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

Nit: I'd recommend moving isSummaryAgentAvailable behind !resultSummaryEnabled because we need to make a network request to get the status.

public/plugin.tsx Outdated Show resolved Hide resolved
Comment on lines 47 to 56
async function checkAgentsExist(
http: HttpSetup,
agentConfigName: string | string[],
dataSourceId?: string
) {
const response = await http.get(AGENT_API.CONFIG_EXISTS, {
query: { agentConfigName, dataSourceId },
});
return response;
}
Copy link
Member

Choose a reason for hiding this comment

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

We should move this function out of render function.

return null;
}

// The action button should be disabled when context menu has no item and result summary disabled.
// The action button should be disabled when context menu has no item and result summary disabled
const actionDisabled = (panels.value?.[0]?.items ?? []).length === 0 && !resultSummaryEnabled;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const actionDisabled = (panels.value?.[0]?.items ?? []).length === 0 && !resultSummaryEnabled;
const actionDisabled = (panels.value?.[0]?.items ?? []).length === 0 && !resultSummaryEnabled && !isSummaryAgentAvailable;

Do we need to add check on isSummaryAgentAvailable?

Copy link
Contributor Author

@Qxisylolo Qxisylolo Jan 27, 2025

Choose a reason for hiding this comment

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

I add this check at first, but if there isn't agent, should we hide the button instead of disabling it?

Copy link
Member

Choose a reason for hiding this comment

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

I think it is OK that we check on both places, but sure it is good enough if we will hide the button if no summary agent is available on target data source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update~ and thanks for all the comments

useEffect(() => {
const fetchSummaryAgent = async () => {
try {
const summaryAgentStatus = await checkAgentsExist(
Copy link
Member

@SuZhou-Joe SuZhou-Joe Jan 27, 2025

Choose a reason for hiding this comment

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

Do we need to call props.isSummaryAgentAvailable$.next(false) before making the call to check if agent exists? if we switch from data source A(agent configured) to data source B (agent not configured) and the call somehow failed, the status will be incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it's import, sorry I forget it., updated~

// The action button should be not displayed when there is no action and result summary disabled.
if (actionsRef.current.length === 0 && !resultSummaryEnabled) {
// The action button should be not displayed when there is no action and result summary disabled or there is no data2Summary agent
if ((!resultSummaryEnabled && actionsRef.current.length === 0) || !isSummaryAgentAvailable) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we need to allow other actions to be displayed if the summary agent is not available? The other actions won't be displayed if the summary agent is not available after the current change. Is it possible to not register the summary action if the summary agent is not available?

Copy link
Member

Choose a reason for hiding this comment

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

The other action includes anomaly detection suggestion and generate visualization, right? If yes, They should be displayed even if their agents are configured, should not be impacted by summary agent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comments, already updated, now the UI context bar will be disabled only when there isn't actions and result summary disabled or or no data2Summary agent is available

Copy link

codecov bot commented Feb 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.03%. Comparing base (581a7ca) to head (b2b3469).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #417      +/-   ##
==========================================
- Coverage   87.46%   85.03%   -2.44%     
==========================================
  Files          65       72       +7     
  Lines        1891     2105     +214     
  Branches      473      518      +45     
==========================================
+ Hits         1654     1790     +136     
- Misses        236      313      +77     
- Partials        1        2       +1     

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

@@ -39,6 +43,26 @@ export const ActionContextMenu = (props: Props) => {
});
const resultSummaryEnabled = useObservable(props.resultSummaryEnabled$, false);
const isQuerySummaryCollapsed = useObservable(props.isQuerySummaryCollapsed$, false);
const isSummaryAgentAvailable = useObservable(props.isSummaryAgentAvailable$, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to add a shouldShowSummarizationAction flag here. Something like

const shouldShowSummarizationAction = resultSummaryEnabled && isSummaryAgentAvailable;

We always need to check resultSummaryEnabled and isSummaryAgentAvailable when we need to determine if this action can be displayed. I'm suggest to combine them in same flag. It can improve the code readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it's a good advice, update~

public/components/ui_action_context_menu.tsx Outdated Show resolved Hide resolved
public/components/ui_action_context_menu.tsx Show resolved Hide resolved
public/components/ui_action_context_menu.tsx Show resolved Hide resolved
Signed-off-by: Qxisylolo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants