From 4385ffd74b089e3b4a4e76c4ba0722118afe1a4b Mon Sep 17 00:00:00 2001 From: Andrew Macri Date: Thu, 1 Jun 2023 22:55:28 -0600 Subject: [PATCH] [Security Solution] Security Assistant: adds the assistantEnabled feature flag (#17) ## Summary - adds the `assistantEnabled` feature flag (default: `false`) in `x-pack/plugins/security_solution/common/experimental_features.ts` --- .../impl/assistant/context_pills/index.tsx | 5 ++-- .../selected_prompt_contexts/index.tsx | 10 +++++++- .../body/data_quality_details/index.test.tsx | 1 + .../body/data_quality_details/index.tsx | 3 +++ .../indices_details/index.test.tsx | 1 + .../indices_details/index.tsx | 3 +++ .../data_quality_panel/body/index.test.tsx | 3 +++ .../data_quality_panel/body/index.tsx | 3 +++ .../index_properties/index.test.tsx | 1 + .../index_properties/index.tsx | 4 ++++ .../data_quality_panel/pattern/index.test.tsx | 1 + .../data_quality_panel/pattern/index.tsx | 4 ++++ .../data_quality_panel/tabs/helpers.test.tsx | 1 + .../data_quality_panel/tabs/helpers.tsx | 4 ++++ .../tabs/incompatible_tab/index.tsx | 24 +++++++++++-------- .../summary_tab/callout_summary/index.tsx | 24 +++++++++++-------- .../tabs/summary_tab/index.tsx | 3 +++ .../impl/data_quality/index.test.tsx | 2 ++ .../impl/data_quality/index.tsx | 3 +++ .../mock/test_providers/test_providers.tsx | 17 ++++++++++++- .../ecs_data_quality_dashboard/tsconfig.json | 1 + .../common/experimental_features.ts | 5 ++++ .../common/components/page_wrapper/index.tsx | 4 +++- .../pages/rule_management/super_header.tsx | 9 +++---- .../public/overview/pages/data_quality.tsx | 3 +++ .../event_details/expandable_event.tsx | 3 ++- .../side_panel/event_details/index.tsx | 8 ++++++- .../timeline/tabs_content/index.tsx | 22 ++++++++++------- 28 files changed, 131 insertions(+), 41 deletions(-) diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx index 525b2bf85b583..a8522a75b5adb 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx @@ -6,11 +6,10 @@ */ import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; -// eslint-disable-next-line @kbn/eslint/module_migration -import styled from 'styled-components'; - import { sortBy } from 'lodash/fp'; import React, { useCallback, useMemo } from 'react'; +// eslint-disable-next-line @kbn/eslint/module_migration +import styled from 'styled-components'; import type { PromptContext } from '../prompt_context/types'; diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/selected_prompt_contexts/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/selected_prompt_contexts/index.tsx index 58388925bb478..eca303284d1a8 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/selected_prompt_contexts/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/selected_prompt_contexts/index.tsx @@ -56,6 +56,8 @@ const SelectedPromptContextsComponent: React.FC = ({ ); useEffect(() => { + const abortController = new AbortController(); + const fetchAccordionContent = async () => { const newAccordionContent = await Promise.all( selectedPromptContexts.map(async ({ getPromptContext, id }) => ({ @@ -63,10 +65,16 @@ const SelectedPromptContextsComponent: React.FC = ({ })) ); - setAccordionContent(newAccordionContent.reduce((acc, curr) => ({ ...acc, ...curr }), {})); + if (!abortController.signal.aborted) { + setAccordionContent(newAccordionContent.reduce((acc, curr) => ({ ...acc, ...curr }), {})); + } }; fetchAccordionContent(); + + return () => { + abortController.abort(); + }; }, [selectedPromptContexts]); if (isEmpty(promptContexts)) { diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.test.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.test.tsx index 3278ec3a1def3..71e63d361a0bc 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.test.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.test.tsx @@ -55,6 +55,7 @@ const defaultProps: Props = { formatNumber, getGroupByFieldsOnClick: jest.fn(), ilmPhases, + isAssistantEnabled: true, openCreateCaseFlyout: jest.fn(), patternIndexNames, patternRollups, diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.tsx index 3c996dd095dc8..45bb717c52706 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/index.tsx @@ -41,6 +41,7 @@ export interface Props { groupByField1: string; }; ilmPhases: string[]; + isAssistantEnabled: boolean; openCreateCaseFlyout: ({ comments, headerContent, @@ -69,6 +70,7 @@ const DataQualityDetailsComponent: React.FC = ({ formatNumber, getGroupByFieldsOnClick, ilmPhases, + isAssistantEnabled, openCreateCaseFlyout, patternIndexNames, patternRollups, @@ -105,6 +107,7 @@ const DataQualityDetailsComponent: React.FC = ({ formatNumber={formatNumber} getGroupByFieldsOnClick={getGroupByFieldsOnClick} ilmPhases={ilmPhases} + isAssistantEnabled={isAssistantEnabled} openCreateCaseFlyout={openCreateCaseFlyout} patterns={patterns} theme={theme} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.test.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.test.tsx index 2b21154d70b3a..8251b16c389b0 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.test.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.test.tsx @@ -55,6 +55,7 @@ const defaultProps: Props = { formatNumber, getGroupByFieldsOnClick: jest.fn(), ilmPhases, + isAssistantEnabled: true, openCreateCaseFlyout: jest.fn(), patternIndexNames, patternRollups, diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.tsx index 9b59a78430e1c..3f9ef7575b385 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/data_quality_details/indices_details/index.tsx @@ -39,6 +39,7 @@ export interface Props { groupByField1: string; }; ilmPhases: string[]; + isAssistantEnabled: boolean; openCreateCaseFlyout: ({ comments, headerContent, @@ -69,6 +70,7 @@ const IndicesDetailsComponent: React.FC = ({ formatNumber, getGroupByFieldsOnClick, ilmPhases, + isAssistantEnabled, openCreateCaseFlyout, patternIndexNames, patternRollups, @@ -90,6 +92,7 @@ const IndicesDetailsComponent: React.FC = ({ getGroupByFieldsOnClick={getGroupByFieldsOnClick} ilmPhases={ilmPhases} indexNames={patternIndexNames[pattern]} + isAssistantEnabled={isAssistantEnabled} openCreateCaseFlyout={openCreateCaseFlyout} pattern={pattern} patternRollup={patternRollups[pattern]} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.test.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.test.tsx index 242229870de25..6e9c5861e6bae 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.test.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.test.tsx @@ -35,6 +35,7 @@ describe('IndexInvalidValues', () => { formatNumber={formatNumber} getGroupByFieldsOnClick={jest.fn()} ilmPhases={[]} + isAssistantEnabled={true} lastChecked={''} openCreateCaseFlyout={jest.fn()} patterns={[]} @@ -63,6 +64,7 @@ describe('IndexInvalidValues', () => { formatNumber={formatNumber} getGroupByFieldsOnClick={jest.fn()} ilmPhases={ilmPhases} + isAssistantEnabled={true} lastChecked={''} openCreateCaseFlyout={jest.fn()} patterns={patterns} @@ -88,6 +90,7 @@ describe('IndexInvalidValues', () => { formatNumber={formatNumber} getGroupByFieldsOnClick={jest.fn()} ilmPhases={ilmPhases} + isAssistantEnabled={true} lastChecked={''} openCreateCaseFlyout={jest.fn()} patterns={patterns} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.tsx index 69de3b8c110e5..ca43cf1e7d40c 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/body/index.tsx @@ -40,6 +40,7 @@ interface Props { groupByField1: string; }; ilmPhases: string[]; + isAssistantEnabled: boolean; lastChecked: string; openCreateCaseFlyout: ({ comments, @@ -60,6 +61,7 @@ const BodyComponent: React.FC = ({ formatNumber, getGroupByFieldsOnClick, ilmPhases, + isAssistantEnabled, lastChecked, openCreateCaseFlyout, patterns, @@ -112,6 +114,7 @@ const BodyComponent: React.FC = ({ formatNumber={formatNumber} getGroupByFieldsOnClick={getGroupByFieldsOnClick} ilmPhases={ilmPhases} + isAssistantEnabled={isAssistantEnabled} openCreateCaseFlyout={openCreateCaseFlyout} patterns={patterns} patternIndexNames={patternIndexNames} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.test.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.test.tsx index c578ec8c91f96..ef0868fe3233b 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.test.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.test.tsx @@ -111,6 +111,7 @@ const defaultProps: Props = { getGroupByFieldsOnClick: jest.fn(), ilmPhase: 'hot', indexName: 'auditbeat-custom-index-1', + isAssistantEnabled: true, openCreateCaseFlyout: jest.fn(), pattern, patternRollup, diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.tsx index ca9eda507f8dd..ac16b9dfbcccf 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/index_properties/index.tsx @@ -60,6 +60,7 @@ export interface Props { }; ilmPhase: IlmPhase | undefined; indexName: string; + isAssistantEnabled: boolean; openCreateCaseFlyout: ({ comments, headerContent, @@ -82,6 +83,7 @@ const IndexPropertiesComponent: React.FC = ({ getGroupByFieldsOnClick, ilmPhase, indexName, + isAssistantEnabled, openCreateCaseFlyout, pattern, patternRollup, @@ -143,6 +145,7 @@ const IndexPropertiesComponent: React.FC = ({ docsCount, getGroupByFieldsOnClick, ilmPhase, + isAssistantEnabled, indexName, onAddToNewCase, partitionedFieldMetadata: partitionedFieldMetadata ?? EMPTY_METADATA, @@ -161,6 +164,7 @@ const IndexPropertiesComponent: React.FC = ({ getGroupByFieldsOnClick, ilmPhase, indexName, + isAssistantEnabled, onAddToNewCase, partitionedFieldMetadata, pattern, diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.test.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.test.tsx index d9b002a63dc68..d06866544a6bf 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.test.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.test.tsx @@ -46,6 +46,7 @@ const defaultProps = { getGroupByFieldsOnClick: jest.fn(), ilmPhases: ['hot', 'warm', 'unmanaged'], indexNames: undefined, + isAssistantEnabled: true, openCreateCaseFlyout: jest.fn(), patternRollup: undefined, selectedIndex: null, diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.tsx index cb430d75ef12e..3213c1c1dbef9 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/pattern/index.tsx @@ -76,6 +76,7 @@ interface Props { }; ilmPhases: string[]; indexNames: string[] | undefined; + isAssistantEnabled: boolean; openCreateCaseFlyout: ({ comments, headerContent, @@ -106,6 +107,7 @@ const PatternComponent: React.FC = ({ getGroupByFieldsOnClick, indexNames, ilmPhases, + isAssistantEnabled, openCreateCaseFlyout, pattern, patternRollup, @@ -150,6 +152,7 @@ const PatternComponent: React.FC = ({ getGroupByFieldsOnClick={getGroupByFieldsOnClick} ilmPhase={ilmExplain != null ? getIlmPhase(ilmExplain[indexName]) : undefined} indexName={indexName} + isAssistantEnabled={isAssistantEnabled} openCreateCaseFlyout={openCreateCaseFlyout} pattern={pattern} patternRollup={patternRollup} @@ -168,6 +171,7 @@ const PatternComponent: React.FC = ({ formatNumber, getGroupByFieldsOnClick, ilmExplain, + isAssistantEnabled, itemIdToExpandedRowMap, openCreateCaseFlyout, pattern, diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.test.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.test.tsx index c0dc6a8aaafe2..fe436309dae78 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.test.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.test.tsx @@ -77,6 +77,7 @@ describe('helpers', () => { getGroupByFieldsOnClick: jest.fn(), ilmPhase: 'unmanaged', indexName: 'auditbeat-custom-index-1', + isAssistantEnabled: true, onAddToNewCase: jest.fn(), partitionedFieldMetadata: mockPartitionedFieldMetadata, pattern: 'auditbeat-*', diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.tsx index c0cbebd45cb8d..c04a7a861d17f 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/helpers.tsx @@ -66,6 +66,7 @@ export const getTabs = ({ getGroupByFieldsOnClick, ilmPhase, indexName, + isAssistantEnabled, onAddToNewCase, partitionedFieldMetadata, pattern, @@ -94,6 +95,7 @@ export const getTabs = ({ }; ilmPhase: IlmPhase | undefined; indexName: string; + isAssistantEnabled: boolean; onAddToNewCase: (markdownComments: string[]) => void; partitionedFieldMetadata: PartitionedFieldMetadata; pattern: string; @@ -113,6 +115,7 @@ export const getTabs = ({ getGroupByFieldsOnClick={getGroupByFieldsOnClick} ilmPhase={ilmPhase} indexName={indexName} + isAssistantEnabled={isAssistantEnabled} onAddToNewCase={onAddToNewCase} partitionedFieldMetadata={partitionedFieldMetadata} pattern={pattern} @@ -140,6 +143,7 @@ export const getTabs = ({ formatNumber={formatNumber} ilmPhase={ilmPhase} indexName={indexName} + isAssistantEnabled={isAssistantEnabled} onAddToNewCase={onAddToNewCase} partitionedFieldMetadata={partitionedFieldMetadata} patternDocsCount={patternDocsCount} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/incompatible_tab/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/incompatible_tab/index.tsx index 157ee13bb17b1..e0e26f3928bde 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/incompatible_tab/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/incompatible_tab/index.tsx @@ -51,6 +51,7 @@ interface Props { formatNumber: (value: number | undefined) => string; ilmPhase: IlmPhase | undefined; indexName: string; + isAssistantEnabled: boolean; onAddToNewCase: (markdownComments: string[]) => void; partitionedFieldMetadata: PartitionedFieldMetadata; patternDocsCount: number; @@ -65,6 +66,7 @@ const IncompatibleTabComponent: React.FC = ({ formatNumber, ilmPhase, indexName, + isAssistantEnabled, onAddToNewCase, partitionedFieldMetadata, patternDocsCount, @@ -139,16 +141,18 @@ const IncompatibleTabComponent: React.FC = ({ - - - + {isAssistantEnabled && ( + + + + )} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/callout_summary/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/callout_summary/index.tsx index e1da560091bfe..ba3aebc501010 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/callout_summary/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/callout_summary/index.tsx @@ -33,6 +33,7 @@ interface Props { formatNumber: (value: number | undefined) => string; ilmPhase: IlmPhase | undefined; indexName: string; + isAssistantEnabled: boolean; onAddToNewCase: (markdownComment: string[]) => void; partitionedFieldMetadata: PartitionedFieldMetadata; pattern: string; @@ -48,6 +49,7 @@ const CalloutSummaryComponent: React.FC = ({ formatNumber, ilmPhase, indexName, + isAssistantEnabled, onAddToNewCase, partitionedFieldMetadata, pattern, @@ -132,16 +134,18 @@ const CalloutSummaryComponent: React.FC = ({ - - - + {isAssistantEnabled && ( + + + + )} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/index.tsx index c830ac2f6c7be..8f27a409c7455 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/index.tsx @@ -42,6 +42,7 @@ interface Props { }; ilmPhase: IlmPhase | undefined; indexName: string; + isAssistantEnabled: boolean; onAddToNewCase: (markdownComments: string[]) => void; partitionedFieldMetadata: PartitionedFieldMetadata; pattern: string; @@ -60,6 +61,7 @@ const SummaryTabComponent: React.FC = ({ getGroupByFieldsOnClick, ilmPhase, indexName, + isAssistantEnabled, onAddToNewCase, partitionedFieldMetadata, pattern, @@ -77,6 +79,7 @@ const SummaryTabComponent: React.FC = ({ docsCount={docsCount} ilmPhase={ilmPhase} indexName={indexName} + isAssistantEnabled={isAssistantEnabled} onAddToNewCase={onAddToNewCase} partitionedFieldMetadata={partitionedFieldMetadata} pattern={pattern} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.test.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.test.tsx index 17f7e830750af..44bc2458990e9 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.test.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.test.tsx @@ -27,6 +27,7 @@ describe('DataQualityPanel', () => { getGroupByFieldsOnClick={jest.fn()} httpFetch={jest.fn()} ilmPhases={ilmPhases} + isAssistantEnabled={true} lastChecked={''} openCreateCaseFlyout={jest.fn()} patterns={[]} @@ -60,6 +61,7 @@ describe('DataQualityPanel', () => { getGroupByFieldsOnClick={jest.fn()} httpFetch={jest.fn()} ilmPhases={ilmPhases} + isAssistantEnabled={true} lastChecked={''} openCreateCaseFlyout={jest.fn()} patterns={[]} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.tsx index 758cad54f7caa..026be1f05d0d8 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/index.tsx @@ -42,6 +42,7 @@ interface Props { }; httpFetch: HttpHandler; ilmPhases: string[]; + isAssistantEnabled: boolean; lastChecked: string; openCreateCaseFlyout: ({ comments, @@ -64,6 +65,7 @@ const DataQualityPanelComponent: React.FC = ({ getGroupByFieldsOnClick, httpFetch, ilmPhases, + isAssistantEnabled, lastChecked, openCreateCaseFlyout, patterns, @@ -91,6 +93,7 @@ const DataQualityPanelComponent: React.FC = ({ formatNumber={formatNumber} getGroupByFieldsOnClick={getGroupByFieldsOnClick} ilmPhases={ilmPhases} + isAssistantEnabled={isAssistantEnabled} lastChecked={lastChecked} openCreateCaseFlyout={openCreateCaseFlyout} patterns={patterns} diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/mock/test_providers/test_providers.tsx b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/mock/test_providers/test_providers.tsx index 3aba964c68783..7c9933942b270 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/mock/test_providers/test_providers.tsx +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/impl/data_quality/mock/test_providers/test_providers.tsx @@ -5,7 +5,9 @@ * 2.0. */ +import { actionTypeRegistryMock } from '@kbn/triggers-actions-ui-plugin/public/application/action_type_registry.mock'; import { httpServiceMock } from '@kbn/core-http-browser-mocks'; +import { AssistantProvider } from '@kbn/elastic-assistant'; import { I18nProvider } from '@kbn/i18n-react'; import { euiDarkVars } from '@kbn/ui-theme'; import React from 'react'; @@ -22,11 +24,24 @@ window.scrollTo = jest.fn(); /** A utility for wrapping children in the providers required to run tests */ export const TestProvidersComponent: React.FC = ({ children }) => { const http = httpServiceMock.createSetupContract({ basePath: '/test' }); + const actionTypeRegistry = actionTypeRegistryMock.create(); + const mockGetInitialConversations = jest.fn(() => ({})); + const mockGetComments = jest.fn(() => []); + const mockHttp = httpServiceMock.createStartContract({ basePath: '/test' }); return ( ({ eui: euiDarkVars, darkMode: true })}> - {children} + + {children} + ); diff --git a/x-pack/packages/security-solution/ecs_data_quality_dashboard/tsconfig.json b/x-pack/packages/security-solution/ecs_data_quality_dashboard/tsconfig.json index c15182a8e8403..b033af7aa5a0c 100644 --- a/x-pack/packages/security-solution/ecs_data_quality_dashboard/tsconfig.json +++ b/x-pack/packages/security-solution/ecs_data_quality_dashboard/tsconfig.json @@ -23,5 +23,6 @@ "@kbn/core-http-browser", "@kbn/core-http-browser-mocks", "@kbn/elastic-assistant", + "@kbn/triggers-actions-ui-plugin", ] } diff --git a/x-pack/plugins/security_solution/common/experimental_features.ts b/x-pack/plugins/security_solution/common/experimental_features.ts index 0e44190bfab78..e313796fe9559 100644 --- a/x-pack/plugins/security_solution/common/experimental_features.ts +++ b/x-pack/plugins/security_solution/common/experimental_features.ts @@ -113,6 +113,11 @@ export const allowedExperimentalValues = Object.freeze({ */ securityFlyoutEnabled: false, + /** + * Enables the Elastic Security Assistant + */ + assistantEnabled: false, + /** * Keep DEPRECATED experimental flags that are documented to prevent failed upgrades. * https://www.elastic.co/guide/en/security/current/user-risk-score.html diff --git a/x-pack/plugins/security_solution/public/common/components/page_wrapper/index.tsx b/x-pack/plugins/security_solution/public/common/components/page_wrapper/index.tsx index 26d0b15093342..6cf4167ea6d6e 100644 --- a/x-pack/plugins/security_solution/public/common/components/page_wrapper/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/page_wrapper/index.tsx @@ -12,6 +12,7 @@ import styled from 'styled-components'; import type { CommonProps } from '@elastic/eui'; import { useGlobalFullScreen } from '../../containers/use_full_screen'; +import { useIsExperimentalFeatureEnabled } from '../../hooks/use_experimental_features'; import { AppGlobalStyle } from '../page'; const Wrapper = styled.div` @@ -42,6 +43,7 @@ interface SecuritySolutionPageWrapperProps { const SecuritySolutionPageWrapperComponent: React.FC< SecuritySolutionPageWrapperProps & CommonProps > = ({ children, className, style, noPadding, noTimeline, ...otherProps }) => { + const isAssistantEnabled = useIsExperimentalFeatureEnabled('assistantEnabled'); const { globalFullScreen, setGlobalFullScreen } = useGlobalFullScreen(); useEffect(() => { setGlobalFullScreen(false); // exit full screen mode on page load @@ -58,7 +60,7 @@ const SecuritySolutionPageWrapperComponent: React.FC< {children} - + {isAssistantEnabled && } ); }; diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/pages/rule_management/super_header.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/pages/rule_management/super_header.tsx index 400b6e13f1bf2..e7bdaca00f2d1 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/pages/rule_management/super_header.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/pages/rule_management/super_header.tsx @@ -8,13 +8,14 @@ import { NewChat } from '@kbn/elastic-assistant'; import React, { useCallback, useMemo } from 'react'; -import { useRulesTableContext } from '../../components/rules_table/rules_table/rules_table_context'; +import { getPromptContextFromDetectionRules } from '../../../../assistant/helpers'; import { HeaderPage } from '../../../../common/components/header_page'; +import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; +import { useRulesTableContext } from '../../components/rules_table/rules_table/rules_table_context'; import * as i18n from '../../../../detections/pages/detection_engine/rules/translations'; -import { getPromptContextFromDetectionRules } from '../../../../assistant/helpers'; - export const SuperHeader: React.FC<{ children: React.ReactNode }> = React.memo(({ children }) => { + const isAssistantEnabled = useIsExperimentalFeatureEnabled('assistantEnabled'); const memoizedChildren = useMemo(() => children, [children]); // Rules state const { @@ -36,7 +37,7 @@ export const SuperHeader: React.FC<{ children: React.ReactNode }> = React.memo(( title={ <> {i18n.PAGE_TITLE}{' '} - {selectedRules.length > 0 && ( + {isAssistantEnabled && selectedRules.length > 0 && ( { + const isAssistantEnabled = useIsExperimentalFeatureEnabled('assistantEnabled'); const httpFetch = KibanaServices.get().http.fetch; const theme = useTheme(); const toasts = useToasts(); @@ -235,6 +237,7 @@ const DataQualityComponent: React.FC = () => { getGroupByFieldsOnClick={getGroupByFieldsOnClick} httpFetch={httpFetch} ilmPhases={ilmPhases} + isAssistantEnabled={isAssistantEnabled} lastChecked={lastChecked} openCreateCaseFlyout={openCreateCaseFlyout} patterns={alertsAndSelectedPatterns} diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/event_details/expandable_event.tsx b/x-pack/plugins/security_solution/public/timelines/components/side_panel/event_details/expandable_event.tsx index f6cbc515dfdb3..5f4e7a087b02e 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/event_details/expandable_event.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/event_details/expandable_event.tsx @@ -96,6 +96,7 @@ export const ExpandableEventTitle = React.memo( ruleName, timestamp, }) => { + const isAssistantEnabled = useIsExperimentalFeatureEnabled('assistantEnabled'); const isAlertDetailsPageEnabled = useIsExperimentalFeatureEnabled('alertDetailsPageEnabled'); const { onClick } = useGetSecuritySolutionLinkProps()({ deepLinkId: SecurityPageName.alerts, @@ -151,7 +152,7 @@ export const ExpandableEventTitle = React.memo( )} - {promptContextId != null && ( + {isAssistantEnabled && promptContextId != null && ( ({ promptContextId: undefined }); + const EventDetailsPanelComponent: React.FC = ({ browserFields, entityType = 'events', // Default to events so only alerts have to pass entityType in @@ -64,6 +67,9 @@ const EventDetailsPanelComponent: React.FC = ({ scopeId, isReadOnly, }) => { + const isAssistantEnabled = useIsExperimentalFeatureEnabled('assistantEnabled'); + // TODO: changing feature flags requires a hard refresh to take effect, but this temporary workaround technically violates the rules of hooks: + const useAssistant = isAssistantEnabled ? useAssistantOverlay : useAssistantNoop; const currentSpaceId = useSpaceId(); const { indexName } = expandedEvent; const eventIndex = getAlertIndexAlias(indexName, currentSpaceId) ?? indexName; @@ -96,7 +102,7 @@ const EventDetailsPanelComponent: React.FC = ({ [detailsData] ); - const { promptContextId } = useAssistantOverlay( + const { promptContextId } = useAssistant( isAlert ? 'alert' : 'event', isAlert ? ALERT_SUMMARY_CONVERSATION_ID : EVENT_SUMMARY_CONVERSATION_ID, isAlert ? ALERT_SUMMARY_CONTEXT_DESCRIPTION(view) : EVENT_SUMMARY_CONTEXT_DESCRIPTION(view), diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs_content/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs_content/index.tsx index 667a79d93e102..f4e38a29dde02 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs_content/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs_content/index.tsx @@ -35,6 +35,7 @@ import { getEventIdToNoteIdsSelector, } from './selectors'; import * as i18n from './translations'; +import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; import { useLicense } from '../../../../common/hooks/use_license'; const HideShowContainer = styled.div.attrs<{ $isVisible: boolean; isOverflowYScroll: boolean }>( @@ -288,6 +289,7 @@ const TabsContentComponent: React.FC = ({ sessionViewConfig, timelineDescription, }) => { + const isAssistantEnabled = useIsExperimentalFeatureEnabled('assistantEnabled'); const dispatch = useDispatch(); const getActiveTab = useMemo(() => getActiveTabSelector(), []); const getShowTimeline = useMemo(() => getShowTimelineSelector(), []); @@ -442,15 +444,17 @@ const TabsContentComponent: React.FC = ({ )} - - {i18n.SECURITY_ASSISTANT} - + {isAssistantEnabled && ( + + {i18n.SECURITY_ASSISTANT} + + )} )}