Skip to content

Commit

Permalink
Merge branch 'main' into lens/valueBased
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Jan 25, 2024
2 parents 3a48475 + e6d228d commit 2400cbd
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 261 deletions.
17 changes: 17 additions & 0 deletions x-pack/plugins/canvas/shareable_runtime/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ module.exports = {
],
sideEffects: false,
},
{
/**
* further process the modules exported by both monaco-editor and monaco-yaml, because;
* 1). they both use non-standard language APIs
* 2). monaco-yaml exports it's src as is see, https://www.npmjs.com/package/monaco-yaml#does-it-work-without-a-bundler
*/
test: /(monaco-editor\/esm\/vs\/|monaco-languageserver-types|monaco-marker-data-provider|monaco-worker-manager).*(t|j)sx?$/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
envName: isProd ? 'production' : 'development',
presets: [require.resolve('@kbn/babel-preset/webpack_preset')],
plugins: [require.resolve('@babel/plugin-transform-numeric-separator')],
},
},
},
{
test: /\.css$/,
exclude: /components/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer } from '../../common/mock';
import { ColumnsPopover } from './columns_popover';

// FLAKY: https://github.com/elastic/kibana/issues/174682
// FLAKY: https://github.com/elastic/kibana/issues/174683
// FLAKY: https://github.com/elastic/kibana/issues/174684
describe.skip('ColumnsPopover', () => {
describe('ColumnsPopover', () => {
let appMockRenderer: AppMockRenderer;

beforeEach(() => {
Expand Down Expand Up @@ -85,7 +82,13 @@ describe.skip('ColumnsPopover', () => {
);

userEvent.click(await screen.findByTestId('column-selection-popover-button'));
userEvent.click(await screen.findByTestId('column-selection-popover-show-all-button'));
userEvent.click(
await screen.findByTestId('column-selection-popover-show-all-button'),
undefined,
{
skipPointerEventsCheck: true,
}
);

const onSelectedColumnsChangeCallParams = selectedColumns.map((column) => ({
...column,
Expand All @@ -108,7 +111,13 @@ describe.skip('ColumnsPopover', () => {
);

userEvent.click(await screen.findByTestId('column-selection-popover-button'));
userEvent.click(await screen.findByTestId('column-selection-popover-hide-all-button'));
userEvent.click(
await screen.findByTestId('column-selection-popover-hide-all-button'),
undefined,
{
skipPointerEventsCheck: true,
}
);

await waitFor(() => {
expect(onSelectedColumnsChange).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ processors:
});

expect(pipelineInstall.contentForInstallation).toMatchInlineSnapshot(
`"{\\"processors\\":[{\\"set\\":{\\"field\\":\\"test\\",\\"value\\":\\"toto\\"}},{\\"pipeline\\":{\\"name\\":\\"global@custom\\",\\"ignore_missing_pipeline\\":true}},{\\"pipeline\\":{\\"name\\":\\"logs@custom\\",\\"ignore_missing_pipeline\\":true}},{\\"pipeline\\":{\\"name\\":\\"logs-test@custom\\",\\"ignore_missing_pipeline\\":true}}]}"`
`"{\\"processors\\":[{\\"set\\":{\\"field\\":\\"test\\",\\"value\\":\\"toto\\"}},{\\"pipeline\\":{\\"name\\":\\"global@custom\\",\\"ignore_missing_pipeline\\":true,\\"description\\":\\"[Fleet] Global pipeline for all data streams\\"}},{\\"pipeline\\":{\\"name\\":\\"logs@custom\\",\\"ignore_missing_pipeline\\":true,\\"description\\":\\"[Fleet] Pipeline for all data streams of type \`logs\`\\"}},{\\"pipeline\\":{\\"name\\":\\"logs-test@custom\\",\\"ignore_missing_pipeline\\":true,\\"description\\":\\"[Fleet] Pipeline for the \`test\` dataset\\"}}]}"`
);
});

Expand Down Expand Up @@ -231,12 +231,15 @@ processors:
- pipeline:
name: global@custom
ignore_missing_pipeline: true
description: '[Fleet] Global pipeline for all data streams'
- pipeline:
name: logs@custom
ignore_missing_pipeline: true
description: '[Fleet] Pipeline for all data streams of type \`logs\`'
- pipeline:
name: logs-test.access@custom
ignore_missing_pipeline: true
description: '[Fleet] Pipeline for the \`test.access\` dataset'
- reroute:
tag: test.access
dataset: test.reroute
Expand Down Expand Up @@ -280,7 +283,7 @@ processors:
});

expect(pipelineInstall.contentForInstallation).toMatchInlineSnapshot(
`"{\\"processors\\":[{\\"set\\":{\\"field\\":\\"test\\",\\"value\\":\\"toto\\"}},{\\"pipeline\\":{\\"name\\":\\"global@custom\\",\\"ignore_missing_pipeline\\":true}},{\\"pipeline\\":{\\"name\\":\\"logs@custom\\",\\"ignore_missing_pipeline\\":true}},{\\"pipeline\\":{\\"name\\":\\"logs-test.access@custom\\",\\"ignore_missing_pipeline\\":true}},{\\"reroute\\":{\\"tag\\":\\"test.access\\",\\"dataset\\":\\"test.reroute\\",\\"namespace\\":\\"default\\",\\"if\\":\\"true == true\\"}}]}"`
`"{\\"processors\\":[{\\"set\\":{\\"field\\":\\"test\\",\\"value\\":\\"toto\\"}},{\\"pipeline\\":{\\"name\\":\\"global@custom\\",\\"ignore_missing_pipeline\\":true,\\"description\\":\\"[Fleet] Global pipeline for all data streams\\"}},{\\"pipeline\\":{\\"name\\":\\"logs@custom\\",\\"ignore_missing_pipeline\\":true,\\"description\\":\\"[Fleet] Pipeline for all data streams of type \`logs\`\\"}},{\\"pipeline\\":{\\"name\\":\\"logs-test.access@custom\\",\\"ignore_missing_pipeline\\":true,\\"description\\":\\"[Fleet] Pipeline for the \`test.access\` dataset\\"}},{\\"reroute\\":{\\"tag\\":\\"test.access\\",\\"dataset\\":\\"test.reroute\\",\\"namespace\\":\\"default\\",\\"if\\":\\"true == true\\"}}]}"`
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,30 @@ export function addCustomPipelineAndLocalRoutingRulesProcessor(
pipeline.dataStream?.routing_rules?.find(
(rule) => rule.source_dataset === pipeline.dataStream?.dataset
)?.rules ?? [];

const customPipelineProcessors = [
{
pipeline: {
name: 'global@custom',
ignore_missing_pipeline: true,
description: '[Fleet] Global pipeline for all data streams',
},
},
{
pipeline: {
name: `${pipeline.dataStream.type}@custom`,
ignore_missing_pipeline: true,
description: `[Fleet] Pipeline for all data streams of type \`${pipeline.dataStream.type}\``,
},
},
...(pipeline.dataStream.package
? [
{
pipeline: {
name: `${pipeline.dataStream.type}-${pipeline.dataStream.package}@custom`,
// This pipeline name gets the `.integration` suffix to avoid conflicts with the pipeline name for the dataset below
name: `${pipeline.dataStream.type}-${pipeline.dataStream.package}.integration@custom`,
ignore_missing_pipeline: true,
description: `[Fleet] Pipeline for all data streams of type \`${pipeline.dataStream.type}\` defined by the \`${pipeline.dataStream.package}\` integration`,
},
},
]
Expand All @@ -107,6 +112,7 @@ export function addCustomPipelineAndLocalRoutingRulesProcessor(
pipeline: {
name: `${pipeline.dataStream.type}-${pipeline.dataStream.dataset}@custom`,
ignore_missing_pipeline: true,
description: `[Fleet] Pipeline for the \`${pipeline.dataStream.dataset}\` dataset`,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const defaultProps: ComponentStoryObj<typeof Component> = {
selectConnector: () => {},
reloadConnectors: () => {},
},
connectorsManagementHref: '',
currentUser: {
username: 'elastic',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { ChatTimeline } from './chat_timeline';
import { Feedback } from '../feedback_buttons';
import { IncorrectLicensePanel } from './incorrect_license_panel';
import { WelcomeMessage } from './welcome_message';
import { EMPTY_CONVERSATION_TITLE } from '../../i18n';
import { ASSISTANT_SETUP_TITLE, EMPTY_CONVERSATION_TITLE, UPGRADE_LICENSE_TITLE } from '../../i18n';
import { ChatActionClickType } from './types';
import type { StartedFrom } from '../../utils/get_timeline_items_from_conversation';
import { TELEMETRY, sendEvent } from '../../analytics';
Expand Down Expand Up @@ -93,7 +93,6 @@ export function ChatBody({
initialConversationId,
connectors,
knowledgeBase,
connectorsManagementHref,
currentUser,
startedFrom,
onConversationUpdate,
Expand All @@ -103,7 +102,6 @@ export function ChatBody({
initialConversationId?: string;
connectors: UseGenAIConnectorsResult;
knowledgeBase: UseKnowledgeBaseResult;
connectorsManagementHref: string;
currentUser?: Pick<AuthenticatedUser, 'full_name' | 'username'>;
startedFrom?: StartedFrom;
onConversationUpdate: (conversation: { conversation: Conversation['conversation'] }) => void;
Expand Down Expand Up @@ -135,6 +133,18 @@ export function ChatBody({
conversation.loading
);

let title = conversation.value?.conversation.title || initialTitle;

if (!title) {
if (!connectors.selectedConnector) {
title = ASSISTANT_SETUP_TITLE;
} else if (!hasCorrectLicense && !initialConversationId) {
title = UPGRADE_LICENSE_TITLE;
} else {
title = EMPTY_CONVERSATION_TITLE;
}
}

const containerClassName = css`
max-height: 100%;
max-width: ${startedFrom === 'conversationView'
Expand Down Expand Up @@ -391,12 +401,9 @@ export function ChatBody({
? conversation.value.conversation.id
: undefined
}
connectorsManagementHref={connectorsManagementHref}
knowledgeBase={knowledgeBase}
licenseInvalid={!hasCorrectLicense && !initialConversationId}
loading={isLoading}
startedFrom={startedFrom}
title={conversation.value?.conversation.title || initialTitle || EMPTY_CONVERSATION_TITLE}
title={title}
onCopyConversation={handleCopyConversation}
onSaveTitle={(newTitle) => {
saveTitle(newTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import React, { useState } from 'react';
import type { Message } from '../../../common/types';
import { useCurrentUser } from '../../hooks/use_current_user';
import { useGenAIConnectors } from '../../hooks/use_genai_connectors';
import { useKibana } from '../../hooks/use_kibana';
import { useKnowledgeBase } from '../../hooks/use_knowledge_base';
import { useObservabilityAIAssistantRouter } from '../../hooks/use_observability_ai_assistant_router';
import { getConnectorsManagementHref } from '../../utils/get_connectors_management_href';
import { StartedFrom } from '../../utils/get_timeline_items_from_conversation';
import { ChatBody } from './chat_body';

Expand All @@ -39,10 +37,6 @@ export function ChatFlyout({
startedFrom: StartedFrom;
onClose: () => void;
}) {
const {
services: { http },
} = useKibana();

const { euiTheme } = useEuiTheme();

const currentUser = useCurrentUser();
Expand Down Expand Up @@ -105,7 +99,6 @@ export function ChatFlyout({
initialTitle={initialTitle}
initialMessages={initialMessages}
currentUser={currentUser}
connectorsManagementHref={getConnectorsManagementHref(http)}
knowledgeBase={knowledgeBase}
startedFrom={startedFrom}
onConversationUpdate={(conversation) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ export const ChatHeaderLoaded: ComponentStoryObj<typeof Component> = {
selectConnector: () => {},
reloadConnectors: () => {},
},
knowledgeBase: {
status: {
loading: false,
value: {
ready: true,
},
refresh: () => {},
},
isInstalling: false,
installError: undefined,
install: async () => {},
},
},
render: (props) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React, { useRef } from 'react';
import React, { useEffect, useState } from 'react';
import {
EuiFlexGroup,
EuiFlexItem,
Expand All @@ -17,11 +17,7 @@ import { i18n } from '@kbn/i18n';
import { css } from '@emotion/css';
import { AssistantAvatar } from '../assistant_avatar';
import { ChatActionsMenu } from './chat_actions_menu';
import { ASSISTANT_SETUP_TITLE, EMPTY_CONVERSATION_TITLE, UPGRADE_LICENSE_TITLE } from '../../i18n';
import { useUnmountAndRemountWhenPropChanges } from '../../hooks/use_unmount_and_remount_when_prop_changes';
import type { UseGenAIConnectorsResult } from '../../hooks/use_genai_connectors';
import type { UseKnowledgeBaseResult } from '../../hooks/use_knowledge_base';
import { StartedFrom } from '../../utils/get_timeline_items_from_conversation';

// needed to prevent InlineTextEdit component from expanding container
const minWidthClassName = css`
Expand All @@ -38,39 +34,25 @@ export function ChatHeader({
loading,
licenseInvalid,
connectors,
connectorsManagementHref,
conversationId,
knowledgeBase,
startedFrom,
onSaveTitle,
onCopyConversation,
onSaveTitle,
}: {
title: string;
loading: boolean;
licenseInvalid: boolean;
connectors: UseGenAIConnectorsResult;
connectorsManagementHref: string;
conversationId?: string;
knowledgeBase: UseKnowledgeBaseResult;
startedFrom?: StartedFrom;
onCopyConversation: () => void;
onSaveTitle?: (title: string) => void;
onSaveTitle: (title: string) => void;
}) {
const hasTitle = !!title;

const displayedTitle = !connectors.selectedConnector
? ASSISTANT_SETUP_TITLE
: licenseInvalid
? UPGRADE_LICENSE_TITLE
: title || EMPTY_CONVERSATION_TITLE;

const theme = useEuiTheme();

// Component only works uncontrolled at the moment, so need to unmount and remount on prop change.
// https://github.com/elastic/eui/issues/7084
const shouldRender = useUnmountAndRemountWhenPropChanges(displayedTitle);
const [newTitle, setNewTitle] = useState(title);

const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
setNewTitle(title);
}, [title]);

return (
<EuiPanel
Expand All @@ -86,28 +68,35 @@ export function ChatHeader({
</EuiFlexItem>

<EuiFlexItem grow className={minWidthClassName}>
{shouldRender ? (
<EuiInlineEditTitle
heading="h2"
size="s"
defaultValue={displayedTitle}
className={css`
color: ${hasTitle ? theme.euiTheme.colors.text : theme.euiTheme.colors.subduedText};
`}
inputAriaLabel={i18n.translate(
'xpack.observabilityAiAssistant.chatHeader.editConversationInput',
{ defaultMessage: 'Edit conversation' }
)}
editModeProps={{ inputProps: { inputRef } }}
isReadOnly={
!conversationId ||
!connectors.selectedConnector ||
licenseInvalid ||
!Boolean(onSaveTitle)
<EuiInlineEditTitle
heading="h2"
size="s"
value={newTitle}
className={css`
color: ${!!title ? theme.euiTheme.colors.text : theme.euiTheme.colors.subduedText};
`}
inputAriaLabel={i18n.translate(
'xpack.observabilityAiAssistant.chatHeader.editConversationInput',
{ defaultMessage: 'Edit conversation' }
)}
isReadOnly={
!conversationId ||
!connectors.selectedConnector ||
licenseInvalid ||
!Boolean(onSaveTitle)
}
onChange={(e) => {
setNewTitle(e.currentTarget.nodeValue || '');
}}
onSave={(e) => {
if (onSaveTitle) {
onSaveTitle(e);
}
onSave={onSaveTitle}
/>
) : null}
}}
onCancel={(previousTitle: string) => {
setNewTitle(previousTitle);
}}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<ChatActionsMenu
Expand Down
Loading

0 comments on commit 2400cbd

Please sign in to comment.