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 3 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]>
};

fetchSummaryAgent();
}, [props, props.httpSetup]);
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.

We should listen to dataSourceId change, listening to props change is too generic. And if the resultSummaryEnabled is false, we do not need to check if agents exists.

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

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~

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.

2 participants