From 1629701ccf477ab521b056a99984b08a9470669e Mon Sep 17 00:00:00 2001 From: Andrew Macri Date: Mon, 5 Jun 2023 17:57:02 -0600 Subject: [PATCH] This PR includes the same changes as https://github.com/elastic/kibana/pull/159054 https://github.com/elastic/kibana/pull/159054 was merged directly to the `8.8` branch, and includes the following changes: - Changes the `New chat` button text from `New chat` to `Chat`, because a new chat context is not created if an existing chat is in progress - Updates the Data Quality dashboard user prompt to remove references to API requests - Fixes an issue where user prompts were not filtered by category --- .../prompt_context_selector.tsx | 3 +-- .../assistant/quick_prompts/quick_prompts.tsx | 24 +++++++++++++++---- .../impl/new_chat/index.test.tsx | 2 +- .../impl/new_chat/translations.ts | 2 +- .../impl/new_chat_by_id/index.test.tsx | 2 +- .../impl/new_chat_by_id/translations.ts | 2 +- .../impl/data_quality/translations.ts | 3 ++- .../ecs_data_quality_dashboard/index.ts | 3 +++ .../content/prompt_contexts/index.tsx | 23 +++++++++++++----- .../content/prompt_contexts/translations.ts | 22 +++++++++++++++++ 10 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/assistant/content/prompt_contexts/translations.ts diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/prompt_context_selector/prompt_context_selector.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/prompt_context_selector/prompt_context_selector.tsx index 760bfc3c5e30d..c14d533ee96fa 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/prompt_context_selector/prompt_context_selector.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/prompt_context_selector/prompt_context_selector.tsx @@ -77,8 +77,7 @@ export const PromptContextSelector: React.FC = React.memo( return ( {label} -   - {`(${value?.category})`} + {` / (${value?.category})`} ); }; diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/quick_prompts.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/quick_prompts.tsx index 536154ab845ae..a88c541b312f0 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/quick_prompts.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/quick_prompts/quick_prompts.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; import { EuiFlexGroup, EuiFlexItem, EuiBadge, EuiPopover } from '@elastic/eui'; // eslint-disable-next-line @kbn/eslint/module_migration import styled from 'styled-components'; @@ -33,7 +33,7 @@ interface QuickPromptsProps { * and localstorage for storing new and edited prompts. */ export const QuickPrompts: React.FC = React.memo(({ setInput }) => { - const { basePromptContexts, baseQuickPrompts, nameSpace } = useAssistantContext(); + const { basePromptContexts, baseQuickPrompts, nameSpace, promptContexts } = useAssistantContext(); // Local storage for all quick prompts, prefixed by assistant nameSpace const [localStorageQuickPrompts, setLocalStorageQuickPrompts] = useLocalStorage( @@ -42,6 +42,20 @@ export const QuickPrompts: React.FC = React.memo(({ setInput ); const [quickPrompts, setQuickPrompts] = useState(localStorageQuickPrompts ?? []); + const contextFilteredQuickPrompts = useMemo(() => { + const registeredPromptContextTitles = Object.values(promptContexts).map((pc) => pc.category); + return quickPrompts.filter((quickPrompt) => { + // Return quick prompt as match if it has no categories, otherwise ensure category exists in registered prompt contexts + if (quickPrompt.categories == null || quickPrompt.categories.length === 0) { + return true; + } else { + return quickPrompt.categories.some((category) => { + return registeredPromptContextTitles.includes(category); + }); + } + }); + }, [quickPrompts, promptContexts]); + // Overflow state const [isOverflowPopoverOpen, setIsOverflowPopoverOpen] = useState(false); const toggleOverflowPopover = useCallback( @@ -67,7 +81,7 @@ export const QuickPrompts: React.FC = React.memo(({ setInput ); return ( - {quickPrompts.slice(0, COUNT_BEFORE_OVERFLOW).map((badge, index) => ( + {contextFilteredQuickPrompts.slice(0, COUNT_BEFORE_OVERFLOW).map((badge, index) => ( = React.memo(({ setInput ))} - {quickPrompts.length > COUNT_BEFORE_OVERFLOW && ( + {contextFilteredQuickPrompts.length > COUNT_BEFORE_OVERFLOW && ( = React.memo(({ setInput anchorPosition="rightUp" > - {quickPrompts.slice(COUNT_BEFORE_OVERFLOW).map((badge, index) => ( + {contextFilteredQuickPrompts.slice(COUNT_BEFORE_OVERFLOW).map((badge, index) => ( { const newChatButton = screen.getByTestId('newChat'); - expect(newChatButton.textContent).toContain('New chat'); + expect(newChatButton.textContent).toContain('Chat'); }); it('renders custom children', () => { diff --git a/x-pack/packages/kbn-elastic-assistant/impl/new_chat/translations.ts b/x-pack/packages/kbn-elastic-assistant/impl/new_chat/translations.ts index 5bc87dc1a261c..69b8e0394af42 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/new_chat/translations.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/new_chat/translations.ts @@ -8,5 +8,5 @@ import { i18n } from '@kbn/i18n'; export const NEW_CHAT = i18n.translate('xpack.elasticAssistant.assistant.newChat.newChatButton', { - defaultMessage: 'New chat', + defaultMessage: 'Chat', }); diff --git a/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/index.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/index.test.tsx index c2ff10fa22a20..7ff86b7631078 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/index.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/index.test.tsx @@ -36,7 +36,7 @@ describe('NewChatById', () => { const newChatButton = screen.getByTestId('newChatById'); - expect(newChatButton.textContent).toContain('New chat'); + expect(newChatButton.textContent).toContain('Chat'); }); it('renders custom children', async () => { diff --git a/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/translations.ts b/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/translations.ts index 373aae6297eee..1cf3ec2609a73 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/translations.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/new_chat_by_id/translations.ts @@ -10,6 +10,6 @@ import { i18n } from '@kbn/i18n'; export const NEW_CHAT = i18n.translate( 'xpack.elasticAssistant.assistant.newChatById.newChatByIdButton', { - defaultMessage: 'New chat', + defaultMessage: 'Chat', } ); diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/translations.ts b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/translations.ts index f0e6ab6fba137..99d94c73ff49c 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/translations.ts +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/translations.ts @@ -87,7 +87,8 @@ export const DATA_QUALITY_SUBTITLE: string = i18n.translate( export const DATA_QUALITY_SUGGESTED_USER_PROMPT = i18n.translate( 'securitySolutionPackages.ecsDataQualityDashboard.dataQualitySuggestedUserPrompt', { - defaultMessage: 'Explain how to fix issues step by step, and provide API calls.', + defaultMessage: + 'Explain the results above, and describe some options to fix incompatibilities.', } ); diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/index.ts b/x-pack/packages/security-solution/ecs_data_quality_dashboard/index.ts index 6e5f3c69f14c4..87c32ba78d5e6 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/index.ts +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/index.ts @@ -10,7 +10,10 @@ export { DataQualityPanel } from './impl/data_quality'; export { getIlmPhaseDescription } from './impl/data_quality/helpers'; export { + DATA_QUALITY_PROMPT_CONTEXT_PILL, + DATA_QUALITY_PROMPT_CONTEXT_PILL_TOOLTIP, DATA_QUALITY_SUBTITLE, + DATA_QUALITY_SUGGESTED_USER_PROMPT, ILM_PHASE, INDEX_LIFECYCLE_MANAGEMENT_PHASES, SELECT_ONE_OR_MORE_ILM_PHASES, diff --git a/x-pack/plugins/security_solution/public/assistant/content/prompt_contexts/index.tsx b/x-pack/plugins/security_solution/public/assistant/content/prompt_contexts/index.tsx index c5d036dc9cc02..b42df2c2cee08 100644 --- a/x-pack/plugins/security_solution/public/assistant/content/prompt_contexts/index.tsx +++ b/x-pack/plugins/security_solution/public/assistant/content/prompt_contexts/index.tsx @@ -7,13 +7,15 @@ import type { PromptContext, PromptContextTemplate } from '@kbn/elastic-assistant'; import { USER_PROMPTS } from '@kbn/elastic-assistant'; -import * as i18n from '../../../common/components/event_details/translations'; +import * as i18nDataQuality from '@kbn/ecs-data-quality-dashboard'; +import * as i18nEventDetails from '../../../common/components/event_details/translations'; import * as i18nDetections from '../../../detections/pages/detection_engine/rules/translations'; -import { SUMMARY_VIEW } from '../../../common/components/event_details/translations'; +import * as i18n from './translations'; export const PROMPT_CONTEXT_ALERT_CATEGORY = 'alert'; export const PROMPT_CONTEXT_EVENT_CATEGORY = 'event'; export const PROMPT_CONTEXT_DETECTION_RULES_CATEGORY = 'detection-rules'; +export const DATA_QUALITY_DASHBOARD_CATEGORY = 'data-quality-dashboard'; /** * Global list of PromptContexts intended to be used throughout Security Solution. @@ -28,8 +30,8 @@ export const PROMPT_CONTEXTS: Record