Skip to content

Commit

Permalink
refactor(t2viz): register the AI actions to query controls in discover (
Browse files Browse the repository at this point in the history
#327) (#328)

* refactor(t2viz): register the AI actions to query controls in discover

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

* add changelogs

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

* remove default of config entry branding.label

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

---------

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
(cherry picked from commit 9930241)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent d45d519 commit eccc09f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
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

0 comments on commit eccc09f

Please sign in to comment.