From da271eb2033be3a3ab1b23244e9b7a047a2f1093 Mon Sep 17 00:00:00 2001 From: christineweng Date: Mon, 29 Jul 2024 13:01:45 -0500 Subject: [PATCH] remove alert type charts feature flag --- .../common/experimental_features.ts | 5 - .../alerts_by_rule.test.tsx | 62 +++++++ .../alerts_by_rule_panel/alerts_by_rule.tsx | 100 ++++++++++ .../helpers.test.tsx | 21 +-- .../alerts_by_rule_panel/helpers.tsx | 35 ++++ .../index.test.tsx | 18 +- .../index.tsx | 27 ++- .../mock_rule_data.ts | 10 +- .../alerts_by_rule_panel/translations.ts | 14 ++ .../types.ts | 26 +-- .../alerts_by_type.test.tsx | 172 ------------------ .../alerts_by_type_panel/alerts_by_type.tsx | 142 --------------- .../alerts_by_type_panel/columns.tsx | 99 ---------- .../alerts_by_type_panel/helpers.tsx | 102 ----------- .../alerts_by_type_panel/mock_type_data.ts | 160 ---------------- .../alerts_by_type_panel/translations.ts | 56 ------ .../aggregations.ts | 17 -- .../helpers.test.tsx | 10 +- .../alerts_summary_charts_panel/helpers.tsx | 10 +- .../alerts_summary_charts_panel/index.tsx | 4 +- .../alerts_summary_charts_panel/types.ts | 10 +- .../use_summary_chart_data.test.tsx | 61 +------ .../translations/translations/fr-FR.json | 6 - .../translations/translations/ja-JP.json | 6 - .../translations/translations/zh-CN.json | 6 - 25 files changed, 250 insertions(+), 929 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.test.tsx create mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.tsx rename x-pack/plugins/security_solution/public/detections/components/alerts_kpis/{alerts_by_type_panel => alerts_by_rule_panel}/helpers.test.tsx (57%) create mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.tsx rename x-pack/plugins/security_solution/public/detections/components/alerts_kpis/{alerts_by_type_panel => alerts_by_rule_panel}/index.test.tsx (80%) rename x-pack/plugins/security_solution/public/detections/components/alerts_kpis/{alerts_by_type_panel => alerts_by_rule_panel}/index.tsx (60%) rename x-pack/plugins/security_solution/public/detections/components/alerts_kpis/{alerts_by_type_panel => alerts_by_rule_panel}/mock_rule_data.ts (85%) create mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/translations.ts rename x-pack/plugins/security_solution/public/detections/components/alerts_kpis/{alerts_by_type_panel => alerts_by_rule_panel}/types.ts (51%) delete mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.test.tsx delete mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.tsx delete mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/columns.tsx delete mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/helpers.tsx delete mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/mock_type_data.ts delete mode 100644 x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/translations.ts diff --git a/x-pack/plugins/security_solution/common/experimental_features.ts b/x-pack/plugins/security_solution/common/experimental_features.ts index 7b8b1a3e47d39..8aac9f3c427f3 100644 --- a/x-pack/plugins/security_solution/common/experimental_features.ts +++ b/x-pack/plugins/security_solution/common/experimental_features.ts @@ -103,11 +103,6 @@ export const allowedExperimentalValues = Object.freeze({ */ alertsPageChartsEnabled: true, - /** - * Enables the alert type column in KPI visualizations on Alerts Page - */ - alertTypeEnabled: false, - /** * Enables new notes */ diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.test.tsx new file mode 100644 index 0000000000000..3ac84caac4157 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.test.tsx @@ -0,0 +1,62 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { act, render } from '@testing-library/react'; +import React from 'react'; +import { TestProviders } from '../../../../common/mock'; +import { AlertsByRule } from './alerts_by_rule'; +import { parsedAlerts } from './mock_rule_data'; + +jest.mock('../../../../common/lib/kibana'); + +jest.mock('react-router-dom', () => { + const actual = jest.requireActual('react-router-dom'); + return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) }; +}); + +describe('Alert by rule chart', () => { + const defaultProps = { + data: [], + isLoading: false, + }; + + afterEach(() => { + jest.clearAllMocks(); + }); + + test('renders table correctly without data', () => { + act(() => { + const { container } = render( + + + + ); + expect( + container.querySelector('[data-test-subj="alerts-by-type-table"]') + ).toBeInTheDocument(); + expect( + container.querySelector('[data-test-subj="alerts-by-type-table"] tbody')?.textContent + ).toEqual('No items found'); + }); + }); + + test('renders table correctly with data', () => { + act(() => { + const { queryAllByRole } = render( + + + + ); + + parsedAlerts.forEach((_, i) => { + expect(queryAllByRole('row')[i + 1].textContent).toContain(parsedAlerts[i].rule); + expect(queryAllByRole('row')[i + 1].textContent).toContain( + parsedAlerts[i].value.toString() + ); + }); + }); + }); +}); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.tsx new file mode 100644 index 0000000000000..83b40bb846367 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.tsx @@ -0,0 +1,100 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { EuiBasicTableColumn } from '@elastic/eui'; +import { EuiInMemoryTable, EuiSpacer, EuiText } from '@elastic/eui'; +import React from 'react'; +import styled from 'styled-components'; +import type { SortOrder } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { ALERT_RULE_NAME } from '@kbn/rule-data-utils'; +import { TableId } from '@kbn/securitysolution-data-table'; +import type { AlertsByRuleData } from './types'; +import { FormattedCount } from '../../../../common/components/formatted_number'; +import { DefaultDraggable } from '../../../../common/components/draggables'; +import { ALERTS_HEADERS_RULE_NAME } from '../../alerts_table/translations'; +import { COUNT_TABLE_TITLE } from '../alerts_count_panel/translations'; + +const Wrapper = styled.div` + margin-top: -${({ theme }) => theme.eui.euiSizeM}; +`; +const TableWrapper = styled.div` + height: 178px; +`; + +export interface AlertsByRuleProps { + data: AlertsByRuleData[]; + isLoading: boolean; +} + +const COLUMNS: Array> = [ + { + field: 'rule', + name: ALERTS_HEADERS_RULE_NAME, + 'data-test-subj': 'detectionsTable-rule', + truncateText: true, + render: (rule: string) => ( + + + + ), + }, + { + field: 'value', + name: COUNT_TABLE_TITLE, + dataType: 'number', + sortable: true, + 'data-test-subj': 'detectionsTable-count', + render: (count: number) => ( + + + + ), + width: '22%', + }, +]; + +export const AlertsByRule: React.FC = ({ data, isLoading }) => { + const sorting: { sort: { field: keyof AlertsByRuleData; direction: SortOrder } } = { + sort: { + field: 'value', + direction: 'desc', + }, + }; + + const pagination: {} = { + pageSize: 25, + showPerPageOptions: false, + }; + + return ( + + + + + + + ); +}; + +AlertsByRule.displayName = 'AlertsByRule'; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/helpers.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.test.tsx similarity index 57% rename from x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/helpers.test.tsx rename to x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.test.tsx index e0118b349e6b1..769ca68db475d 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/helpers.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.test.tsx @@ -4,28 +4,11 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { parseAlertsTypeData, parseAlertsRuleData } from './helpers'; -import * as mockType from './mock_type_data'; +import { parseAlertsRuleData } from './helpers'; import * as mockRule from './mock_rule_data'; -import type { AlertsByTypeAgg, AlertsByRuleAgg } from './types'; +import type { AlertsByRuleAgg } from './types'; import type { AlertSearchResponse } from '../../../containers/detection_engine/alerts/types'; -describe('parse alerts by type data', () => { - test('parse alerts with data', () => { - const res = parseAlertsTypeData( - mockType.mockAlertsData as AlertSearchResponse<{}, AlertsByTypeAgg> - ); - expect(res).toEqual(mockType.parsedAlerts); - }); - - test('parse alerts without data', () => { - const res = parseAlertsTypeData( - mockType.mockAlertsEmptyData as AlertSearchResponse<{}, AlertsByTypeAgg> - ); - expect(res).toEqual([]); - }); -}); - describe('parse alerts by rule data', () => { test('parse alerts with data', () => { const res = parseAlertsRuleData( diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.tsx new file mode 100644 index 0000000000000..ceb6a1a91f25f --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.tsx @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { has } from 'lodash'; +import type { AlertsByRuleData, AlertsByRuleAgg } from './types'; +import type { AlertSearchResponse } from '../../../containers/detection_engine/alerts/types'; +import type { SummaryChartsData, SummaryChartsAgg } from '../alerts_summary_charts_panel/types'; + +export const parseAlertsRuleData = ( + response: AlertSearchResponse<{}, AlertsByRuleAgg> +): AlertsByRuleData[] => { + const rulesBuckets = response?.aggregations?.alertsByRule?.buckets ?? []; + + return rulesBuckets.length === 0 + ? [] + : rulesBuckets.map((rule) => { + return { + rule: rule.key, + value: rule.doc_count, + }; + }); +}; + +export const getIsAlertsByRuleData = (data: SummaryChartsData[]): data is AlertsByRuleData[] => { + return data?.every((x) => has(x, 'rule')); +}; + +export const getIsAlertsByRuleAgg = ( + data: AlertSearchResponse<{}, SummaryChartsAgg> +): data is AlertSearchResponse<{}, AlertsByRuleAgg> => { + return has(data, 'aggregations.alertsByRule'); +}; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/index.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/index.test.tsx similarity index 80% rename from x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/index.test.tsx rename to x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/index.test.tsx index 9dbfcfa23af03..387df74772f02 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/index.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/index.test.tsx @@ -7,7 +7,7 @@ import { act, render } from '@testing-library/react'; import React from 'react'; import { TestProviders } from '../../../../common/mock'; -import { AlertsByTypePanel } from '.'; +import { AlertsByRulePanel } from '.'; jest.mock('../../../../common/lib/kibana'); @@ -16,7 +16,7 @@ jest.mock('react-router-dom', () => { return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) }; }); -describe('Alert by type panel', () => { +describe('Alert by rule panel', () => { const defaultProps = { signalIndexName: 'signalIndexName', skip: false, @@ -30,11 +30,11 @@ describe('Alert by type panel', () => { await act(async () => { const { container } = render( - + ); expect( - container.querySelector('[data-test-subj="alerts-by-type-panel"]') + container.querySelector('[data-test-subj="alerts-by-rule-panel"]') ).toBeInTheDocument(); }); }); @@ -43,7 +43,7 @@ describe('Alert by type panel', () => { await act(async () => { const { container } = render( - + ); expect(container.querySelector(`[data-test-subj="header-section"]`)).toBeInTheDocument(); @@ -54,21 +54,21 @@ describe('Alert by type panel', () => { await act(async () => { const { container } = render( - + ); expect(container.querySelector('[data-test-subj="inspect-icon-button"]')).toBeInTheDocument(); }); }); - test('renders alert by type chart', async () => { + test('renders alert by rule chart', async () => { await act(async () => { const { container } = render( - + ); - expect(container.querySelector('[data-test-subj="alerts-by-type"]')).toBeInTheDocument(); + expect(container.querySelector('[data-test-subj="alerts-by-rule"]')).toBeInTheDocument(); }); }); }); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/index.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/index.tsx similarity index 60% rename from x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/index.tsx rename to x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/index.tsx index 92d88d28ec419..98e98698f6083 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/index.tsx @@ -9,32 +9,27 @@ import { EuiPanel } from '@elastic/eui'; import React, { useMemo } from 'react'; import { v4 as uuid } from 'uuid'; import type { ChartsPanelProps } from '../alerts_summary_charts_panel/types'; -import { AlertsByType } from './alerts_by_type'; +import { AlertsByRule } from './alerts_by_rule'; import { HeaderSection } from '../../../../common/components/header_section'; import { InspectButtonContainer } from '../../../../common/components/inspect'; import { useSummaryChartData } from '../alerts_summary_charts_panel/use_summary_chart_data'; -import { - alertTypeAggregations, - alertRuleAggregations, -} from '../alerts_summary_charts_panel/aggregations'; -import { getIsAlertsTypeData } from './helpers'; +import { alertRuleAggregations } from '../alerts_summary_charts_panel/aggregations'; +import { getIsAlertsByRuleData } from './helpers'; import * as i18n from './translations'; -import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; const ALERTS_BY_TYPE_CHART_ID = 'alerts-summary-alert_by_type'; -export const AlertsByTypePanel: React.FC = ({ +export const AlertsByRulePanel: React.FC = ({ filters, query, signalIndexName, runtimeMappings, skip, }) => { - const isAlertTypeEnabled = useIsExperimentalFeatureEnabled('alertTypeEnabled'); const uniqueQueryId = useMemo(() => `${ALERTS_BY_TYPE_CHART_ID}-${uuid()}`, []); const { items, isLoading } = useSummaryChartData({ - aggregations: isAlertTypeEnabled ? alertTypeAggregations : alertRuleAggregations, + aggregations: alertRuleAggregations, filters, query, signalIndexName, @@ -42,23 +37,23 @@ export const AlertsByTypePanel: React.FC = ({ skip, uniqueQueryId, }); - const data = useMemo(() => (getIsAlertsTypeData(items) ? items : []), [items]); + const data = useMemo(() => (getIsAlertsByRuleData(items) ? items : []), [items]); return ( - + - + ); }; -AlertsByTypePanel.displayName = 'AlertsByTypePanel'; +AlertsByRulePanel.displayName = 'AlertsByRulePanel'; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/mock_rule_data.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/mock_rule_data.ts similarity index 85% rename from x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/mock_rule_data.ts rename to x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/mock_rule_data.ts index 62dc3f3f885f1..42d743004bec9 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/mock_rule_data.ts +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/mock_rule_data.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import type { AlertsTypeData } from './types'; +import type { AlertsByRuleData } from './types'; const from = '2022-04-05T12:00:00.000Z'; const to = '2022-04-08T12:00:00.000Z'; @@ -102,8 +102,8 @@ export const query = { runtime_mappings: undefined, }; -export const parsedAlerts: AlertsTypeData[] = [ - { rule: 'Test rule 1', type: 'Detection', value: 537, color: '#D36086' }, - { rule: 'Test rule 2', type: 'Detection', value: 27, color: '#D36086' }, - { rule: 'Test rule 3', type: 'Detection', value: 25, color: '#D36086' }, +export const parsedAlerts: AlertsByRuleData[] = [ + { rule: 'Test rule 1', value: 537 }, + { rule: 'Test rule 2', value: 27 }, + { rule: 'Test rule 3', value: 25 }, ]; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/translations.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/translations.ts new file mode 100644 index 0000000000000..5664f01691821 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/translations.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { i18n } from '@kbn/i18n'; + +export const ALERTS_RULE_TITLE = i18n.translate( + 'xpack.securitySolution.detectionEngine.alerts.alertsByType.alertRuleChartTitle', + { + defaultMessage: 'Alerts by name', + } +); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/types.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/types.ts similarity index 51% rename from x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/types.ts rename to x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/types.ts index 3f1a97096cca7..7cda2fa27df26 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/types.ts +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/types.ts @@ -6,16 +6,6 @@ */ import type { BucketItem } from '../../../../../common/search_strategy/security_solution/cti'; -export type AlertType = 'Detection' | 'Prevention'; - -export interface AlertsByTypeAgg { - alertsByType: { - doc_count_error_upper_bound: number; - sum_other_doc_count: number; - buckets: RuleBucket[]; - }; -} - export interface AlertsByRuleAgg { alertsByRule: { doc_count_error_upper_bound: number; @@ -24,21 +14,7 @@ export interface AlertsByRuleAgg { }; } -interface RuleBucket { - key: string; - doc_count: number; - ruleByEventType?: RuleByEventType; -} - -interface RuleByEventType { - doc_count_error_upper_bound: number; - sum_other_doc_count: number; - buckets: BucketItem[]; -} - -export interface AlertsTypeData { +export interface AlertsByRuleData { rule: string; - type: AlertType; value: number; - color: string; } diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.test.tsx deleted file mode 100644 index 59ceb50ec227e..0000000000000 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.test.tsx +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import { act, render } from '@testing-library/react'; -import React from 'react'; -import { TestProviders } from '../../../../common/mock'; -import { AlertsByType } from './alerts_by_type'; -import { parsedAlerts } from './mock_type_data'; -import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; - -const display = 'alerts-by-type-palette-display'; - -jest.mock('../../../../common/lib/kibana'); - -jest.mock('react-router-dom', () => { - const actual = jest.requireActual('react-router-dom'); - return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) }; -}); - -const mockUseIsExperimentalFeatureEnabled = useIsExperimentalFeatureEnabled as jest.Mock; -jest.mock('../../../../common/hooks/use_experimental_features'); - -describe('Alert by type chart', () => { - const defaultProps = { - data: [], - isLoading: false, - }; - - afterEach(() => { - jest.clearAllMocks(); - }); - - describe('isAlertTypeEnabled flag is true', () => { - beforeEach(() => { - mockUseIsExperimentalFeatureEnabled.mockReturnValue(true); - }); - - test('renders health and pallette display correctly without data', () => { - act(() => { - const { container } = render( - - - - ); - expect(container.querySelector(`[data-test-subj="${display}"]`)).toBeInTheDocument(); - expect(container.querySelector(`[data-test-subj="${display}"]`)?.textContent).toContain( - 'Detection:0' - ); - expect(container.querySelector(`[data-test-subj="${display}"]`)?.textContent).toContain( - 'Prevention:0' - ); - }); - }); - - test('renders table correctly without data', () => { - act(() => { - const { container } = render( - - - - ); - expect( - container.querySelector('[data-test-subj="alerts-by-type-table"]') - ).toBeInTheDocument(); - expect( - container.querySelector('[data-test-subj="alerts-by-type-table"] tbody')?.textContent - ).toEqual('No items found'); - }); - }); - - test('renders health and pallette display correctly with data', () => { - act(() => { - const { container } = render( - - - - ); - expect(container.querySelector(`[data-test-subj="${display}"]`)).toBeInTheDocument(); - expect(container.querySelector(`[data-test-subj="${display}"]`)?.textContent).toContain( - 'Detection:583' - ); - expect(container.querySelector(`[data-test-subj="${display}"]`)?.textContent).toContain( - 'Prevention:6' - ); - }); - }); - - test('renders table correctly with data', () => { - act(() => { - const { queryAllByRole } = render( - - - - ); - - parsedAlerts.forEach((_, i) => { - expect(queryAllByRole('row')[i + 1].textContent).toContain(parsedAlerts[i].rule); - expect(queryAllByRole('row')[i + 1].textContent).toContain(parsedAlerts[i].type); - expect(queryAllByRole('row')[i + 1].textContent).toContain( - parsedAlerts[i].value.toString() - ); - }); - }); - }); - }); - - describe('isAlertTypeEnabled flag is false', () => { - beforeEach(() => { - mockUseIsExperimentalFeatureEnabled.mockReturnValue(false); - }); - - test('do not renders health and pallette display correctly without data', () => { - act(() => { - const { container } = render( - - - - ); - expect(container.querySelector(`[data-test-subj="${display}"]`)).not.toBeInTheDocument(); - }); - }); - - test('renders table correctly without data', () => { - act(() => { - const { container } = render( - - - - ); - expect( - container.querySelector('[data-test-subj="alerts-by-type-table"]') - ).toBeInTheDocument(); - expect( - container.querySelector('[data-test-subj="alerts-by-type-table"] tbody')?.textContent - ).toEqual('No items found'); - }); - }); - - test('do not renders health and pallette display correctly with data', () => { - mockUseIsExperimentalFeatureEnabled.mockReturnValue(false); - act(() => { - const { container } = render( - - - - ); - expect(container.querySelector(`[data-test-subj="${display}"]`)).not.toBeInTheDocument(); - }); - }); - - test('renders table correctly with data', () => { - mockUseIsExperimentalFeatureEnabled.mockReturnValue(false); - act(() => { - const { queryAllByRole } = render( - - - - ); - - parsedAlerts.forEach((_, i) => { - expect(queryAllByRole('row')[i + 1].textContent).toContain(parsedAlerts[i].rule); - expect(queryAllByRole('row')[i + 1].textContent).toContain( - parsedAlerts[i].value.toString() - ); - }); - }); - }); - }); -}); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.tsx deleted file mode 100644 index 5208e74470fa8..0000000000000 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/alerts_by_type.tsx +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - EuiFlexItem, - EuiInMemoryTable, - EuiColorPaletteDisplay, - EuiSpacer, - EuiFlexGroup, - EuiHealth, - EuiText, -} from '@elastic/eui'; -import React, { useMemo } from 'react'; -import styled from 'styled-components'; -import type { SortOrder } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import type { AlertsTypeData, AlertType } from './types'; -import { FormattedCount } from '../../../../common/components/formatted_number'; -import { getAlertsTypeTableColumns } from './columns'; -import { ALERT_TYPE_COLOR } from './helpers'; -import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; - -const Wrapper = styled.div` - margin-top: -${({ theme }) => theme.eui.euiSizeM}; -`; -const TableWrapper = styled.div` - height: 178px; -`; -const StyledEuiColorPaletteDisplay = styled(EuiColorPaletteDisplay)` - border: none; - border-radius: 0; -`; -interface PalletteObject { - stop: number; - color: string; -} - -export interface AlertsByTypeProps { - data: AlertsTypeData[]; - isLoading: boolean; -} - -export const AlertsByType: React.FC = ({ data, isLoading }) => { - const isAlertTypeEnabled = useIsExperimentalFeatureEnabled('alertTypeEnabled'); - const columns = useMemo( - () => getAlertsTypeTableColumns(isAlertTypeEnabled), - [isAlertTypeEnabled] - ); - - const subtotals = useMemo( - () => - data.reduce( - (acc: { Detection: number; Prevention: number }, item: AlertsTypeData) => { - if (item.type === 'Detection') { - acc.Detection += item.value; - } - if (item.type === 'Prevention') { - acc.Prevention += item.value; - } - return acc; - }, - { Detection: 0, Prevention: 0 } - ), - [data] - ); - - const palette: PalletteObject[] = useMemo( - () => - (Object.keys(subtotals) as AlertType[]).reduce((acc: PalletteObject[], type: AlertType) => { - const previousStop = acc.length > 0 ? acc[acc.length - 1].stop : 0; - if (subtotals[type]) { - const newEntry: PalletteObject = { - stop: previousStop + (subtotals[type] || 0), - color: ALERT_TYPE_COLOR[type], - }; - acc.push(newEntry); - } - return acc; - }, [] as PalletteObject[]), - [subtotals] - ); - - const sorting: { sort: { field: keyof AlertsTypeData; direction: SortOrder } } = { - sort: { - field: 'value', - direction: 'desc', - }, - }; - - const pagination: {} = { - pageSize: 25, - showPerPageOptions: false, - }; - - return ( - - {isAlertTypeEnabled && ( - <> - - {(Object.keys(subtotals) as AlertType[]).map((type) => ( - - - - - -

{`${type}:`}

-
-
-
- - - - - -
-
- ))} - -
- - - - )} - - - - -
- ); -}; - -AlertsByType.displayName = 'AlertsByType'; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/columns.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/columns.tsx deleted file mode 100644 index 24dc0cc6690aa..0000000000000 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/columns.tsx +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import React from 'react'; -import { EuiHealth, EuiText } from '@elastic/eui'; -import { ALERT_RULE_NAME } from '@kbn/rule-data-utils'; -import type { EuiBasicTableColumn } from '@elastic/eui'; -import { TableId } from '@kbn/securitysolution-data-table'; -import { - SecurityCellActions, - CellActionsMode, - SecurityCellActionsTrigger, -} from '../../../../common/components/cell_actions'; -import type { AlertsTypeData, AlertType } from './types'; -import { DefaultDraggable } from '../../../../common/components/draggables'; -import { FormattedCount } from '../../../../common/components/formatted_number'; -import { ALERTS_HEADERS_RULE_NAME } from '../../alerts_table/translations'; -import { ALERT_TYPE_COLOR, ALERT_TYPE_LABEL } from './helpers'; -import { COUNT_TABLE_TITLE } from '../alerts_count_panel/translations'; -import * as i18n from './translations'; -import { SourcererScopeName } from '../../../../sourcerer/store/model'; - -export const getAlertsTypeTableColumns = ( - isAlertTypeEnabled: boolean -): Array> => [ - { - field: 'rule', - name: ALERTS_HEADERS_RULE_NAME, - 'data-test-subj': 'detectionsTable-rule', - truncateText: true, - render: (rule: string) => ( - - - - ), - }, - ...(isAlertTypeEnabled - ? [ - { - field: 'type', - name: i18n.ALERTS_TYPE_COLUMN_TITLE, - 'data-test-subj': 'detectionsTable-type', - truncateText: true, - render: (type: string) => { - return ( - - - - {ALERT_TYPE_LABEL[type as AlertType]} - - - - ); - }, - width: '30%', - }, - ] - : []), - { - field: 'value', - name: COUNT_TABLE_TITLE, - dataType: 'number', - sortable: true, - 'data-test-subj': 'detectionsTable-count', - render: (count: number) => ( - - - - ), - width: '22%', - }, -]; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/helpers.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/helpers.tsx deleted file mode 100644 index 5ad677bea154a..0000000000000 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/helpers.tsx +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import { has } from 'lodash'; -import type { AlertType, AlertsByTypeAgg, AlertsTypeData, AlertsByRuleAgg } from './types'; -import type { AlertSearchResponse } from '../../../containers/detection_engine/alerts/types'; -import type { SummaryChartsData, SummaryChartsAgg } from '../alerts_summary_charts_panel/types'; -import { DETECTION, PREVENTION } from './translations'; - -export const ALERT_TYPE_COLOR = { - Detection: '#D36086', - Prevention: '#54B399', -}; -export const ALERT_TYPE_LABEL = { - Detection: DETECTION, - Prevention: PREVENTION, -}; - -export const parseAlertsRuleData = ( - response: AlertSearchResponse<{}, AlertsByRuleAgg> -): AlertsTypeData[] => { - const rulesBuckets = response?.aggregations?.alertsByRule?.buckets ?? []; - - return rulesBuckets.length === 0 - ? [] - : rulesBuckets.map((rule) => { - return { - rule: rule.key, - type: 'Detection' as AlertType, - value: rule.doc_count, - color: ALERT_TYPE_COLOR.Detection, - }; - }); -}; - -export const parseAlertsTypeData = ( - response: AlertSearchResponse<{}, AlertsByTypeAgg> -): AlertsTypeData[] => { - const rulesBuckets = response?.aggregations?.alertsByType?.buckets ?? []; - return rulesBuckets.length === 0 - ? [] - : rulesBuckets.flatMap((rule) => { - const events = rule.ruleByEventType?.buckets ?? []; - return getAlertType(rule.key, rule.doc_count, events); - }); -}; - -const getAlertType = ( - ruleName: string, - ruleCount: number, - ruleEvents: Array<{ key: string; doc_count: number }> -): AlertsTypeData[] => { - const preventions = ruleEvents.find((bucket) => bucket.key === 'denied'); - if (!preventions) { - return [ - { - rule: ruleName, - type: 'Detection' as AlertType, - value: ruleCount, - color: ALERT_TYPE_COLOR.Detection, - }, - ]; - } - - const ret = []; - if (preventions.doc_count < ruleCount) { - ret.push({ - rule: ruleName, - type: 'Detection' as AlertType, - value: ruleCount - preventions.doc_count, - color: ALERT_TYPE_COLOR.Detection, - }); - } - - ret.push({ - rule: ruleName, - type: 'Prevention' as AlertType, - value: preventions.doc_count, - color: ALERT_TYPE_COLOR.Prevention, - }); - - return ret; -}; - -export const getIsAlertsTypeData = (data: SummaryChartsData[]): data is AlertsTypeData[] => { - return data?.every((x) => has(x, 'type')); -}; - -export const getIsAlertsByTypeAgg = ( - data: AlertSearchResponse<{}, SummaryChartsAgg> -): data is AlertSearchResponse<{}, AlertsByTypeAgg> => { - return has(data, 'aggregations.alertsByType'); -}; - -export const getIsAlertsByRuleAgg = ( - data: AlertSearchResponse<{}, SummaryChartsAgg> -): data is AlertSearchResponse<{}, AlertsByRuleAgg> => { - return has(data, 'aggregations.alertsByRule'); -}; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/mock_type_data.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/mock_type_data.ts deleted file mode 100644 index 4c9cea8e63206..0000000000000 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/mock_type_data.ts +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import type { AlertsTypeData } from './types'; - -const from = '2022-04-05T12:00:00.000Z'; -const to = '2022-04-08T12:00:00.000Z'; - -export const mockAlertsData = { - took: 0, - timeout: false, - _shards: { - total: 1, - successful: 1, - skipped: 0, - failed: 0, - }, - hits: { - total: { - value: 589, - relation: 'eq', - }, - max_score: null, - hits: [], - }, - aggregations: { - alertsByType: { - doc_count_error_upper_bound: 0, - sum_other_doc_count: 0, - buckets: [ - { - key: 'Test rule 1', - doc_count: 537, - ruleByEventType: { - doc_count_error_upper_bound: 0, - sum_other_doc_count: 0, - buckets: [ - { - key: 'info', - doc_count: 406, - }, - { - key: 'creation', - doc_count: 131, - }, - ], - }, - }, - { - key: 'Test rule 2', - doc_count: 27, - ruleByEventType: { - doc_count_error_upper_bound: 0, - sum_other_doc_count: 0, - buckets: [ - { - key: 'info', - doc_count: 19, - }, - { - key: 'creation', - doc_count: 8, - }, - ], - }, - }, - { - key: 'Test rule 3', - doc_count: 25, - ruleByEventType: { - doc_count_error_upper_bound: 0, - sum_other_doc_count: 0, - buckets: [ - { - key: 'info', - doc_count: 19, - }, - { - key: 'denied', - doc_count: 6, - }, - ], - }, - }, - ], - }, - }, -}; - -export const mockAlertsEmptyData = { - took: 0, - timeout: false, - _shards: { - total: 1, - successful: 1, - skipped: 0, - failed: 0, - }, - hits: { - total: { - value: 0, - relation: 'eq', - }, - max_score: null, - hits: [], - }, - aggregations: { - alertsByType: { - doc_count_error_upper_bound: 0, - sum_other_doc_count: 0, - buckets: [], - }, - }, -}; - -export const query = { - size: 0, - query: { - bool: { - filter: [ - { - bool: { - filter: [], - must: [], - must_not: [], - should: [], - }, - }, - { range: { '@timestamp': { gte: from, lte: to } } }, - ], - }, - }, - aggs: { - alertsByType: { - terms: { - field: 'kibana.alert.rule.name', - size: 1000, - }, - aggs: { - ruleByEventType: { - terms: { - field: 'event.type', - size: 1000, - }, - }, - }, - }, - }, - runtime_mappings: undefined, -}; - -export const parsedAlerts: AlertsTypeData[] = [ - { rule: 'Test rule 1', type: 'Detection', value: 537, color: '#D36086' }, - { rule: 'Test rule 2', type: 'Detection', value: 27, color: '#D36086' }, - { rule: 'Test rule 3', type: 'Detection', value: 19, color: '#D36086' }, - { rule: 'Test rule 3', type: 'Prevention', value: 6, color: '#54B399' }, -]; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/translations.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/translations.ts deleted file mode 100644 index 66fa31c29a448..0000000000000 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_by_type_panel/translations.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import { i18n } from '@kbn/i18n'; - -export const ALERTS_TYPE_TITLE = i18n.translate( - 'xpack.securitySolution.detectionEngine.alerts.alertsByType.alertTypeChartTitle', - { - defaultMessage: 'Alerts by type', - } -); - -export const ALERTS_RULE_TITLE = i18n.translate( - 'xpack.securitySolution.detectionEngine.alerts.alertsByType.alertRuleChartTitle', - { - defaultMessage: 'Alerts by name', - } -); - -export const ALERTS_TYPE_COLUMN_TITLE = i18n.translate( - 'xpack.securitySolution.detectionEngine.alerts.alertsByType.typeColumn', - { - defaultMessage: 'Type', - } -); - -export const PREVENTIONS = i18n.translate( - 'xpack.securitySolution.detectionEngine.alerts.alertsByType.preventions', - { - defaultMessage: 'Preventions', - } -); - -export const DETECTIONS = i18n.translate( - 'xpack.securitySolution.detectionEngine.alerts.alertsByType.detections', - { - defaultMessage: 'Detections', - } -); - -export const PREVENTION = i18n.translate( - 'xpack.securitySolution.detectionEngine.alerts.alertsByType.prevention', - { - defaultMessage: 'Prevention', - } -); - -export const DETECTION = i18n.translate( - 'xpack.securitySolution.detectionEngine.alerts.alertsByType.detection', - { - defaultMessage: 'Detection', - } -); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/aggregations.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/aggregations.ts index dd646a20931f6..2cf83768e510d 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/aggregations.ts +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/aggregations.ts @@ -17,23 +17,6 @@ export const severityAggregations = { }, }; -export const alertTypeAggregations = { - alertsByType: { - terms: { - field: ALERT_RULE_NAME, - size: DEFAULT_QUERY_SIZE, - }, - aggs: { - ruleByEventType: { - terms: { - field: 'event.type', - size: DEFAULT_QUERY_SIZE, - }, - }, - }, - }, -}; - export const alertRuleAggregations = { alertsByRule: { terms: { diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.test.tsx index 7ff8c949e0624..3f8df968204e4 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.test.tsx @@ -6,8 +6,7 @@ */ import { parseData } from './helpers'; import * as severityMock from '../severity_level_panel/mock_data'; -import * as alertsTypeMock from '../alerts_by_type_panel/mock_type_data'; -import * as alertsRuleMock from '../alerts_by_type_panel/mock_rule_data'; +import * as alertsRuleMock from '../alerts_by_rule_panel/mock_rule_data'; import * as alertsGroupingMock from '../alerts_progress_bar_panel/mock_data'; import type { SummaryChartsAgg } from './types'; import type { AlertSearchResponse } from '../../../containers/detection_engine/alerts/types'; @@ -18,12 +17,7 @@ describe('parse data by aggregation type', () => { expect(res).toEqual(severityMock.parsedAlerts); }); - test('parse alert type data', () => { - const resType = parseData( - alertsTypeMock.mockAlertsData as AlertSearchResponse<{}, SummaryChartsAgg> - ); - expect(resType).toEqual(alertsTypeMock.parsedAlerts); - + test('parse alert by rule data', () => { const resRule = parseData( alertsRuleMock.mockAlertsData as AlertSearchResponse<{}, SummaryChartsAgg> ); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.tsx index 03f8571aa8bc0..12007bd3f7e00 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/helpers.tsx @@ -7,12 +7,7 @@ import type { SummaryChartsAgg } from './types'; import type { AlertSearchResponse } from '../../../containers/detection_engine/alerts/types'; import { parseSeverityData, getIsAlertsBySeverityAgg } from '../severity_level_panel/helpers'; -import { - parseAlertsTypeData, - getIsAlertsByTypeAgg, - parseAlertsRuleData, - getIsAlertsByRuleAgg, -} from '../alerts_by_type_panel/helpers'; +import { parseAlertsRuleData, getIsAlertsByRuleAgg } from '../alerts_by_rule_panel/helpers'; import { parseAlertsGroupingData, getIsAlertsByGroupingAgg, @@ -26,9 +21,6 @@ export const parseData = (data: AlertSearchResponse<{}, SummaryChartsAgg>) => { if (getIsAlertsBySeverityAgg(data)) { return parseSeverityData(data); } - if (getIsAlertsByTypeAgg(data)) { - return parseAlertsTypeData(data); - } if (getIsAlertsByRuleAgg(data)) { return parseAlertsRuleData(data); } diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/index.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/index.tsx index ff1597a0246af..9cdd6608f34f8 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/index.tsx @@ -13,7 +13,7 @@ import * as i18n from './translations'; import { KpiPanel } from '../common/components'; import { HeaderSection } from '../../../../common/components/header_section'; import { SeverityLevelPanel } from '../severity_level_panel'; -import { AlertsByTypePanel } from '../alerts_by_type_panel'; +import { AlertsByRulePanel } from '../alerts_by_rule_panel'; import { AlertsProgressBarPanel } from '../alerts_progress_bar_panel'; import { useQueryToggle } from '../../../../common/containers/query_toggle'; import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; @@ -125,7 +125,7 @@ export const AlertsSummaryChartsPanel: React.FC = ({ /> - ; export type SummaryChartsData = | SeverityData - | AlertsTypeData + | AlertsByRuleData | AlertsProgressBarData | ChartCollapseData; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx index 7719fd47ea606..4949fa9a2855f 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx @@ -12,8 +12,7 @@ import type { UseAlerts, UseAlertsQueryProps } from './use_summary_chart_data'; import { useSummaryChartData, getAlertsQuery } from './use_summary_chart_data'; import * as aggregations from './aggregations'; import * as severityMock from '../severity_level_panel/mock_data'; -import * as alertTypeMock from '../alerts_by_type_panel/mock_type_data'; -import * as alertRuleMock from '../alerts_by_type_panel/mock_rule_data'; +import * as alertRuleMock from '../alerts_by_rule_panel/mock_rule_data'; import * as alertsGroupingMock from '../alerts_progress_bar_panel/mock_data'; import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; @@ -66,25 +65,6 @@ describe('getAlertsQuery', () => { ).toEqual(severityMock.query); }); - test('it returns the expected alerts by type query', () => { - expect( - getAlertsQuery({ - from, - to, - additionalFilters, - aggregations: aggregations.alertTypeAggregations, - }) - ).toEqual(alertTypeMock.query); - expect( - getAlertsQuery({ - from, - to, - additionalFilters, - aggregations: aggregations.alertRuleAggregations, - }) - ).toEqual(alertRuleMock.query); - }); - test('it returns the expected alerts by grouping query', () => { expect( getAlertsQuery({ @@ -192,28 +172,9 @@ describe('get summary charts data', () => { jest.clearAllMocks(); mockDateNow.mockReturnValue(dateNow); mockUseQueryAlerts.mockReturnValue(defaultUseQueryAlertsReturn); - mockUseIsExperimentalFeatureEnabled.mockReturnValue(true); - }); - it('should return correct default values when alertsTypeChartsEnabled is true', () => { - const { result } = renderUseSummaryChartData({ - aggregations: aggregations.alertTypeAggregations, - }); - - expect(result.current).toEqual({ - items: [], - isLoading: false, - updatedAt: dateNow, - }); - - expect(mockUseQueryAlerts).toBeCalledWith({ - query: alertTypeMock.query, - indexName: 'signal-alerts', - skip: false, - queryName: ALERTS_QUERY_NAMES.COUNT, - }); }); - it('should return correct default values when alertsTypeChartsEnabled is false', () => { + it('should return correct default values', () => { mockUseIsExperimentalFeatureEnabled.mockReturnValue(false); const { result } = renderUseSummaryChartData({ aggregations: aggregations.alertRuleAggregations, @@ -233,23 +194,7 @@ describe('get summary charts data', () => { }); }); - it('should return parsed alerts by type items when alertsTypeChartsEnabled is true', () => { - mockUseQueryAlerts.mockReturnValue({ - ...defaultUseQueryAlertsReturn, - data: alertTypeMock.mockAlertsData, - }); - - const { result } = renderUseSummaryChartData({ - aggregations: aggregations.alertTypeAggregations, - }); - expect(result.current).toEqual({ - items: alertTypeMock.parsedAlerts, - isLoading: false, - updatedAt: dateNow, - }); - }); - - it('should return parsed alerts by type items when alertsTypeChartsEnabled is false', () => { + it('should return parsed alerts by type items', () => { mockUseIsExperimentalFeatureEnabled.mockReturnValue(false); mockUseQueryAlerts.mockReturnValue({ ...defaultUseQueryAlertsReturn, diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 62ce477ecca04..4d44c2936ba38 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -33651,12 +33651,6 @@ "xpack.securitySolution.detectionEngine.alerts.alertsByGrouping.sourceLabel": "source", "xpack.securitySolution.detectionEngine.alerts.alertsByGrouping.userNameLabel": "utilisateur", "xpack.securitySolution.detectionEngine.alerts.alertsByType.alertRuleChartTitle": "Alertes par nom", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.alertTypeChartTitle": "Alertes par type", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.detection": "Détection", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.detections": "Détections", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.prevention": "Prévention", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.preventions": "Préventions", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.typeColumn": "Type", "xpack.securitySolution.detectionEngine.alerts.chartsTitle": "Graphiques", "xpack.securitySolution.detectionEngine.alerts.closedAlertFailedToastMessage": "Impossible de fermer l'alerte ou les alertes.", "xpack.securitySolution.detectionEngine.alerts.closedAlertsTitle": "Fermé", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index bba91c32ffc4c..57abf3a495c64 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -33523,12 +33523,6 @@ "xpack.securitySolution.detectionEngine.alerts.alertsByGrouping.sourceLabel": "ソース", "xpack.securitySolution.detectionEngine.alerts.alertsByGrouping.userNameLabel": "ユーザー", "xpack.securitySolution.detectionEngine.alerts.alertsByType.alertRuleChartTitle": "名前別アラート", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.alertTypeChartTitle": "タイプ別アラート", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.detection": "検知", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.detections": "検出", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.prevention": "防御", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.preventions": "防御", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.typeColumn": "型", "xpack.securitySolution.detectionEngine.alerts.chartsTitle": "チャート", "xpack.securitySolution.detectionEngine.alerts.closedAlertFailedToastMessage": "アラートをクローズできませんでした。", "xpack.securitySolution.detectionEngine.alerts.closedAlertsTitle": "対応済", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index b2fb6ec9b4f02..3bbdc2e2859c5 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -33691,12 +33691,6 @@ "xpack.securitySolution.detectionEngine.alerts.alertsByGrouping.sourceLabel": "源", "xpack.securitySolution.detectionEngine.alerts.alertsByGrouping.userNameLabel": "user", "xpack.securitySolution.detectionEngine.alerts.alertsByType.alertRuleChartTitle": "按名称排列的告警", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.alertTypeChartTitle": "按类型排列的告警", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.detection": "检测", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.detections": "检测", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.prevention": "防护", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.preventions": "防护", - "xpack.securitySolution.detectionEngine.alerts.alertsByType.typeColumn": "类型", "xpack.securitySolution.detectionEngine.alerts.chartsTitle": "图表", "xpack.securitySolution.detectionEngine.alerts.closedAlertFailedToastMessage": "无法关闭告警。", "xpack.securitySolution.detectionEngine.alerts.closedAlertsTitle": "已关闭",