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

[Backport 2.x] refactor(t2viz): register the AI actions to query controls in discover #328

Merged
merged 1 commit into from
Sep 27, 2024
Merged
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
3 changes: 3 additions & 0 deletions common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const configSchema = schema.object({
smartAnomalyDetector: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
branding: schema.object({
label: schema.string({ defaultValue: '' }),
}),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
26 changes: 19 additions & 7 deletions public/components/ui_action_context_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

import React, { useState, useRef } from 'react';
import useAsync from 'react-use/lib/useAsync';
import { EuiButtonIcon, EuiContextMenu, EuiPopover } from '@elastic/eui';
import { EuiButtonEmpty, EuiContextMenu, EuiPopover } from '@elastic/eui';
import { i18n } from '@osd/i18n';

import { buildContextMenuForActions } from '../../../../src/plugins/ui_actions/public';
import { AI_ASSISTANT_QUERY_EDITOR_TRIGGER } from '../ui_triggers';
import { getUiActions } from '../services';
import assistantTriggerIcon from '../assets/assistant_trigger.svg';

export const ActionContextMenu = () => {
interface Props {
label?: string;
}

export const ActionContextMenu = (props: Props) => {
const uiActions = getUiActions();
const actionsRef = useRef(uiActions.getTriggerActions(AI_ASSISTANT_QUERY_EDITOR_TRIGGER));
const [open, setOpen] = useState(false);
Expand All @@ -38,12 +42,20 @@ export const ActionContextMenu = () => {
return (
<EuiPopover
button={
<EuiButtonIcon
<EuiButtonEmpty
color="text"
aria-label="AI assistant trigger button"
size="s"
iconType={assistantTriggerIcon}
size="xs"
iconType="arrowDown"
onClick={() => setOpen(!open)}
/>
iconSide="right"
flush="both"
>
{props.label ||
i18n.translate('dashboardAssistant.branding.assistantActionButton.label', {
defaultMessage: 'AI assistant',
})}
</EuiButtonEmpty>
}
isOpen={open}
panelPaddingSize="none"
Expand Down
4 changes: 2 additions & 2 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ export class AssistantPlugin
id: 'assistant-query-actions',
order: 2000,
isEnabled$: () => of(true),
getComponent: () => {
return <ActionContextMenu />;
getSearchBarButton: () => {
return <ActionContextMenu label={this.config.branding.label} />;
},
},
},
Expand Down
1 change: 1 addition & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const config: PluginConfigDescriptor<ConfigSchema> = {
text2viz: true,
alertInsight: true,
smartAnomalyDetector: true,
branding: true,
},
schema: configSchema,
};
Expand Down
Loading