From 609bf6ce43cb5aaf88d4742042ceaf891c2ae72e Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 26 Jan 2023 13:05:42 +0000 Subject: [PATCH] revert alert treemap and chart --- .../components/alerts_treemap_panel/index.tsx | 28 +- .../common/components/charts/donutchart.tsx | 10 +- .../alerts_by_severity_table.test.ts.snap | 161 ------ .../__snapshots__/alerts_treemap.test.ts.snap | 532 ------------------ .../alerts/alerts_by_severity_table.test.ts | 63 --- .../common/alerts/alerts_by_severity_table.ts | 131 ----- .../common/alerts/alerts_treemap.test.ts | 100 ---- .../common/alerts/alerts_treemap.ts | 138 ----- .../alerts_summary_charts_panel/index.tsx | 12 +- .../severity_donut/severity_level_chart.tsx | 73 +-- .../use_severity_chart_data.test.tsx | 9 +- .../severity_donut/use_severity_chart_data.ts | 4 +- 12 files changed, 28 insertions(+), 1233 deletions(-) delete mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_by_severity_table.test.ts.snap delete mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_treemap.test.ts.snap delete mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.test.ts delete mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.ts delete mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.test.ts delete mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.ts diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx b/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx index dd94d0c8d16e3..bc1a247d1ad26 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx @@ -26,9 +26,6 @@ import { InspectButtonContainer } from '../inspect'; import { DEFAULT_STACK_BY_FIELD0_SIZE, getAlertsRiskQuery } from '../alerts_treemap/query'; import type { AlertsTreeMapAggregation } from '../alerts_treemap/types'; import { useIsExperimentalFeatureEnabled } from '../../hooks/use_experimental_features'; -import { getAlertsTreemapLensAttributes as getLensAttributes } from '../visualization_actions/lens_attributes/common/alerts/alerts_treemap'; -import { SourcererScopeName } from '../../store/sourcerer/model'; -import { VisualizationEmbeddable } from '../visualization_actions/visualization_embeddable'; const DEFAULT_HEIGHT = DEFAULT_MIN_CHART_HEIGHT + 134; // px @@ -92,15 +89,6 @@ const AlertsTreemapPanelComponent: React.FC = ({ // create a unique, but stable (across re-renders) query id const uniqueQueryId = useMemo(() => `${ALERTS_TREEMAP_ID}-${uuidv4()}`, []); const isChartEmbeddablesEnabled = useIsExperimentalFeatureEnabled('chartEmbeddablesEnabled'); - const timerange = useMemo(() => ({ from, to }), [from, to]); - - const extraVisualizationOptions = useMemo( - () => ({ - breakdownField: stackByField1, - filters, - }), - [stackByField1, filters] - ); const additionalFilters = useMemo(() => { try { @@ -133,7 +121,7 @@ const AlertsTreemapPanelComponent: React.FC = ({ stackByField1, to, }), - skip: !isPanelExpanded || isChartEmbeddablesEnabled, + skip: !isPanelExpanded, indexName: signalIndexName, queryName: ALERTS_QUERY_NAMES.TREE_MAP, }); @@ -213,19 +201,7 @@ const AlertsTreemapPanelComponent: React.FC = ({ {isPanelExpanded ? ( - isChartEmbeddablesEnabled && getLensAttributes && timerange ? ( - - ) : isLoadingAlerts ? ( + isLoadingAlerts ? ( ) : ( <> diff --git a/x-pack/plugins/security_solution/public/common/components/charts/donutchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/donutchart.tsx index ea6c8444c0fad..8b968077f3dcb 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/donutchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/donutchart.tsx @@ -66,10 +66,10 @@ export interface DonutChartWrapperProps { /* Make this position absolute in order to overlap the text onto the donut */ export const DonutTextWrapper = styled(EuiFlexGroup)< EuiFlexGroupProps & { - $isChartEmbeddablesEnabled?: boolean; $dataExists?: boolean; + $donutTextWrapperStyles?: FlattenSimpleInterpolation; + $isChartEmbeddablesEnabled?: boolean; className?: string; - donutTextWrapperStyles?: FlattenSimpleInterpolation; } >` top: ${({ $isChartEmbeddablesEnabled, $dataExists }) => @@ -79,8 +79,8 @@ export const DonutTextWrapper = styled(EuiFlexGroup)< position: absolute; z-index: 1; - ${({ className, donutTextWrapperStyles }) => - className && donutTextWrapperStyles ? `&.${className} {${donutTextWrapperStyles}}` : ''} + ${({ className, $donutTextWrapperStyles }) => + className && $donutTextWrapperStyles ? `&.${className} {${$donutTextWrapperStyles}}` : ''} `; export const StyledEuiFlexItem = styled(EuiFlexItem)` @@ -116,11 +116,11 @@ const DonutChartWrapperComponent: React.FC = ({ diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_by_severity_table.test.ts.snap b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_by_severity_table.test.ts.snap deleted file mode 100644 index 3447332aaea96..0000000000000 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_by_severity_table.test.ts.snap +++ /dev/null @@ -1,161 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`getAlertsBySeverityTableAttributes should render without extra options 1`] = ` -Object { - "description": "", - "references": Array [ - Object { - "id": "security-solution-my-test", - "name": "indexpattern-datasource-layer-b9b43606-7ff7-46ae-a47c-85bed80fab9a", - "type": "index-pattern", - }, - Object { - "id": "security-solution-my-test", - "name": "22752b9b-cfcd-43f0-a6ee-27dd4893edcf", - "type": "index-pattern", - }, - ], - "state": Object { - "adHocDataViews": Object {}, - "datasourceStates": Object { - "formBased": Object { - "layers": Object { - "b9b43606-7ff7-46ae-a47c-85bed80fab9a": Object { - "columnOrder": Array [ - "a9b43606-7ff7-46ae-a47c-85bed80fab9a", - "21cc4a49-3780-4b1a-be28-f02fa5303d24", - ], - "columns": Object { - "21cc4a49-3780-4b1a-be28-f02fa5303d24": Object { - "dataType": "number", - "filter": Object { - "language": "kuery", - "query": "", - }, - "isBucketed": false, - "label": "Count of records", - "operationType": "count", - "params": Object { - "emptyAsNull": true, - }, - "scale": "ratio", - "sourceField": "___records___", - }, - "a9b43606-7ff7-46ae-a47c-85bed80fab9a": Object { - "dataType": "string", - "isBucketed": true, - "label": "Filters", - "operationType": "filters", - "params": Object { - "filters": Array [ - Object { - "input": Object { - "language": "kuery", - "query": "kibana.alert.severity: \\"critical\\"", - }, - "label": "Critical", - }, - Object { - "input": Object { - "language": "kuery", - "query": "kibana.alert.severity : \\"high\\"", - }, - "label": "High", - }, - Object { - "input": Object { - "language": "kuery", - "query": "kibana.alert.severity: \\"medium\\"", - }, - "label": "Medium", - }, - Object { - "input": Object { - "language": "kuery", - "query": "kibana.alert.severity : \\"low\\"", - }, - "label": "Low", - }, - ], - }, - "scale": "ordinal", - }, - }, - "incompleteColumns": Object {}, - "sampling": 1, - }, - }, - }, - "textBased": Object { - "layers": Object {}, - }, - }, - "filters": Array [ - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "host.id", - "negate": false, - "params": Object { - "query": "123", - }, - "type": "phrase", - }, - "query": Object { - "match_phrase": Object { - "host.id": "123", - }, - }, - }, - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "_index", - "negate": false, - "params": Array [ - "signal-index", - ], - "type": "phrases", - }, - "query": Object { - "bool": Object { - "minimum_should_match": 1, - "should": Array [ - Object { - "match_phrase": Object { - "_index": "signal-index", - }, - }, - ], - }, - }, - }, - ], - "internalReferences": Array [], - "query": Object { - "language": "kql", - "query": "host.name: *", - }, - "visualization": Object { - "columns": Array [ - Object { - "columnId": "a9b43606-7ff7-46ae-a47c-85bed80fab9a", - }, - Object { - "columnId": "21cc4a49-3780-4b1a-be28-f02fa5303d24", - }, - ], - "headerRowHeight": "custom", - "headerRowHeightLines": 0.6, - "layerId": "b9b43606-7ff7-46ae-a47c-85bed80fab9a", - "layerType": "data", - "rowHeight": "custom", - "rowHeightLines": 0.8, - }, - }, - "title": "Alerts", - "visualizationType": "lnsDatatable", -} -`; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_treemap.test.ts.snap b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_treemap.test.ts.snap deleted file mode 100644 index 981bb217aae6e..0000000000000 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/__snapshots__/alerts_treemap.test.ts.snap +++ /dev/null @@ -1,532 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`getAlertsTreemapLensAttributes should render with extra options - breakdownField 1`] = ` -Object { - "description": "", - "references": Array [ - Object { - "id": "security-solution-my-test", - "name": "indexpattern-datasource-layer-4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b", - "type": "index-pattern", - }, - ], - "state": Object { - "adHocDataViews": Object {}, - "datasourceStates": Object { - "formBased": Object { - "layers": Object { - "4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b": Object { - "columnOrder": Array [ - "2881fedd-54b7-42ba-8c97-5175dec86166", - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059", - "f04a71a3-399f-4d32-9efc-8a005e989991", - ], - "columns": Object { - "2881fedd-54b7-42ba-8c97-5175dec86166": Object { - "dataType": "string", - "isBucketed": true, - "label": "Top values of event.category", - "operationType": "terms", - "params": Object { - "exclude": Array [], - "excludeIsRegex": false, - "include": Array [], - "includeIsRegex": false, - "missingBucket": false, - "orderBy": Object { - "columnId": "f04a71a3-399f-4d32-9efc-8a005e989991", - "type": "column", - }, - "orderDirection": "desc", - "otherBucket": true, - "parentFormat": Object { - "id": "terms", - }, - "size": 1000, - }, - "scale": "ordinal", - "sourceField": "event.category", - }, - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059": Object { - "dataType": "string", - "isBucketed": true, - "label": "Top values of agent.type", - "operationType": "terms", - "params": Object { - "exclude": Array [], - "excludeIsRegex": false, - "include": Array [], - "includeIsRegex": false, - "missingBucket": false, - "orderBy": Object { - "columnId": "f04a71a3-399f-4d32-9efc-8a005e989991", - "type": "column", - }, - "orderDirection": "desc", - "otherBucket": true, - "parentFormat": Object { - "id": "terms", - }, - "size": 1000, - }, - "scale": "ordinal", - "sourceField": "agent.type", - }, - "f04a71a3-399f-4d32-9efc-8a005e989991": Object { - "dataType": "number", - "isBucketed": false, - "label": "Maximum of kibana.alert.risk_score", - "operationType": "max", - "params": Object { - "emptyAsNull": true, - }, - "scale": "ratio", - "sourceField": "kibana.alert.risk_score", - }, - }, - "incompleteColumns": Object {}, - "sampling": 1, - }, - }, - }, - "textBased": Object { - "layers": Object {}, - }, - }, - "filters": Array [ - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "host.id", - "negate": false, - "params": Object { - "query": "123", - }, - "type": "phrase", - }, - "query": Object { - "match_phrase": Object { - "host.id": "123", - }, - }, - }, - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "_index", - "negate": false, - "params": Array [ - "signal-index", - ], - "type": "phrases", - }, - "query": Object { - "bool": Object { - "minimum_should_match": 1, - "should": Array [ - Object { - "match_phrase": Object { - "_index": "signal-index", - }, - }, - ], - }, - }, - }, - ], - "internalReferences": Array [], - "query": Object { - "language": "kql", - "query": "host.name: *", - }, - "visualization": Object { - "layers": Array [ - Object { - "categoryDisplay": "default", - "layerId": "4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b", - "layerType": "data", - "legendDisplay": "show", - "legendPosition": "left", - "legendSize": "xlarge", - "metrics": Array [ - "f04a71a3-399f-4d32-9efc-8a005e989991", - ], - "nestedLegend": true, - "numberDisplay": "value", - "primaryGroups": Array [ - "2881fedd-54b7-42ba-8c97-5175dec86166", - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059", - ], - }, - ], - "shape": "treemap", - }, - }, - "title": "Alerts", - "visualizationType": "lnsPie", -} -`; - -exports[`getAlertsTreemapLensAttributes should render with extra options - filters 1`] = ` -Object { - "description": "", - "references": Array [ - Object { - "id": "security-solution-my-test", - "name": "indexpattern-datasource-layer-4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b", - "type": "index-pattern", - }, - ], - "state": Object { - "adHocDataViews": Object {}, - "datasourceStates": Object { - "formBased": Object { - "layers": Object { - "4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b": Object { - "columnOrder": Array [ - "2881fedd-54b7-42ba-8c97-5175dec86166", - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059", - "f04a71a3-399f-4d32-9efc-8a005e989991", - ], - "columns": Object { - "2881fedd-54b7-42ba-8c97-5175dec86166": Object { - "dataType": "string", - "isBucketed": true, - "label": "Top values of event.category", - "operationType": "terms", - "params": Object { - "exclude": Array [], - "excludeIsRegex": false, - "include": Array [], - "includeIsRegex": false, - "missingBucket": false, - "orderBy": Object { - "columnId": "f04a71a3-399f-4d32-9efc-8a005e989991", - "type": "column", - }, - "orderDirection": "desc", - "otherBucket": true, - "parentFormat": Object { - "id": "terms", - }, - "size": 1000, - }, - "scale": "ordinal", - "sourceField": "event.category", - }, - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059": Object { - "dataType": "string", - "isBucketed": true, - "label": "Top values of undefined", - "operationType": "terms", - "params": Object { - "exclude": Array [], - "excludeIsRegex": false, - "include": Array [], - "includeIsRegex": false, - "missingBucket": false, - "orderBy": Object { - "columnId": "f04a71a3-399f-4d32-9efc-8a005e989991", - "type": "column", - }, - "orderDirection": "desc", - "otherBucket": true, - "parentFormat": Object { - "id": "terms", - }, - "size": 1000, - }, - "scale": "ordinal", - "sourceField": undefined, - }, - "f04a71a3-399f-4d32-9efc-8a005e989991": Object { - "dataType": "number", - "isBucketed": false, - "label": "Maximum of kibana.alert.risk_score", - "operationType": "max", - "params": Object { - "emptyAsNull": true, - }, - "scale": "ratio", - "sourceField": "kibana.alert.risk_score", - }, - }, - "incompleteColumns": Object {}, - "sampling": 1, - }, - }, - }, - "textBased": Object { - "layers": Object {}, - }, - }, - "filters": Array [ - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "_index", - "negate": false, - "params": Array [ - ".alerts-security.alerts-default", - ], - "type": "phrases", - }, - "query": Object { - "bool": Object { - "minimum_should_match": 1, - "should": Array [ - Object { - "match_phrase": Object { - "_index": ".alerts-security.alerts-default", - }, - }, - ], - }, - }, - }, - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "host.id", - "negate": false, - "params": Object { - "query": "123", - }, - "type": "phrase", - }, - "query": Object { - "match_phrase": Object { - "host.id": "123", - }, - }, - }, - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "_index", - "negate": false, - "params": Array [ - "signal-index", - ], - "type": "phrases", - }, - "query": Object { - "bool": Object { - "minimum_should_match": 1, - "should": Array [ - Object { - "match_phrase": Object { - "_index": "signal-index", - }, - }, - ], - }, - }, - }, - ], - "internalReferences": Array [], - "query": Object { - "language": "kql", - "query": "host.name: *", - }, - "visualization": Object { - "layers": Array [ - Object { - "categoryDisplay": "default", - "layerId": "4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b", - "layerType": "data", - "legendDisplay": "show", - "legendPosition": "left", - "legendSize": "xlarge", - "metrics": Array [ - "f04a71a3-399f-4d32-9efc-8a005e989991", - ], - "nestedLegend": true, - "numberDisplay": "value", - "primaryGroups": Array [ - "2881fedd-54b7-42ba-8c97-5175dec86166", - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059", - ], - }, - ], - "shape": "treemap", - }, - }, - "title": "Alerts", - "visualizationType": "lnsPie", -} -`; - -exports[`getAlertsTreemapLensAttributes should render without extra options 1`] = ` -Object { - "description": "", - "references": Array [ - Object { - "id": "security-solution-my-test", - "name": "indexpattern-datasource-layer-4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b", - "type": "index-pattern", - }, - ], - "state": Object { - "adHocDataViews": Object {}, - "datasourceStates": Object { - "formBased": Object { - "layers": Object { - "4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b": Object { - "columnOrder": Array [ - "2881fedd-54b7-42ba-8c97-5175dec86166", - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059", - "f04a71a3-399f-4d32-9efc-8a005e989991", - ], - "columns": Object { - "2881fedd-54b7-42ba-8c97-5175dec86166": Object { - "dataType": "string", - "isBucketed": true, - "label": "Top values of event.category", - "operationType": "terms", - "params": Object { - "exclude": Array [], - "excludeIsRegex": false, - "include": Array [], - "includeIsRegex": false, - "missingBucket": false, - "orderBy": Object { - "columnId": "f04a71a3-399f-4d32-9efc-8a005e989991", - "type": "column", - }, - "orderDirection": "desc", - "otherBucket": true, - "parentFormat": Object { - "id": "terms", - }, - "size": 1000, - }, - "scale": "ordinal", - "sourceField": "event.category", - }, - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059": Object { - "dataType": "string", - "isBucketed": true, - "label": "Top values of undefined", - "operationType": "terms", - "params": Object { - "exclude": Array [], - "excludeIsRegex": false, - "include": Array [], - "includeIsRegex": false, - "missingBucket": false, - "orderBy": Object { - "columnId": "f04a71a3-399f-4d32-9efc-8a005e989991", - "type": "column", - }, - "orderDirection": "desc", - "otherBucket": true, - "parentFormat": Object { - "id": "terms", - }, - "size": 1000, - }, - "scale": "ordinal", - "sourceField": undefined, - }, - "f04a71a3-399f-4d32-9efc-8a005e989991": Object { - "dataType": "number", - "isBucketed": false, - "label": "Maximum of kibana.alert.risk_score", - "operationType": "max", - "params": Object { - "emptyAsNull": true, - }, - "scale": "ratio", - "sourceField": "kibana.alert.risk_score", - }, - }, - "incompleteColumns": Object {}, - "sampling": 1, - }, - }, - }, - "textBased": Object { - "layers": Object {}, - }, - }, - "filters": Array [ - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "host.id", - "negate": false, - "params": Object { - "query": "123", - }, - "type": "phrase", - }, - "query": Object { - "match_phrase": Object { - "host.id": "123", - }, - }, - }, - Object { - "meta": Object { - "alias": null, - "disabled": false, - "key": "_index", - "negate": false, - "params": Array [ - "signal-index", - ], - "type": "phrases", - }, - "query": Object { - "bool": Object { - "minimum_should_match": 1, - "should": Array [ - Object { - "match_phrase": Object { - "_index": "signal-index", - }, - }, - ], - }, - }, - }, - ], - "internalReferences": Array [], - "query": Object { - "language": "kql", - "query": "host.name: *", - }, - "visualization": Object { - "layers": Array [ - Object { - "categoryDisplay": "default", - "layerId": "4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b", - "layerType": "data", - "legendDisplay": "show", - "legendPosition": "left", - "legendSize": "xlarge", - "metrics": Array [ - "f04a71a3-399f-4d32-9efc-8a005e989991", - ], - "nestedLegend": true, - "numberDisplay": "value", - "primaryGroups": Array [ - "2881fedd-54b7-42ba-8c97-5175dec86166", - "75ce269b-ee9c-4c7d-a14e-9226ba0fe059", - ], - }, - ], - "shape": "treemap", - }, - }, - "title": "Alerts", - "visualizationType": "lnsPie", -} -`; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.test.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.test.ts deleted file mode 100644 index 5c275979f6796..0000000000000 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.test.ts +++ /dev/null @@ -1,63 +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 { renderHook } from '@testing-library/react-hooks'; -import { mockExtraFilter, wrapper } from '../../../mocks'; - -import { useLensAttributes } from '../../../use_lens_attributes'; - -import { getAlertsBySeverityTableAttributes } from './alerts_by_severity_table'; - -jest.mock('uuid', () => ({ - v4: jest.fn().mockReturnValue('b9b43606-7ff7-46ae-a47c-85bed80fab9a'), -})); - -jest.mock('../../../../../containers/sourcerer', () => ({ - useSourcererDataView: jest.fn().mockReturnValue({ - dataViewId: 'security-solution-my-test', - indicesExist: true, - selectedPatterns: ['signal-index'], - }), -})); - -jest.mock('../../../../../utils/route/use_route_spy', () => ({ - useRouteSpy: jest.fn().mockReturnValue([ - { - pageName: 'alerts', - }, - ]), -})); - -describe('getAlertsBySeverityTableAttributes', () => { - it('should render without extra options', () => { - const { result } = renderHook( - () => - useLensAttributes({ - getLensAttributes: getAlertsBySeverityTableAttributes, - stackByField: 'kibana.alert.severity', - }), - { wrapper } - ); - - expect(result?.current).toMatchSnapshot(); - }); - - it('should render with extra options - filters', () => { - const { result } = renderHook( - () => - useLensAttributes({ - extraOptions: { - filters: mockExtraFilter, - }, - getLensAttributes: getAlertsBySeverityTableAttributes, - stackByField: 'kibana.alert.severity', - }), - { wrapper } - ); - - expect(result?.current?.state.filters).toEqual(expect.arrayContaining(mockExtraFilter)); - }); -}); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.ts deleted file mode 100644 index ee71c07a4a26d..0000000000000 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table.ts +++ /dev/null @@ -1,131 +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 { v4 as uuidv4 } from 'uuid'; -import type { GetLensAttributes } from '../../../types'; -const layerId = uuidv4(); - -export const getAlertsBySeverityTableAttributes: GetLensAttributes = ( - stackByField = 'kibana.alert.severity', - extraOptions -) => { - return { - title: 'Alerts', - description: '', - visualizationType: 'lnsDatatable', - state: { - visualization: { - layerId, - layerType: 'data', - columns: [ - { - columnId: 'a9b43606-7ff7-46ae-a47c-85bed80fab9a', - }, - { - columnId: '21cc4a49-3780-4b1a-be28-f02fa5303d24', - }, - ], - headerRowHeight: 'custom', - headerRowHeightLines: 0.6, - rowHeight: 'custom', - rowHeightLines: 0.8, - }, - query: { - query: '', - language: 'kuery', - }, - filters: extraOptions?.filters ? extraOptions.filters : [], - datasourceStates: { - formBased: { - layers: { - [layerId]: { - columns: { - 'a9b43606-7ff7-46ae-a47c-85bed80fab9a': { - label: 'Filters', - dataType: 'string', - operationType: 'filters', - scale: 'ordinal', - isBucketed: true, - params: { - filters: [ - { - input: { - query: `${stackByField}: "critical"`, - language: 'kuery', - }, - label: 'Critical', - }, - { - label: 'High', - input: { - query: `${stackByField} : "high"`, - language: 'kuery', - }, - }, - { - input: { - query: `${stackByField}: "medium"`, - language: 'kuery', - }, - label: 'Medium', - }, - { - input: { - query: `${stackByField} : "low"`, - language: 'kuery', - }, - label: 'Low', - }, - ], - }, - }, - '21cc4a49-3780-4b1a-be28-f02fa5303d24': { - label: 'Count of records', - dataType: 'number', - operationType: 'count', - isBucketed: false, - scale: 'ratio', - sourceField: '___records___', - filter: { - query: '', - language: 'kuery', - }, - params: { - emptyAsNull: true, - }, - }, - }, - columnOrder: [ - 'a9b43606-7ff7-46ae-a47c-85bed80fab9a', - '21cc4a49-3780-4b1a-be28-f02fa5303d24', - ], - sampling: 1, - incompleteColumns: {}, - }, - }, - }, - textBased: { - layers: {}, - }, - }, - internalReferences: [], - adHocDataViews: {}, - }, - references: [ - { - type: 'index-pattern', - id: '{dataViewId}', - name: `indexpattern-datasource-layer-${layerId}`, - }, - { - type: 'index-pattern', - name: '22752b9b-cfcd-43f0-a6ee-27dd4893edcf', - id: '{dataViewId}', - }, - ], - }; -}; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.test.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.test.ts deleted file mode 100644 index e09feb8ddb584..0000000000000 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.test.ts +++ /dev/null @@ -1,100 +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 { renderHook } from '@testing-library/react-hooks'; -import { wrapper } from '../../../mocks'; - -import { useLensAttributes } from '../../../use_lens_attributes'; - -import { getAlertsTreemapLensAttributes } from './alerts_treemap'; - -jest.mock('uuid', () => ({ - v4: jest.fn().mockReturnValue('4aa7cf71-cf20-4e62-8ca6-ca6be6b0988b'), -})); - -jest.mock('../../../../../containers/sourcerer', () => ({ - useSourcererDataView: jest.fn().mockReturnValue({ - dataViewId: 'security-solution-my-test', - indicesExist: true, - selectedPatterns: ['signal-index'], - }), -})); - -jest.mock('../../../../../utils/route/use_route_spy', () => ({ - useRouteSpy: jest.fn().mockReturnValue([ - { - pageName: 'alerts', - }, - ]), -})); - -describe('getAlertsTreemapLensAttributes', () => { - it('should render without extra options', () => { - const { result } = renderHook( - () => - useLensAttributes({ - getLensAttributes: getAlertsTreemapLensAttributes, - stackByField: 'event.category', - }), - { wrapper } - ); - - expect(result?.current).toMatchSnapshot(); - }); - - it('should render with extra options - filters', () => { - const { result } = renderHook( - () => - useLensAttributes({ - extraOptions: { - filters: [ - { - meta: { - type: 'phrases', - key: '_index', - params: ['.alerts-security.alerts-default'], - alias: null, - negate: false, - disabled: false, - }, - query: { - bool: { - should: [ - { - match_phrase: { - _index: '.alerts-security.alerts-default', - }, - }, - ], - minimum_should_match: 1, - }, - }, - }, - ], - }, - getLensAttributes: getAlertsTreemapLensAttributes, - stackByField: 'event.category', - }), - { wrapper } - ); - - expect(result?.current).toMatchSnapshot(); - }); - - it('should render with extra options - breakdownField', () => { - const { result } = renderHook( - () => - useLensAttributes({ - extraOptions: { breakdownField: 'agent.type' }, - getLensAttributes: getAlertsTreemapLensAttributes, - stackByField: 'event.category', - }), - { wrapper } - ); - - expect(result?.current).toMatchSnapshot(); - }); -}); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.ts deleted file mode 100644 index dbf5d0c578f4d..0000000000000 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_treemap.ts +++ /dev/null @@ -1,138 +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 { v4 as uuidv4 } from 'uuid'; -import type { GetLensAttributes } from '../../../types'; - -const layerId = uuidv4(); - -export const getAlertsTreemapLensAttributes: GetLensAttributes = ( - stackByField = 'kibana.alert.rule.name', - extraOptions -) => { - return { - title: 'Alerts', - description: '', - visualizationType: 'lnsPie', - state: { - visualization: { - shape: 'treemap', - layers: [ - { - layerId, - primaryGroups: [ - '2881fedd-54b7-42ba-8c97-5175dec86166', - '75ce269b-ee9c-4c7d-a14e-9226ba0fe059', - ], - metrics: ['f04a71a3-399f-4d32-9efc-8a005e989991'], - numberDisplay: 'value', - categoryDisplay: 'default', - legendDisplay: 'show', - nestedLegend: true, - layerType: 'data', - legendSize: 'xlarge', - legendPosition: 'left', - }, - ], - }, - query: { - query: '', - language: 'kuery', - }, - filters: extraOptions?.filters ? extraOptions.filters : [], - datasourceStates: { - formBased: { - layers: { - [layerId]: { - columns: { - '2881fedd-54b7-42ba-8c97-5175dec86166': { - label: `Top values of ${stackByField}`, - dataType: 'string', - operationType: 'terms', - scale: 'ordinal', - sourceField: stackByField, - isBucketed: true, - params: { - size: 1000, - orderBy: { - type: 'column', - columnId: 'f04a71a3-399f-4d32-9efc-8a005e989991', - }, - orderDirection: 'desc', - otherBucket: true, - missingBucket: false, - parentFormat: { - id: 'terms', - }, - include: [], - exclude: [], - includeIsRegex: false, - excludeIsRegex: false, - }, - }, - '75ce269b-ee9c-4c7d-a14e-9226ba0fe059': { - label: `Top values of ${extraOptions?.breakdownField}`, - dataType: 'string', - operationType: 'terms', - scale: 'ordinal', - sourceField: extraOptions?.breakdownField, - isBucketed: true, - params: { - size: 1000, - orderBy: { - type: 'column', - columnId: 'f04a71a3-399f-4d32-9efc-8a005e989991', - }, - orderDirection: 'desc', - otherBucket: true, - missingBucket: false, - parentFormat: { - id: 'terms', - }, - include: [], - exclude: [], - includeIsRegex: false, - excludeIsRegex: false, - }, - }, - 'f04a71a3-399f-4d32-9efc-8a005e989991': { - label: 'Maximum of kibana.alert.risk_score', - dataType: 'number', - operationType: 'max', - sourceField: 'kibana.alert.risk_score', - isBucketed: false, - scale: 'ratio', - params: { - emptyAsNull: true, - }, - }, - }, - columnOrder: [ - '2881fedd-54b7-42ba-8c97-5175dec86166', - '75ce269b-ee9c-4c7d-a14e-9226ba0fe059', - 'f04a71a3-399f-4d32-9efc-8a005e989991', - ], - sampling: 1, - incompleteColumns: {}, - }, - }, - }, - textBased: { - layers: {}, - }, - }, - internalReferences: [], - adHocDataViews: {}, - }, - references: [ - { - type: 'index-pattern', - id: '{dataViewId}', - name: `indexpattern-datasource-layer-${layerId}`, - }, - ], - }; -}; 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 0b31df3da4de8..e7e51a9ebc4c5 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 @@ -16,7 +16,6 @@ import { HeaderSection } from '../../../../common/components/header_section'; import { useQueryToggle } from '../../../../common/containers/query_toggle'; import { useSeverityChartData } from './severity_donut/use_severity_chart_data'; import { SeverityLevelChart } from './severity_donut/severity_level_chart'; -import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; const DETECTIONS_ALERTS_CHARTS_ID = 'detections-alerts-charts'; @@ -55,7 +54,6 @@ export const AlertsSummaryChartsPanel: React.FC = ({ }: Props) => { // create a unique, but stable (across re-renders) query id const uniqueQueryId = useMemo(() => `${DETECTIONS_ALERTS_CHARTS_ID}-${uuidv4()}`, []); - const isChartEmbeddablesEnabled = useIsExperimentalFeatureEnabled('chartEmbeddablesEnabled'); const { toggleStatus, setToggleStatus } = useQueryToggle(DETECTIONS_ALERTS_CHARTS_ID); const [querySkip, setQuerySkip] = useState(!toggleStatus); @@ -71,16 +69,12 @@ export const AlertsSummaryChartsPanel: React.FC = ({ [setQuerySkip, setToggleStatus] ); - const { - items: severityData, - isLoading: isSeverityLoading, - timerange, - } = useSeverityChartData({ + const { items: severityData, isLoading: isSeverityLoading } = useSeverityChartData({ filters, query, signalIndexName, runtimeMappings, - skip: querySkip || isChartEmbeddablesEnabled, + skip: querySkip, uniqueQueryId, }); @@ -107,9 +101,7 @@ export const AlertsSummaryChartsPanel: React.FC = ({ diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/severity_level_chart.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/severity_level_chart.tsx index 17d31a3058e3a..6868437e303e1 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/severity_level_chart.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/severity_level_chart.tsx @@ -8,7 +8,6 @@ import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiInMemoryTable } from '@elastic/eui'; import React, { useCallback, useMemo } from 'react'; import { isEmpty } from 'lodash/fp'; -import type { Filter } from '@kbn/es-query'; import { ALERT_SEVERITY } from '@kbn/rule-data-utils'; import type { SortOrder } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ShapeTreeNode, ElementClickListener } from '@elastic/charts'; @@ -22,10 +21,6 @@ import { InspectButtonContainer } from '../../../../../common/components/inspect import { getSeverityTableColumns } from '../columns'; import { getSeverityColor } from '../helpers'; import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features'; -import { getAlertsByStatusAttributes } from '../../../../../common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_status_donut'; -import { SourcererScopeName } from '../../../../../common/store/sourcerer/model'; -import { VisualizationEmbeddable } from '../../../../../common/components/visualization_actions/visualization_embeddable'; -import { getAlertsBySeverityTableAttributes } from '../../../../../common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_severity_table'; const DONUT_HEIGHT = 150; @@ -34,18 +29,14 @@ type FieldFilter = ({ field, value }: { field: string; value: string | number }) interface AlertsChartsPanelProps { addFilter?: FieldFilter; data: ParsedSeverityData; - filters?: Filter[]; isLoading: boolean; - timerange: { from: string; to: string }; uniqueQueryId: string; } export const SeverityLevelChart: React.FC = ({ addFilter, data, - filters, isLoading, - timerange, uniqueQueryId, }) => { const isChartEmbeddablesEnabled = useIsExperimentalFeatureEnabled('chartEmbeddablesEnabled'); @@ -88,7 +79,6 @@ export const SeverityLevelChart: React.FC = ({ }, [addFilter] ); - const extraOptions = useMemo(() => ({ filters }), [filters]); return ( @@ -104,54 +94,25 @@ export const SeverityLevelChart: React.FC = ({ /> - {isChartEmbeddablesEnabled ? ( - - ) : ( - - )} + - {isChartEmbeddablesEnabled ? ( - - ) : ( - } - totalCount={count} - onElementClick={onElementClick} - /> - )} + } + totalCount={count} + onElementClick={onElementClick} + /> diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.test.tsx index 753f6715f923b..0d48d023d06a3 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.test.tsx @@ -15,10 +15,7 @@ import { useSeverityChartData } from './use_severity_chart_data'; const dateNow = new Date('2022-04-08T12:00:00.000Z').valueOf(); const mockDateNow = jest.fn().mockReturnValue(dateNow); Date.now = jest.fn(() => mockDateNow()) as unknown as DateConstructor['now']; -const timerange = { - from: '2022-04-05T12:00:00.000Z', - to: '2022-04-08T12:00:00.000Z', -}; + const defaultUseQueryAlertsReturn = { loading: false, data: null, @@ -71,7 +68,6 @@ describe('useSeverityChartData', () => { items: null, isLoading: false, updatedAt: dateNow, - timerange, }); expect(mockUseQueryAlerts).toBeCalledWith({ @@ -93,7 +89,6 @@ describe('useSeverityChartData', () => { items: parsedAlerts, isLoading: false, updatedAt: dateNow, - timerange, }); }); @@ -114,7 +109,6 @@ describe('useSeverityChartData', () => { items: parsedAlerts, isLoading: false, updatedAt: newDateNow, - timerange, }); }); @@ -132,7 +126,6 @@ describe('useSeverityChartData', () => { items: null, isLoading: false, updatedAt: dateNow, - timerange, }); }); }); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.ts b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.ts index f8fef66bea3c0..32665399ce2ec 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.ts +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/severity_donut/use_severity_chart_data.ts @@ -72,7 +72,6 @@ export interface UseSeverityChartProps { export type UseAlertsBySeverity = (props: UseSeverityChartProps) => { items: ParsedSeverityData; isLoading: boolean; - timerange: { from: string; to: string }; updatedAt: number; }; @@ -88,7 +87,6 @@ export const useSeverityChartData: UseAlertsBySeverity = ({ const { to, from, deleteQuery, setQuery } = useGlobalTime(); const [updatedAt, setUpdatedAt] = useState(Date.now()); const [items, setItems] = useState(null); - const timerange = useMemo(() => ({ to, from }), [to, from]); const additionalFilters = useMemo(() => { try { return [ @@ -160,5 +158,5 @@ export const useSeverityChartData: UseAlertsBySeverity = ({ uniqueQueryId, }); - return { items, isLoading, updatedAt, timerange }; + return { items, isLoading, updatedAt }; };