-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,15 +16,18 @@ import { i18n } from '@osd/i18n'; | |||||
|
||||||
import { BehaviorSubject } from 'rxjs'; | ||||||
import { useObservable } from 'react-use'; | ||||||
import { HttpSetup } from '../../../../src/core/public'; | ||||||
import { buildContextMenuForActions } from '../../../../src/plugins/ui_actions/public'; | ||||||
import { AI_ASSISTANT_QUERY_EDITOR_TRIGGER } from '../ui_triggers'; | ||||||
import { getUiActions } from '../services'; | ||||||
import { DataPublicPluginSetup } from '../../../../src/plugins/data/public'; | ||||||
|
||||||
import { AGENT_API, DATA2SUMMARY_AGENT_CONFIG_ID } from '../../common/constants/llm'; | ||||||
interface Props { | ||||||
data: DataPublicPluginSetup; | ||||||
isQuerySummaryCollapsed$: BehaviorSubject<boolean>; | ||||||
resultSummaryEnabled$: BehaviorSubject<boolean>; | ||||||
isSummaryAgentAvailable$: BehaviorSubject<boolean>; | ||||||
httpSetup: HttpSetup; | ||||||
label?: string; | ||||||
} | ||||||
|
||||||
|
@@ -39,6 +42,35 @@ export const ActionContextMenu = (props: Props) => { | |||||
}); | ||||||
const resultSummaryEnabled = useObservable(props.resultSummaryEnabled$, false); | ||||||
const isQuerySummaryCollapsed = useObservable(props.isQuerySummaryCollapsed$, false); | ||||||
const isSummaryAgentAvailable = useObservable(props.isSummaryAgentAvailable$, false); | ||||||
|
||||||
async function checkAgentsExist( | ||||||
http: HttpSetup, | ||||||
agentConfigName: string | string[], | ||||||
dataSourceId?: string | ||||||
) { | ||||||
const response = await http.get(AGENT_API.CONFIG_EXISTS, { | ||||||
query: { agentConfigName, dataSourceId }, | ||||||
}); | ||||||
return response; | ||||||
} | ||||||
|
||||||
useEffect(() => { | ||||||
const fetchSummaryAgent = async () => { | ||||||
try { | ||||||
const summaryAgentStatus = await checkAgentsExist( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it's import, sorry I forget it., updated~ |
||||||
props.httpSetup, | ||||||
DATA2SUMMARY_AGENT_CONFIG_ID, | ||||||
props.data.query.queryString.getQuery().dataset?.dataSource?.id | ||||||
); | ||||||
props.isSummaryAgentAvailable$.next(!!summaryAgentStatus.exists); | ||||||
} catch (error) { | ||||||
console.error(error); | ||||||
} | ||||||
}; | ||||||
|
||||||
fetchSummaryAgent(); | ||||||
}, [props, props.httpSetup]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
|
||||||
useEffect(() => { | ||||||
const subscription = props.data.query.queryString.getUpdates$().subscribe((query) => { | ||||||
|
@@ -75,14 +107,13 @@ export const ActionContextMenu = (props: Props) => { | |||||
[actionContext.datasetId, actionContext.datasetType, actionContext.dataSourceId] | ||||||
); | ||||||
|
||||||
// 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)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I'd recommend moving |
||||||
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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do we need to add check on There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update~ and thanks for all the comments |
||||||
|
||||||
return ( | ||||||
<EuiPopover | ||||||
button={ | ||||||
|
There was a problem hiding this comment.
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.