From 0cc92f6eac39e24eef95aa291dcce78f51a5603a Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 1 Mar 2022 03:00:11 +0800 Subject: [PATCH 01/59] add chart configs --- .../public/hosts/configs/authentication.ts | 191 ++++++++++++++++ .../public/hosts/configs/events.ts | 122 ++++++++++ .../public/hosts/configs/external_alert.ts | 150 +++++++++++++ .../public/hosts/configs/kpi_host_area.ts | 89 ++++++++ .../public/hosts/configs/kpi_host_metric.ts | 61 +++++ .../hosts/configs/kpi_unique_ips-area.ts | 137 ++++++++++++ .../hosts/configs/kpi_unique_ips-bar.ts | 135 +++++++++++ .../kpi_unique_ips-destination_metric.ts | 61 +++++ .../configs/kpi_unique_ips-source_metric.ts | 61 +++++ .../kpi_user_authentication_metric_failure.ts | 93 ++++++++ ...kpi_user_authentications-metric_success.ts | 94 ++++++++ .../configs/kpi_user_authentications_area.ts | 205 +++++++++++++++++ .../configs/kpi_user_authentications_bar.ts | 209 ++++++++++++++++++ .../public/network/configs/dns_top_domains.ts | 161 ++++++++++++++ .../public/network/configs/kpi_dns_queries.ts | 60 +++++ .../network/configs/kpi_network_events.ts | 108 +++++++++ .../network/configs/kpi_tls_handshakes.ts | 59 +++++ .../network/configs/kpi_unique_flow_ids.ts | 59 +++++ .../configs/kpi_unique_private_ips-area.ts | 174 +++++++++++++++ .../configs/kpi_unique_private_ips-bar.ts | 196 ++++++++++++++++ ...i_unique_private_ips-destination_metric.ts | 59 +++++ .../kpi_unique_private_ips-source_metric.ts | 59 +++++ 22 files changed, 2543 insertions(+) create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/authentication.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/events.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts create mode 100644 x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts create mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts diff --git a/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts b/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts new file mode 100644 index 00000000000000..aba4ffe9f39412 --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts @@ -0,0 +1,191 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const authentication: LensAttributes = { + title: 'Authentication', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + title: 'Empty XY chart', + legend: { + isVisible: true, + position: 'right', + }, + valueLabels: 'hide', + preferredSeriesType: 'bar_stacked', + layers: [ + { + layerId: '3fd0c5d5-f762-4a27-8c56-14eee0223e13', + accessors: ['5417777d-d9d9-4268-9cdc-eb29b873bd65'], + position: 'top', + seriesType: 'bar_stacked', + showGridlines: false, + layerType: 'data', + xAccessor: 'b41a2958-650b-470a-84c4-c6fd8f0c6d37', + yConfig: [ + { + forAccessor: '5417777d-d9d9-4268-9cdc-eb29b873bd65', + color: '#54b399', + }, + ], + }, + { + layerId: 'bef502be-e5ff-442f-9e3e-229f86ca2afa', + seriesType: 'bar_stacked', + accessors: ['a3bf9dc1-c8d2-42d6-9e60-31892a4c509e'], + layerType: 'data', + xAccessor: 'cded27f7-8ef8-458c-8d9b-70db48ae340d', + yConfig: [ + { + forAccessor: 'a3bf9dc1-c8d2-42d6-9e60-31892a4c509e', + color: '#da8b45', + }, + ], + }, + ], + yRightExtent: { + mode: 'full', + }, + yLeftExtent: { + mode: 'full', + }, + axisTitlesVisibilitySettings: { + x: false, + yLeft: false, + yRight: true, + }, + }, + query: { + query: '', + language: 'kuery', + }, + filters: [ + { + meta: { + index: '6f4dbdc7-35b6-4e20-ac53-1272167e3919', + type: 'custom', + disabled: false, + negate: false, + alias: null, + key: 'query', + value: '{"bool":{"must":[{"term":{"event.category":"authentication"}}]}}', + }, + $state: { + store: 'appState', + }, + query: { + bool: { + must: [ + { + term: { + 'event.category': 'authentication', + }, + }, + ], + }, + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + '3fd0c5d5-f762-4a27-8c56-14eee0223e13': { + columns: { + 'b41a2958-650b-470a-84c4-c6fd8f0c6d37': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', + }, + }, + '5417777d-d9d9-4268-9cdc-eb29b873bd65': { + label: 'Success', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + filter: { + query: 'event.outcome : "success"', + language: 'kuery', + }, + customLabel: true, + }, + }, + columnOrder: [ + 'b41a2958-650b-470a-84c4-c6fd8f0c6d37', + '5417777d-d9d9-4268-9cdc-eb29b873bd65', + ], + incompleteColumns: {}, + }, + 'bef502be-e5ff-442f-9e3e-229f86ca2afa': { + columns: { + 'cded27f7-8ef8-458c-8d9b-70db48ae340d': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', + }, + }, + 'a3bf9dc1-c8d2-42d6-9e60-31892a4c509e': { + label: 'Failure', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + filter: { + query: 'event.outcome : "failure"', + language: 'kuery', + }, + customLabel: true, + }, + }, + columnOrder: [ + 'cded27f7-8ef8-458c-8d9b-70db48ae340d', + 'a3bf9dc1-c8d2-42d6-9e60-31892a4c509e', + ], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-3fd0c5d5-f762-4a27-8c56-14eee0223e13', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-bef502be-e5ff-442f-9e3e-229f86ca2afa', + }, + { + type: 'index-pattern', + name: '6f4dbdc7-35b6-4e20-ac53-1272167e3919', + id: 'security-solution-default', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/events.ts b/x-pack/plugins/security_solution/public/hosts/configs/events.ts new file mode 100644 index 00000000000000..eee1b1086b3b8e --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/events.ts @@ -0,0 +1,122 @@ +/* + * 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 { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; + +export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'event.action') => + ({ + title: 'Host - events', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + title: 'Empty XY chart', + legend: { + isVisible: true, + position: 'right', + }, + valueLabels: 'hide', + preferredSeriesType: 'bar_stacked', + layers: [ + { + layerId: '0039eb0c-9a1a-4687-ae54-0f4e239bec75', + accessors: ['e09e0380-0740-4105-becc-0a4ca12e3944'], + position: 'top', + seriesType: 'bar_stacked', + showGridlines: false, + layerType: 'data', + xAccessor: 'aac9d7d0-13a3-480a-892b-08207a787926', + splitAccessor: '34919782-4546-43a5-b668-06ac934d3acd', + }, + ], + yRightExtent: { + mode: 'full', + }, + yLeftExtent: { + mode: 'full', + }, + axisTitlesVisibilitySettings: { + x: false, + yLeft: false, + yRight: true, + }, + }, + query: { + query: '', + language: 'kuery', + }, + filters: [], + datasourceStates: { + indexpattern: { + layers: { + '0039eb0c-9a1a-4687-ae54-0f4e239bec75': { + columns: { + 'aac9d7d0-13a3-480a-892b-08207a787926': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', + }, + }, + 'e09e0380-0740-4105-becc-0a4ca12e3944': { + label: 'Count of records', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + }, + '34919782-4546-43a5-b668-06ac934d3acd': { + label: `Top values of ${stackByField}`, // could be event.dataset or event.module + dataType: 'string', + operationType: 'terms', + scale: 'ordinal', + sourceField: `${stackByField}`, // could be event.dataset or event.module + isBucketed: true, + params: { + size: 10, + orderBy: { + type: 'column', + columnId: 'e09e0380-0740-4105-becc-0a4ca12e3944', + }, + orderDirection: 'desc', + otherBucket: true, + missingBucket: false, + parentFormat: { + id: 'terms', + }, + }, + }, + }, + columnOrder: [ + '34919782-4546-43a5-b668-06ac934d3acd', + 'aac9d7d0-13a3-480a-892b-08207a787926', + 'e09e0380-0740-4105-becc-0a4ca12e3944', + ], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-0039eb0c-9a1a-4687-ae54-0f4e239bec75', + }, + ], + } as LensAttributes); diff --git a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts new file mode 100644 index 00000000000000..555b8133a8479a --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts @@ -0,0 +1,150 @@ +/* + * 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 { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; + +export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event.module') => { + return { + title: 'external alerts', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + title: 'Empty XY chart', + legend: { + isVisible: true, + position: 'right', + }, + valueLabels: 'hide', + preferredSeriesType: 'bar_stacked', + layers: [ + { + layerId: 'a3c54471-615f-4ff9-9fda-69b5b2ea3eef', + accessors: ['0a923af2-c880-4aa3-aa93-a0b9c2801f6d'], + position: 'top', + seriesType: 'bar_stacked', + showGridlines: false, + layerType: 'data', + xAccessor: '37bdf546-3c11-4b08-8c5d-e37debc44f1d', + splitAccessor: '42334c6e-98d9-47a2-b4cb-a445abb44c93', + }, + ], + yRightExtent: { + mode: 'full', + }, + yLeftExtent: { + mode: 'full', + }, + }, + query: { + query: '', + language: 'kuery', + }, + filters: [ + { + meta: { + index: 'a04472fc-94a3-4b8d-ae05-9d30ea8fbd6a', + alias: null, + negate: false, + disabled: false, + type: 'phrase', + key: 'event.kind', + params: { + query: 'alert', + }, + }, + query: { + match_phrase: { + 'event.kind': 'alert', + }, + }, + $state: { + store: 'appState', + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + 'a3c54471-615f-4ff9-9fda-69b5b2ea3eef': { + columns: { + '37bdf546-3c11-4b08-8c5d-e37debc44f1d': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', + }, + }, + '0a923af2-c880-4aa3-aa93-a0b9c2801f6d': { + label: 'Count of records', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + }, + '42334c6e-98d9-47a2-b4cb-a445abb44c93': { + label: `Top values of ${stackByField}`, // could be event.category + dataType: 'string', + operationType: 'terms', + scale: 'ordinal', + sourceField: `${stackByField}`, // could be event.category + isBucketed: true, + params: { + size: 10, + orderBy: { + type: 'column', + columnId: '0a923af2-c880-4aa3-aa93-a0b9c2801f6d', + }, + orderDirection: 'desc', + otherBucket: true, + missingBucket: false, + parentFormat: { + id: 'terms', + }, + }, + }, + }, + columnOrder: [ + '42334c6e-98d9-47a2-b4cb-a445abb44c93', + '37bdf546-3c11-4b08-8c5d-e37debc44f1d', + '0a923af2-c880-4aa3-aa93-a0b9c2801f6d', + ], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-a3c54471-615f-4ff9-9fda-69b5b2ea3eef', + }, + { + type: 'index-pattern', + name: '723c4653-681b-4105-956e-abef287bf025', + id: 'security-solution-default', + }, + { + type: 'index-pattern', + name: 'a04472fc-94a3-4b8d-ae05-9d30ea8fbd6a', + id: 'security-solution-default', + }, + ], + } as LensAttributes; +}; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts new file mode 100644 index 00000000000000..21aed9ea7b4e99 --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts @@ -0,0 +1,89 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiHostArea: LensAttributes = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + '416b6fad-1923-4f6a-a2df-b223bb287e30': { + columnOrder: [ + '5eea817b-67b7-4268-8ecb-7688d1094721', + 'b00c65ea-32be-4163-bfc8-f795b1ef9d06', + ], + columns: { + '5eea817b-67b7-4268-8ecb-7688d1094721': { + dataType: 'date', + isBucketed: true, + label: '@timestamp', + operationType: 'date_histogram', + params: { interval: 'auto' }, + scale: 'interval', + sourceField: '@timestamp', + }, + 'b00c65ea-32be-4163-bfc8-f795b1ef9d06': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: ' ', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'host.name', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { language: 'kuery', query: '' }, + visualization: { + axisTitlesVisibilitySettings: { x: false, yLeft: false, yRight: false }, + fittingFunction: 'None', + gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true }, + labelsOrientation: { x: 0, yLeft: 0, yRight: 0 }, + layers: [ + { + accessors: ['b00c65ea-32be-4163-bfc8-f795b1ef9d06'], + layerId: '416b6fad-1923-4f6a-a2df-b223bb287e30', + layerType: 'data', + seriesType: 'area', + xAccessor: '5eea817b-67b7-4268-8ecb-7688d1094721', + }, + ], + legend: { isVisible: true, position: 'right' }, + preferredSeriesType: 'area', + tickLabelsVisibilitySettings: { x: true, yLeft: true, yRight: true }, + valueLabels: 'hide', + yLeftExtent: { mode: 'full' }, + yRightExtent: { mode: 'full' }, + }, + }, + title: '[Host] KPI Hosts - area', + visualizationType: 'lnsXY', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-416b6fad-1923-4f6a-a2df-b223bb287e30', + type: 'index-pattern', + }, + { + id: '880973d0-89cb-11ec-acbb-112a5cf3323a', + name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', + type: 'tag', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts new file mode 100644 index 00000000000000..6e42a0fac4ee4b --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts @@ -0,0 +1,61 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiHostMetric: LensAttributes = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + '416b6fad-1923-4f6a-a2df-b223bb287e30': { + columnOrder: ['b00c65ea-32be-4163-bfc8-f795b1ef9d06'], + columns: { + 'b00c65ea-32be-4163-bfc8-f795b1ef9d06': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: ' ', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'host.name', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { language: 'kuery', query: '' }, + visualization: { + accessor: 'b00c65ea-32be-4163-bfc8-f795b1ef9d06', + layerId: '416b6fad-1923-4f6a-a2df-b223bb287e30', + layerType: 'data', + }, + }, + title: '[Host] KPI Hosts - metric', + visualizationType: 'lnsMetric', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-416b6fad-1923-4f6a-a2df-b223bb287e30', + type: 'index-pattern', + }, + { + id: '880973d0-89cb-11ec-acbb-112a5cf3323a', + name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', + type: 'tag', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts new file mode 100644 index 00000000000000..f1bce738e3fb74 --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts @@ -0,0 +1,137 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { + DESTINATION_CHART_LABEL, + SOURCE_CHART_LABEL, +} from '../components/kpi_hosts/unique_ips/translations'; + +export const kpiUniqueIpsArea: LensAttributes = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + '8be0156b-d423-4a39-adf1-f54d4c9f2e69': { + columnOrder: [ + 'a0cb6400-f708-46c3-ad96-24788f12dae4', + 'd9a6eb6b-8b78-439e-98e7-a718f8ffbebe', + ], + columns: { + 'a0cb6400-f708-46c3-ad96-24788f12dae4': { + dataType: 'date', + isBucketed: true, + label: '@timestamp', + operationType: 'date_histogram', + params: { interval: 'auto' }, + scale: 'interval', + sourceField: '@timestamp', + }, + 'd9a6eb6b-8b78-439e-98e7-a718f8ffbebe': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: SOURCE_CHART_LABEL, + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'source.ip', + }, + }, + incompleteColumns: {}, + }, + 'ca05ecdb-0fa4-49a8-9305-b23d91012a46': { + columnOrder: [ + 'f95e74e6-99dd-4b11-8faf-439b4d959df9', + 'e7052671-fb9e-481f-8df3-7724c98cfc6f', + ], + columns: { + 'e7052671-fb9e-481f-8df3-7724c98cfc6f': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: DESTINATION_CHART_LABEL, + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'destination.ip', + }, + 'f95e74e6-99dd-4b11-8faf-439b4d959df9': { + dataType: 'date', + isBucketed: true, + label: '@timestamp', + operationType: 'date_histogram', + params: { interval: 'auto' }, + scale: 'interval', + sourceField: '@timestamp', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { language: 'kuery', query: '' }, + visualization: { + axisTitlesVisibilitySettings: { x: false, yLeft: false, yRight: true }, + fittingFunction: 'None', + gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true }, + labelsOrientation: { x: 0, yLeft: 0, yRight: 0 }, + layers: [ + { + accessors: ['d9a6eb6b-8b78-439e-98e7-a718f8ffbebe'], + layerId: '8be0156b-d423-4a39-adf1-f54d4c9f2e69', + layerType: 'data', + seriesType: 'area', + xAccessor: 'a0cb6400-f708-46c3-ad96-24788f12dae4', + yConfig: [{ color: '#d36186', forAccessor: 'd9a6eb6b-8b78-439e-98e7-a718f8ffbebe' }], + }, + { + accessors: ['e7052671-fb9e-481f-8df3-7724c98cfc6f'], + layerId: 'ca05ecdb-0fa4-49a8-9305-b23d91012a46', + layerType: 'data', + seriesType: 'area', + xAccessor: 'f95e74e6-99dd-4b11-8faf-439b4d959df9', + yConfig: [{ color: '#9170b8', forAccessor: 'e7052671-fb9e-481f-8df3-7724c98cfc6f' }], + }, + ], + legend: { isVisible: false, position: 'right', showSingleSeries: false }, + preferredSeriesType: 'area', + tickLabelsVisibilitySettings: { x: true, yLeft: true, yRight: true }, + valueLabels: 'hide', + yLeftExtent: { mode: 'full' }, + yRightExtent: { mode: 'full' }, + }, + }, + title: '[Host] KPI Unique IPs - area', + visualizationType: 'lnsXY', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-ca05ecdb-0fa4-49a8-9305-b23d91012a46', + type: 'index-pattern', + }, + { + id: '880973d0-89cb-11ec-acbb-112a5cf3323a', + name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', + type: 'tag', + }, + ], + type: 'lens', + updated_at: '2022-02-09T17:44:03.359Z', + version: 'WzI5MTI5OSwzXQ==', +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts new file mode 100644 index 00000000000000..065ce05957c45f --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts @@ -0,0 +1,135 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { + SOURCE_CHART_LABEL, + DESTINATION_CHART_LABEL, +} from '../components/kpi_hosts/unique_ips/translations'; + +export const kpiUniqueIpsBar: LensAttributes = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + '8be0156b-d423-4a39-adf1-f54d4c9f2e69': { + columnOrder: [ + 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e', + '32f66676-f4e1-48fd-b7f8-d4de38318601', + ], + columns: { + '32f66676-f4e1-48fd-b7f8-d4de38318601': { + dataType: 'number', + isBucketed: false, + label: 'Unique count of source.ip', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'source.ip', + }, + 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e': { + dataType: 'string', + isBucketed: true, + label: 'Filters', + operationType: 'filters', + params: { + filters: [{ input: { language: 'kuery', query: '' }, label: SOURCE_CHART_LABEL }], + }, + scale: 'ordinal', + }, + }, + incompleteColumns: {}, + }, + 'ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e': { + columnOrder: [ + 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff', + 'b7e59b08-96e6-40d1-84fd-e97b977d1c47', + ], + columns: { + 'b7e59b08-96e6-40d1-84fd-e97b977d1c47': { + dataType: 'number', + isBucketed: false, + label: 'Unique count of destination.ip', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'destination.ip', + }, + 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff': { + customLabel: true, + dataType: 'string', + isBucketed: true, + label: DESTINATION_CHART_LABEL, + operationType: 'filters', + params: { + filters: [{ input: { language: 'kuery', query: '' }, label: 'Dest.' }], + }, + scale: 'ordinal', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { language: 'kuery', query: '' }, + visualization: { + axisTitlesVisibilitySettings: { x: false, yLeft: false, yRight: true }, + fittingFunction: 'None', + gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true }, + labelsOrientation: { x: 0, yLeft: 0, yRight: 0 }, + layers: [ + { + accessors: ['32f66676-f4e1-48fd-b7f8-d4de38318601'], + layerId: '8be0156b-d423-4a39-adf1-f54d4c9f2e69', + layerType: 'data', + seriesType: 'bar_horizontal_stacked', + xAccessor: 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e', + yConfig: [{ color: '#d36186', forAccessor: '32f66676-f4e1-48fd-b7f8-d4de38318601' }], + }, + { + accessors: ['b7e59b08-96e6-40d1-84fd-e97b977d1c47'], + layerId: 'ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e', + layerType: 'data', + seriesType: 'bar_horizontal_stacked', + xAccessor: 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff', + yConfig: [{ color: '#9170b8', forAccessor: 'b7e59b08-96e6-40d1-84fd-e97b977d1c47' }], + }, + ], + legend: { isVisible: false, position: 'right', showSingleSeries: false }, + preferredSeriesType: 'bar_horizontal_stacked', + tickLabelsVisibilitySettings: { x: true, yLeft: true, yRight: true }, + valueLabels: 'hide', + yLeftExtent: { mode: 'full' }, + yRightExtent: { mode: 'full' }, + }, + }, + title: '[Host] KPI Unique IPs - bar', + visualizationType: 'lnsXY', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e', + type: 'index-pattern', + }, + { + id: '880973d0-89cb-11ec-acbb-112a5cf3323a', + name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', + type: 'tag', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts new file mode 100644 index 00000000000000..4a87e1afed709f --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts @@ -0,0 +1,61 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUniqueIpsDestinationMetric: LensAttributes = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + '8be0156b-d423-4a39-adf1-f54d4c9f2e69': { + columnOrder: ['d9a6eb6b-8b78-439e-98e7-a718f8ffbebe'], + columns: { + 'd9a6eb6b-8b78-439e-98e7-a718f8ffbebe': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: ' ', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'destination.ip', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { language: 'kuery', query: '' }, + visualization: { + accessor: 'd9a6eb6b-8b78-439e-98e7-a718f8ffbebe', + layerId: '8be0156b-d423-4a39-adf1-f54d4c9f2e69', + layerType: 'data', + }, + }, + title: '[Host] KPI Unique IPs - destination metric', + visualizationType: 'lnsMetric', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', + type: 'index-pattern', + }, + { + id: '880973d0-89cb-11ec-acbb-112a5cf3323a', + name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', + type: 'tag', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts new file mode 100644 index 00000000000000..1375587ef1c9a8 --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts @@ -0,0 +1,61 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUniqueIpsSourceMetric: LensAttributes = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + '8be0156b-d423-4a39-adf1-f54d4c9f2e69': { + columnOrder: ['d9a6eb6b-8b78-439e-98e7-a718f8ffbebe'], + columns: { + 'd9a6eb6b-8b78-439e-98e7-a718f8ffbebe': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: ' ', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'source.ip', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { language: 'kuery', query: '' }, + visualization: { + accessor: 'd9a6eb6b-8b78-439e-98e7-a718f8ffbebe', + layerId: '8be0156b-d423-4a39-adf1-f54d4c9f2e69', + layerType: 'data', + }, + }, + title: '[Host] KPI Unique IPs - source metric', + visualizationType: 'lnsMetric', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', + type: 'index-pattern', + }, + { + id: '880973d0-89cb-11ec-acbb-112a5cf3323a', + name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', + type: 'tag', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts new file mode 100644 index 00000000000000..be400c9d7684f1 --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts @@ -0,0 +1,93 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUserAuthenticationsMetricFailure: LensAttributes = { + title: '[Host] KPI User authentications - metric failure ', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + accessor: '0eb97c09-a351-4280-97da-944e4bd30dd7', + layerId: '4590dafb-4ac7-45aa-8641-47a3ff0b817c', + layerType: 'data', + }, + query: { + language: 'kuery', + query: '', + }, + filters: [ + { + $state: { + store: 'appState', + }, + meta: { + alias: null, + disabled: false, + indexRefName: 'filter-index-pattern-0', + key: 'query', + negate: false, + type: 'custom', + value: '{"bool":{"filter":[{"term":{"event.category":"authentication"}}]}}', + }, + query: { + bool: { + filter: [ + { + term: { + 'event.category': 'authentication', + }, + }, + ], + }, + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + '4590dafb-4ac7-45aa-8641-47a3ff0b817c': { + columnOrder: ['0eb97c09-a351-4280-97da-944e4bd30dd7'], + columns: { + '0eb97c09-a351-4280-97da-944e4bd30dd7': { + dataType: 'number', + filter: { + language: 'kuery', + query: 'event.outcome : "failure" ', + }, + isBucketed: false, + label: '', + operationType: 'count', + scale: 'ratio', + sourceField: '___records___', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-4590dafb-4ac7-45aa-8641-47a3ff0b817c', + }, + { + type: 'tag', + id: 'security-solution-default', + name: 'tag-ref-security-solution-default', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts new file mode 100644 index 00000000000000..29263bc1148ef4 --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts @@ -0,0 +1,94 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUserAuthenticationsMetricSuccess: LensAttributes = { + title: '[Host] KPI User authentications - metric success ', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + accessor: '0eb97c09-a351-4280-97da-944e4bd30dd7', + layerId: '4590dafb-4ac7-45aa-8641-47a3ff0b817c', + layerType: 'data', + }, + query: { + language: 'kuery', + query: '', + }, + filters: [ + { + $state: { + store: 'appState', + }, + meta: { + alias: null, + disabled: false, + indexRefName: 'filter-index-pattern-0', + key: 'query', + negate: false, + type: 'custom', + value: '{"bool":{"filter":[{"term":{"event.category":"authentication"}}]}}', + }, + query: { + bool: { + filter: [ + { + term: { + 'event.category': 'authentication', + }, + }, + ], + }, + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + '4590dafb-4ac7-45aa-8641-47a3ff0b817c': { + columnOrder: ['0eb97c09-a351-4280-97da-944e4bd30dd7'], + columns: { + '0eb97c09-a351-4280-97da-944e4bd30dd7': { + customLabel: true, + dataType: 'number', + filter: { + language: 'kuery', + query: 'event.outcome : "success" ', + }, + isBucketed: false, + label: ' ', + operationType: 'count', + scale: 'ratio', + sourceField: '___records___', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-4590dafb-4ac7-45aa-8641-47a3ff0b817c', + }, + { + type: 'tag', + id: 'security-solution-default', + name: 'tag-ref-security-solution-default', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts new file mode 100644 index 00000000000000..529a0c40a80e4b --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts @@ -0,0 +1,205 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUserAuthenticationsArea: LensAttributes = { + title: '[Host] KPI User authentications - area ', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + axisTitlesVisibilitySettings: { + x: true, + yLeft: false, + yRight: true, + }, + fittingFunction: 'None', + gridlinesVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + labelsOrientation: { + x: 0, + yLeft: 0, + yRight: 0, + }, + layers: [ + { + accessors: ['0eb97c09-a351-4280-97da-944e4bd30dd7'], + layerId: '4590dafb-4ac7-45aa-8641-47a3ff0b817c', + layerType: 'data', + seriesType: 'area', + xAccessor: '49a42fe6-ebe8-4adb-8eed-1966a5297b7e', + yConfig: [ + { + color: '#54b399', + forAccessor: '0eb97c09-a351-4280-97da-944e4bd30dd7', + }, + ], + }, + { + accessors: ['2b27c80e-a20d-46f1-8fb2-79626ef4563c'], + layerId: '31213ae3-905b-4e88-b987-0cccb1f3209f', + layerType: 'data', + seriesType: 'area', + xAccessor: '33a6163d-0c0a-451d-aa38-8ca6010dd5bf', + yConfig: [ + { + color: '#e7664c', + forAccessor: '2b27c80e-a20d-46f1-8fb2-79626ef4563c', + }, + ], + }, + ], + legend: { + isVisible: false, + position: 'right', + showSingleSeries: false, + }, + preferredSeriesType: 'area', + tickLabelsVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + valueLabels: 'hide', + yLeftExtent: { + mode: 'full', + }, + yRightExtent: { + mode: 'full', + }, + }, + query: { + language: 'kuery', + query: '', + }, + filters: [ + { + $state: { + store: 'appState', + }, + meta: { + alias: null, + disabled: false, + indexRefName: 'filter-index-pattern-0', + key: 'query', + negate: false, + type: 'custom', + value: '{"bool":{"filter":[{"term":{"event.category":"authentication"}}]}}', + }, + query: { + bool: { + filter: [ + { + term: { + 'event.category': 'authentication', + }, + }, + ], + }, + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + '31213ae3-905b-4e88-b987-0cccb1f3209f': { + columnOrder: [ + '33a6163d-0c0a-451d-aa38-8ca6010dd5bf', + '2b27c80e-a20d-46f1-8fb2-79626ef4563c', + ], + columns: { + '2b27c80e-a20d-46f1-8fb2-79626ef4563c': { + customLabel: true, + dataType: 'number', + filter: { + language: 'kuery', + query: 'event.outcome: "failure" ', + }, + isBucketed: false, + label: 'Fail', + operationType: 'count', + scale: 'ratio', + sourceField: '___records___', + }, + '33a6163d-0c0a-451d-aa38-8ca6010dd5bf': { + dataType: 'date', + isBucketed: true, + label: '@timestamp', + operationType: 'date_histogram', + params: { + interval: 'auto', + }, + scale: 'interval', + sourceField: '@timestamp', + }, + }, + incompleteColumns: {}, + }, + '4590dafb-4ac7-45aa-8641-47a3ff0b817c': { + columnOrder: [ + '49a42fe6-ebe8-4adb-8eed-1966a5297b7e', + '0eb97c09-a351-4280-97da-944e4bd30dd7', + ], + columns: { + '0eb97c09-a351-4280-97da-944e4bd30dd7': { + customLabel: true, + dataType: 'number', + filter: { + language: 'kuery', + query: 'event.outcome : "success" ', + }, + isBucketed: false, + label: 'Succ.', + operationType: 'count', + scale: 'ratio', + sourceField: '___records___', + }, + '49a42fe6-ebe8-4adb-8eed-1966a5297b7e': { + dataType: 'date', + isBucketed: true, + label: '@timestamp', + operationType: 'date_histogram', + params: { + interval: 'auto', + }, + scale: 'interval', + sourceField: '@timestamp', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-31213ae3-905b-4e88-b987-0cccb1f3209f', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-4590dafb-4ac7-45aa-8641-47a3ff0b817c', + }, + { + type: 'tag', + id: 'security-solution-default', + name: 'tag-ref-security-solution-default', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts new file mode 100644 index 00000000000000..a59e9ca7558357 --- /dev/null +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts @@ -0,0 +1,209 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { + FAIL_CHART_LABEL, + SUCCESS_CHART_LABEL, +} from '../components/kpi_hosts/authentications/translations'; + +export const kpiUserAuthenticationsBar: LensAttributes = { + title: '[Host] KPI User authentications - bar ', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + axisTitlesVisibilitySettings: { + x: false, + yLeft: false, + yRight: true, + }, + fittingFunction: 'None', + gridlinesVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + labelsOrientation: { + x: 0, + yLeft: 0, + yRight: 0, + }, + layers: [ + { + accessors: ['938b445a-a291-4bbc-84fe-4f47b69c20e4'], + layerId: '31213ae3-905b-4e88-b987-0cccb1f3209f', + layerType: 'data', + seriesType: 'bar_horizontal_stacked', + xAccessor: '430e690c-9992-414f-9bce-00812d99a5e7', + yConfig: [], + }, + { + accessors: ['c8165fc3-7180-4f1b-8c87-bc3ea04c6df7'], + layerId: 'b9acd453-f476-4467-ad38-203e37b73e55', + layerType: 'data', + seriesType: 'bar_horizontal_stacked', + xAccessor: 'e959c351-a3a2-4525-b244-9623f215a8fd', + yConfig: [ + { + color: '#e7664c', + forAccessor: 'c8165fc3-7180-4f1b-8c87-bc3ea04c6df7', + }, + ], + }, + ], + legend: { + isVisible: false, + position: 'right', + showSingleSeries: false, + }, + preferredSeriesType: 'bar_horizontal_stacked', + tickLabelsVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + valueLabels: 'hide', + yLeftExtent: { + mode: 'full', + }, + yRightExtent: { + mode: 'full', + }, + }, + query: { + language: 'kuery', + query: '', + }, + filters: [ + { + $state: { + store: 'appState', + }, + meta: { + alias: null, + disabled: false, + indexRefName: 'filter-index-pattern-0', + key: 'query', + negate: false, + type: 'custom', + value: '{"bool":{"filter":[{"term":{"event.category":"authentication"}}]}}', + }, + query: { + bool: { + filter: [ + { + term: { + 'event.category': 'authentication', + }, + }, + ], + }, + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + '31213ae3-905b-4e88-b987-0cccb1f3209f': { + columnOrder: [ + '430e690c-9992-414f-9bce-00812d99a5e7', + '938b445a-a291-4bbc-84fe-4f47b69c20e4', + ], + columns: { + '430e690c-9992-414f-9bce-00812d99a5e7': { + dataType: 'string', + isBucketed: true, + label: 'Filters', + operationType: 'filters', + params: { + filters: [ + { + input: { + language: 'kuery', + query: 'event.outcome : "success" ', + }, + label: SUCCESS_CHART_LABEL, + }, + ], + }, + scale: 'ordinal', + }, + '938b445a-a291-4bbc-84fe-4f47b69c20e4': { + dataType: 'number', + isBucketed: false, + label: SUCCESS_CHART_LABEL, + operationType: 'count', + scale: 'ratio', + sourceField: '___records___', + }, + }, + incompleteColumns: {}, + }, + 'b9acd453-f476-4467-ad38-203e37b73e55': { + columnOrder: [ + 'e959c351-a3a2-4525-b244-9623f215a8fd', + 'c8165fc3-7180-4f1b-8c87-bc3ea04c6df7', + ], + columns: { + 'c8165fc3-7180-4f1b-8c87-bc3ea04c6df7': { + dataType: 'number', + isBucketed: false, + label: 'Fail', + operationType: 'count', + scale: 'ratio', + sourceField: '___records___', + }, + 'e959c351-a3a2-4525-b244-9623f215a8fd': { + customLabel: true, + dataType: 'string', + isBucketed: true, + label: FAIL_CHART_LABEL, + operationType: 'filters', + params: { + filters: [ + { + input: { + language: 'kuery', + query: 'event.outcome:"failure" ', + }, + label: FAIL_CHART_LABEL, + }, + ], + }, + scale: 'ordinal', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-31213ae3-905b-4e88-b987-0cccb1f3209f', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-b9acd453-f476-4467-ad38-203e37b73e55', + }, + { + type: 'tag', + id: 'security-solution-default', + name: 'tag-ref-security-solution-default', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts b/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts new file mode 100644 index 00000000000000..96b5c9246a7279 --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts @@ -0,0 +1,161 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +/* Exported from Kibana Saved Object */ +export const dnsTopDomainsAttrs: LensAttributes = { + title: 'Top domains by dns.question.registered_domain', + description: 'Security Solution Network DNS', + visualizationType: 'lnsXY', + state: { + visualization: { + legend: { + isVisible: true, + position: 'right', + }, + valueLabels: 'hide', + fittingFunction: 'None', + yLeftExtent: { + mode: 'full', + }, + yRightExtent: { + mode: 'full', + }, + axisTitlesVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + tickLabelsVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + labelsOrientation: { + x: 0, + yLeft: 0, + yRight: 0, + }, + gridlinesVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + preferredSeriesType: 'bar', + layers: [ + { + layerId: 'b1c3efc6-c886-4fba-978f-3b6bb5e7948a', + accessors: ['2a4d5e20-f570-48e4-b9ab-ff3068919377'], + position: 'top', + seriesType: 'bar', + showGridlines: false, + layerType: 'data', + xAccessor: 'd1452b87-0e9e-4fc0-a725-3727a18e0b37', + splitAccessor: 'e8842815-2a45-4c74-86de-c19a391e2424', + }, + ], + }, + query: { + query: '', + language: 'kuery', + }, + filters: [ + { + meta: { + alias: null, + negate: true, + disabled: false, + type: 'phrase', + key: 'dns.question.type', + params: { + query: 'PTR', + }, + indexRefName: 'filter-index-pattern-0', + }, + query: { + match_phrase: { + 'dns.question.type': 'PTR', + }, + }, + $state: { + store: 'appState', + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + 'b1c3efc6-c886-4fba-978f-3b6bb5e7948a': { + columns: { + 'd1452b87-0e9e-4fc0-a725-3727a18e0b37': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', + }, + }, + '2a4d5e20-f570-48e4-b9ab-ff3068919377': { + label: 'Unique count of dns.question.registered_domain', + dataType: 'number', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'dns.question.registered_domain', + isBucketed: false, + }, + 'e8842815-2a45-4c74-86de-c19a391e2424': { + label: 'Top values of dns.question.name', + dataType: 'string', + operationType: 'terms', + scale: 'ordinal', + sourceField: 'dns.question.name', + isBucketed: true, + params: { + size: 6, + orderBy: { + type: 'column', + columnId: '2a4d5e20-f570-48e4-b9ab-ff3068919377', + }, + orderDirection: 'desc', + otherBucket: true, + missingBucket: false, + }, + }, + }, + columnOrder: [ + 'e8842815-2a45-4c74-86de-c19a391e2424', + 'd1452b87-0e9e-4fc0-a725-3727a18e0b37', + '2a4d5e20-f570-48e4-b9ab-ff3068919377', + ], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'filebeat-*', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'logs-*', + name: 'indexpattern-datasource-layer-b1c3efc6-c886-4fba-978f-3b6bb5e7948a', + }, + { + name: 'filter-index-pattern-0', + type: 'index-pattern', + id: 'logs-*', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts new file mode 100644 index 00000000000000..ef1b92ed2bbd8b --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts @@ -0,0 +1,60 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiDnsQueries: LensAttributes = { + title: '[Network] KPI Unique private IPs - source metric', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + layerId: 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + accessor: 'bd17c23e-4f83-4108-8005-2669170d064b', + layerType: 'data', + }, + query: { + query: + 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', + language: 'kuery', + }, + filters: [], + datasourceStates: { + indexpattern: { + layers: { + 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3': { + columns: { + 'bd17c23e-4f83-4108-8005-2669170d064b': { + label: ' ', + dataType: 'number', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'source.ip', + isBucketed: false, + customLabel: true, + }, + }, + columnOrder: ['bd17c23e-4f83-4108-8005-2669170d064b'], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts new file mode 100644 index 00000000000000..5a9f3b4937527d --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts @@ -0,0 +1,108 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiNetworkEvents: LensAttributes = { + title: '[Network] KPI Network events', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + layerId: 'eaadfec7-deaa-4aeb-a403-3b4e516416d2', + accessor: '370ebd07-5ce0-4f46-a847-0e363c50d037', + layerType: 'data', + }, + query: { + query: '', + language: 'kuery', + }, + filters: [ + { + meta: { + index: 'security-solution-default', + alias: null, + negate: false, + disabled: false, + type: 'exists', + key: 'source.ip', + value: 'exists', + }, + query: { + exists: { + field: 'source.ip', + }, + }, + $state: { + store: 'appState', + }, + }, + { + meta: { + index: 'security-solution-default', + alias: null, + negate: false, + disabled: false, + type: 'exists', + key: 'destination.ip', + value: 'exists', + }, + query: { + exists: { + field: 'destination.ip', + }, + }, + $state: { + store: 'appState', + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + 'eaadfec7-deaa-4aeb-a403-3b4e516416d2': { + columns: { + '370ebd07-5ce0-4f46-a847-0e363c50d037': { + label: ' ', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + customLabel: true, + }, + }, + columnOrder: ['370ebd07-5ce0-4f46-a847-0e363c50d037'], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-eaadfec7-deaa-4aeb-a403-3b4e516416d2', + }, + { + type: 'index-pattern', + name: '861af17d-be25-45a3-a82d-d6e697b76e51', + id: 'security-solution-default', + }, + { + type: 'index-pattern', + name: '09617767-f732-410e-af53-bebcbd0bf4b9', + id: 'security-solution-default', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts new file mode 100644 index 00000000000000..5e5d476fe51ccf --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts @@ -0,0 +1,59 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiTlsHandshakes: LensAttributes = { + title: '[Network] KPI TLS handshakes', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + layerId: '1f48a633-8eee-45ae-9471-861227e9ca03', + accessor: '21052b6b-5504-4084-a2e2-c17f772345cf', + layerType: 'data', + }, + query: { + query: + '(source.ip: * or destination.ip: *) and (tls.version: * or suricata.eve.tls.version: * or zeek.ssl.version: * )', + language: 'kuery', + }, + filters: [], + datasourceStates: { + indexpattern: { + layers: { + '1f48a633-8eee-45ae-9471-861227e9ca03': { + columns: { + '21052b6b-5504-4084-a2e2-c17f772345cf': { + label: ' ', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + customLabel: true, + }, + }, + columnOrder: ['21052b6b-5504-4084-a2e2-c17f772345cf'], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-1f48a633-8eee-45ae-9471-861227e9ca03', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts new file mode 100644 index 00000000000000..7df97d6420e119 --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts @@ -0,0 +1,59 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUniqueFlowIds: LensAttributes = { + title: '[Network] KPI Unique flow IDs', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + layerId: '5d46d48f-6ce8-46be-a797-17ad50642564', + accessor: 'a27f3503-9c73-4fc1-86bb-12461dae4b70', + layerType: 'data', + }, + query: { + query: 'source.ip: * or destination.ip: * ', + language: 'kuery', + }, + filters: [], + datasourceStates: { + indexpattern: { + layers: { + '5d46d48f-6ce8-46be-a797-17ad50642564': { + columns: { + 'a27f3503-9c73-4fc1-86bb-12461dae4b70': { + label: ' ', + dataType: 'number', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'network.community_id', + isBucketed: false, + customLabel: true, + }, + }, + columnOrder: ['a27f3503-9c73-4fc1-86bb-12461dae4b70'], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-5d46d48f-6ce8-46be-a797-17ad50642564', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts new file mode 100644 index 00000000000000..f07b0233e45175 --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts @@ -0,0 +1,174 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUniquePrivateIpsArea: LensAttributes = { + title: '[Network] KPI Unique private IPs - area chart', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + legend: { + isVisible: false, + position: 'right', + showSingleSeries: false, + }, + valueLabels: 'hide', + fittingFunction: 'None', + yLeftExtent: { + mode: 'full', + }, + yRightExtent: { + mode: 'full', + }, + axisTitlesVisibilitySettings: { + x: false, + yLeft: false, + yRight: true, + }, + tickLabelsVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + labelsOrientation: { + x: 0, + yLeft: 0, + yRight: 0, + }, + gridlinesVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + preferredSeriesType: 'area', + layers: [ + { + layerId: '38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7', + seriesType: 'area', + accessors: ['5f317308-cfbb-4ee5-bfb9-07653184fabf'], + layerType: 'data', + xAccessor: '662cd5e5-82bf-4325-a703-273f84b97e09', + yConfig: [ + { + forAccessor: '5f317308-cfbb-4ee5-bfb9-07653184fabf', + color: '#d36186', + }, + ], + }, + { + layerId: '72dc4b99-b07d-4dc9-958b-081d259e11fa', + seriesType: 'area', + accessors: ['ac1eb80c-ddde-46c4-a90c-400261926762'], + layerType: 'data', + xAccessor: '36444b8c-7e10-4069-8298-6c1b46912be2', + yConfig: [ + { + forAccessor: 'ac1eb80c-ddde-46c4-a90c-400261926762', + color: '#9170b8', + }, + ], + }, + ], + }, + query: { + query: '', + language: 'kuery', + }, + filters: [], + datasourceStates: { + indexpattern: { + layers: { + '38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7': { + columns: { + '662cd5e5-82bf-4325-a703-273f84b97e09': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', + }, + }, + '5f317308-cfbb-4ee5-bfb9-07653184fabf': { + label: 'Src.', + dataType: 'number', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'source.ip', + isBucketed: false, + customLabel: true, + filter: { + query: + '"source.ip": "10.0.0.0/8" or "source.ip": "192.168.0.0/16" or "source.ip": "172.16.0.0/12" or "source.ip": "fd00::/8"', + language: 'kuery', + }, + }, + }, + columnOrder: [ + '662cd5e5-82bf-4325-a703-273f84b97e09', + '5f317308-cfbb-4ee5-bfb9-07653184fabf', + ], + incompleteColumns: {}, + }, + '72dc4b99-b07d-4dc9-958b-081d259e11fa': { + columns: { + '36444b8c-7e10-4069-8298-6c1b46912be2': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', + }, + }, + 'ac1eb80c-ddde-46c4-a90c-400261926762': { + label: 'Dest.', + dataType: 'number', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'destination.ip', + isBucketed: false, + filter: { + query: + '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', + language: 'kuery', + }, + }, + }, + columnOrder: [ + '36444b8c-7e10-4069-8298-6c1b46912be2', + 'ac1eb80c-ddde-46c4-a90c-400261926762', + ], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-72dc4b99-b07d-4dc9-958b-081d259e11fa', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts new file mode 100644 index 00000000000000..f36dcaee6e78b6 --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts @@ -0,0 +1,196 @@ +/* + * 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 { + SOURCE_CHART_LABEL, + DESTINATION_CHART_LABEL, +} from '../components/kpi_network/unique_private_ips/translations'; +import { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUniquePrivateIpsBar = { + title: '[Network] KPI Unique private IPs - bar chart', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + legend: { + isVisible: false, + position: 'right', + showSingleSeries: false, + }, + valueLabels: 'hide', + fittingFunction: 'None', + yLeftExtent: { + mode: 'full', + }, + yRightExtent: { + mode: 'full', + }, + axisTitlesVisibilitySettings: { + x: false, + yLeft: false, + yRight: true, + }, + tickLabelsVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + labelsOrientation: { + x: 0, + yLeft: 0, + yRight: 0, + }, + gridlinesVisibilitySettings: { + x: true, + yLeft: true, + yRight: true, + }, + preferredSeriesType: 'bar_horizontal_stacked', + layers: [ + { + layerId: 'e406bf4f-942b-41ac-b516-edb5cef06ec8', + accessors: ['5acd4c9d-dc3b-4b21-9632-e4407944c36d'], + position: 'top', + seriesType: 'bar_horizontal_stacked', + showGridlines: false, + layerType: 'data', + yConfig: [ + { + forAccessor: '5acd4c9d-dc3b-4b21-9632-e4407944c36d', + color: '#d36186', + }, + ], + xAccessor: 'd9c438c5-f776-4436-9d20-d62dc8c03be8', + }, + { + layerId: '38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7', + seriesType: 'bar_horizontal_stacked', + accessors: ['d27e0966-daf9-41f4-9033-230cf1e76dc9'], + layerType: 'data', + yConfig: [ + { + forAccessor: 'd27e0966-daf9-41f4-9033-230cf1e76dc9', + color: '#9170b8', + }, + ], + xAccessor: '4607c585-3af3-43b9-804f-e49b27796d79', + }, + ], + }, + query: { + query: '', + language: 'kuery', + }, + filters: [], + datasourceStates: { + indexpattern: { + layers: { + 'e406bf4f-942b-41ac-b516-edb5cef06ec8': { + columns: { + '5acd4c9d-dc3b-4b21-9632-e4407944c36d': { + label: SOURCE_CHART_LABEL, + dataType: 'number', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'source.ip', + isBucketed: false, + customLabel: true, + filter: { + query: + '"source.ip": "10.0.0.0/8" or "source.ip": "192.168.0.0/16" or "source.ip": "172.16.0.0/12" or "source.ip": "fd00::/8"', + language: 'kuery', + }, + }, + 'd9c438c5-f776-4436-9d20-d62dc8c03be8': { + label: 'Filters', + dataType: 'string', + operationType: 'filters', + scale: 'ordinal', + isBucketed: true, + params: { + filters: [ + { + input: { + query: '', + language: 'kuery', + }, + label: SOURCE_CHART_LABEL, + }, + ], + }, + }, + }, + columnOrder: [ + 'd9c438c5-f776-4436-9d20-d62dc8c03be8', + '5acd4c9d-dc3b-4b21-9632-e4407944c36d', + ], + incompleteColumns: {}, + }, + '38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7': { + columns: { + 'd27e0966-daf9-41f4-9033-230cf1e76dc9': { + label: DESTINATION_CHART_LABEL, + dataType: 'number', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'destination.ip', + isBucketed: false, + customLabel: true, + filter: { + query: + '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', + language: 'kuery', + }, + }, + '4607c585-3af3-43b9-804f-e49b27796d79': { + label: 'Filters', + dataType: 'string', + operationType: 'filters', + scale: 'ordinal', + isBucketed: true, + params: { + filters: [ + { + input: { + query: '', + language: 'kuery', + }, + label: DESTINATION_CHART_LABEL, + }, + ], + }, + }, + }, + columnOrder: [ + '4607c585-3af3-43b9-804f-e49b27796d79', + 'd27e0966-daf9-41f4-9033-230cf1e76dc9', + ], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-e406bf4f-942b-41ac-b516-edb5cef06ec8', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts new file mode 100644 index 00000000000000..258b4a5c315fd2 --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts @@ -0,0 +1,59 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUniquePrivateIpsDestinationMetric = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3': { + columnOrder: ['bd17c23e-4f83-4108-8005-2669170d064b'], + columns: { + 'bd17c23e-4f83-4108-8005-2669170d064b': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: ' ', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'destination.ip', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { + language: 'kuery', + query: + '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', + }, + visualization: { + accessor: 'bd17c23e-4f83-4108-8005-2669170d064b', + layerId: 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + layerType: 'data', + }, + }, + title: '[Network] KPI Unique private IPs - destination metric', + visualizationType: 'lnsMetric', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + type: 'index-pattern', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts new file mode 100644 index 00000000000000..4bc70224430c8c --- /dev/null +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts @@ -0,0 +1,59 @@ +/* + * 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 { LensAttributes } from '../../common/components/matrix_histogram/types'; + +export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { + description: '', + state: { + datasourceStates: { + indexpattern: { + layers: { + 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3': { + columnOrder: ['bd17c23e-4f83-4108-8005-2669170d064b'], + columns: { + 'bd17c23e-4f83-4108-8005-2669170d064b': { + customLabel: true, + dataType: 'number', + isBucketed: false, + label: ' ', + operationType: 'unique_count', + scale: 'ratio', + sourceField: 'source.ip', + }, + }, + incompleteColumns: {}, + }, + }, + }, + }, + filters: [], + query: { + language: 'kuery', + query: + 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', + }, + visualization: { + accessor: 'bd17c23e-4f83-4108-8005-2669170d064b', + layerId: 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + layerType: 'data', + }, + }, + title: '[Network] KPI Unique private IPs - source metric', + visualizationType: 'lnsMetric', + references: [ + { + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + type: 'index-pattern', + }, + ], +} as LensAttributes; From 9c0d99698062d3ffd9152988e99580bae64bde16 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Sun, 27 Feb 2022 03:14:30 +0800 Subject: [PATCH 02/59] init hosts chart actions --- x-pack/plugins/security_solution/kibana.json | 1 + .../alerts_viewer/histogram_configs.ts | 2 + .../common/components/alerts_viewer/index.tsx | 1 + .../common/components/charts/areachart.tsx | 49 ++++- .../common/components/charts/barchart.tsx | 63 ++++-- .../common/components/charts/common.tsx | 4 + .../components/header_section/index.tsx | 57 +++-- .../common/components/inspect/index.tsx | 112 +++------- .../common/components/inspect/use_inspect.tsx | 106 +++++++++ .../matrix_histogram/histogram_actions.tsx | 207 ++++++++++++++++++ .../components/matrix_histogram/index.tsx | 35 ++- .../components/matrix_histogram/types.ts | 3 + .../matrix_histogram/use_lens_attributes.tsx | 94 ++++++++ .../components/matrix_histogram/utils.ts | 107 +++++++++ .../common/components/stat_items/index.tsx | 137 ++++++++---- .../kpi_hosts/authentications/index.tsx | 9 + .../components/kpi_hosts/common/index.tsx | 5 +- .../components/kpi_hosts/hosts/index.tsx | 5 + .../components/kpi_hosts/unique_ips/index.tsx | 9 + .../public/hosts/configs/events.ts | 207 +++++++++--------- .../public/hosts/configs/external_alert.ts | 10 +- .../authentications_query_tab_body.tsx | 4 + .../navigation/events_query_tab_body.tsx | 3 + 23 files changed, 940 insertions(+), 290 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx create mode 100644 x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx create mode 100644 x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx diff --git a/x-pack/plugins/security_solution/kibana.json b/x-pack/plugins/security_solution/kibana.json index 9f22f229b33c19..0143f28197bb32 100644 --- a/x-pack/plugins/security_solution/kibana.json +++ b/x-pack/plugins/security_solution/kibana.json @@ -18,6 +18,7 @@ "eventLog", "features", "inspector", + "lens", "licensing", "maps", "ruleRegistry", diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts index e710dd2c247dbc..bc31cdc55f1610 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts +++ b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts @@ -8,6 +8,7 @@ import * as i18n from './translations'; import { MatrixHistogramOption, MatrixHistogramConfigs } from '../matrix_histogram/types'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution/matrix_histogram'; +import { getExternalAlertConfigs } from '../../../hosts/configs/external_alert'; export const alertsStackByOptions: MatrixHistogramOption[] = [ { @@ -30,4 +31,5 @@ export const histogramConfigs: MatrixHistogramConfigs = { stackByOptions: alertsStackByOptions, subtitle: undefined, title: i18n.ALERTS_GRAPH_TITLE, + getLensAttributes: getExternalAlertConfigs, }; diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx index b0471a72c6ee6b..be83e7df1c0bad 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx @@ -69,6 +69,7 @@ const AlertsViewComponent: React.FC = ({ indexNames={indexNames} setQuery={setQuery} startDate={startDate} + showInspectButton={false} {...alertsHistogramConfigs} /> )} diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index 9a00736c4a605f..9d51906eaafe82 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React from 'react'; +import React, { useMemo } from 'react'; import { Axis, AreaSeries, @@ -16,8 +16,10 @@ import { AreaSeriesStyle, RecursivePartial, } from '@elastic/charts'; + import { getOr, get, isNull, isNumber } from 'lodash/fp'; +import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { useThrottledResizeObserver } from '../utils'; import { ChartPlaceHolder } from './chart_place_holder'; import { useTimeZone } from '../../lib/kibana'; @@ -29,7 +31,14 @@ import { getChartWidth, WrappedByAutoSizer, useTheme, + Wrapper, } from './common'; +import { + HistogramActions, + HistogramActionsProps, + HISTOGRAM_ACTIONS_BUTTON_CLASS, +} from '../matrix_histogram/histogram_actions'; +import { HoverVisibilityContainer } from '../hover_visibility_container'; // custom series styles: https://ela.st/areachart-styling const getSeriesLineStyle = (): RecursivePartial => { @@ -138,21 +147,45 @@ AreaChartBase.displayName = 'AreaChartBase'; interface AreaChartComponentProps { areaChart: ChartSeriesData[] | null | undefined; configs?: ChartSeriesConfigs | undefined; + histogramActionsOptions?: HistogramActionsProps; } -export const AreaChartComponent: React.FC = ({ areaChart, configs }) => { +export const AreaChartComponent: React.FC = ({ + areaChart, + configs, + histogramActionsOptions, +}) => { const { ref: measureRef, width, height } = useThrottledResizeObserver(); const customHeight = get('customHeight', configs); const customWidth = get('customWidth', configs); const chartHeight = getChartHeight(customHeight, height); const chartWidth = getChartWidth(customWidth, width); - return checkIfAnyValidSeriesExist(areaChart) ? ( - - - - ) : ( - + const isVlidSeriesExist = useMemo(() => checkIfAnyValidSeriesExist(areaChart), [areaChart]); + + return ( + + + {isVlidSeriesExist && ( + + + + + + + + )} + {!isVlidSeriesExist && ( + + )} + + + ); }; diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index a2bc3a2c0456aa..3c0c6ee8f8211b 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -31,10 +31,17 @@ import { getChartWidth, WrappedByAutoSizer, useTheme, + Wrapper, } from './common'; import { DraggableLegend } from './draggable_legend'; import { LegendItem } from './draggable_legend_item'; import type { ChartData } from './common'; +import { + HistogramActions, + HistogramActionsProps, + HISTOGRAM_ACTIONS_BUTTON_CLASS, +} from '../matrix_histogram/histogram_actions'; +import { HoverVisibilityContainer } from '../hover_visibility_container'; const LegendFlexItem = styled(EuiFlexItem)` overview: hidden; @@ -144,6 +151,7 @@ interface BarChartComponentProps { configs?: ChartSeriesConfigs | undefined; stackByField?: string; timelineId?: string; + histogramActionsOptions?: HistogramActionsProps; } const NO_LEGEND_DATA: LegendItem[] = []; @@ -153,6 +161,7 @@ export const BarChartComponent: React.FC = ({ configs, stackByField, timelineId, + histogramActionsOptions, }) => { const { ref: measureRef, width, height } = useThrottledResizeObserver(); const legendItems: LegendItem[] = useMemo( @@ -176,27 +185,39 @@ export const BarChartComponent: React.FC = ({ const customWidth = get('customWidth', configs); const chartHeight = getChartHeight(customHeight, height); const chartWidth = getChartWidth(customWidth, width); - - return checkIfAnyValidSeriesExist(barChart) ? ( - - - - - - - - - - - ) : ( - + const isVlidSeriesExist = useMemo(() => checkIfAnyValidSeriesExist(barChart), [barChart]); + + return ( + + + {isVlidSeriesExist && ( + + + + + + + + + + + + )} + {!isVlidSeriesExist && ( + + )} + {histogramActionsOptions?.lensAttributes && histogramActionsOptions?.timerange && ( + + )} + + ); }; diff --git a/x-pack/plugins/security_solution/public/common/components/charts/common.tsx b/x-pack/plugins/security_solution/public/common/components/charts/common.tsx index d7bafffec9a8ff..efb03c12183549 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/common.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/common.tsx @@ -136,3 +136,7 @@ export const checkIfAllValuesAreZero = (data: ChartSeriesData[] | null | undefin data.every((series) => { return Array.isArray(series.value) && (series.value as ChartData[]).every(({ y }) => y === 0); }); + +export const Wrapper = styled.div` + position: relative; +`; diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx index 5cb1cd1051ec6c..af09e14631a19c 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx @@ -8,8 +8,10 @@ import { EuiFlexGroup, EuiFlexItem, EuiIconTip, EuiTitle, EuiTitleSize } from '@elastic/eui'; import React from 'react'; import styled, { css } from 'styled-components'; +import { TypedLensByValueInput } from '../../../../../lens/public'; import { InspectButton } from '../inspect'; +import { HistogramActions } from '../matrix_histogram/histogram_actions'; import { Subtitle } from '../subtitle'; interface HeaderProps { @@ -39,37 +41,46 @@ Header.displayName = 'Header'; export interface HeaderSectionProps extends HeaderProps { children?: React.ReactNode; + growLeftSplit?: boolean; headerFilters?: string | React.ReactNode; height?: number; + hideSubtitle?: boolean; id?: string; + inspectMultiple?: boolean; isInspectDisabled?: boolean; + lensAttributes?: LensAttributes | null; + showInspectButton?: boolean; split?: boolean; + stackByField?: string; stackHeader?: boolean; subtitle?: string | React.ReactNode; + timerange?: { from: string; to: string }; title: string | React.ReactNode; titleSize?: EuiTitleSize; tooltip?: string; - growLeftSplit?: boolean; - inspectMultiple?: boolean; - hideSubtitle?: boolean; } const HeaderSectionComponent: React.FC = ({ border, children, + getLensAttributes, + growLeftSplit = true, headerFilters, height, + hideSubtitle = false, id, + inspectMultiple = false, isInspectDisabled, + lensAttributes, + showInspectButton = true, split, + stackByField, stackHeader, subtitle, + timerange, title, titleSize = 'm', tooltip, - growLeftSplit = true, - inspectMultiple = false, - hideSubtitle = false, }) => (
= ({ {id && ( - - - + <> + {showInspectButton && ( + + + + )} + {(getLensAttributes || lensAttributes) && timerange && ( + + + + )} + )} {headerFilters && {headerFilters}} diff --git a/x-pack/plugins/security_solution/public/common/components/inspect/index.tsx b/x-pack/plugins/security_solution/public/common/components/inspect/index.tsx index defb90b9054f11..134faa0928b93c 100644 --- a/x-pack/plugins/security_solution/public/common/components/inspect/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/inspect/index.tsx @@ -6,17 +6,14 @@ */ import { EuiButtonEmpty, EuiButtonIcon } from '@elastic/eui'; -import { omit } from 'lodash/fp'; -import React, { useMemo, useCallback } from 'react'; -import { connect, ConnectedProps } from 'react-redux'; +import React from 'react'; -import { inputsSelectors, State } from '../../store'; import { InputsModelId } from '../../store/inputs/constants'; -import { inputsActions } from '../../store/inputs'; import { HoverVisibilityContainer } from '../hover_visibility_container'; import { ModalInspectQuery } from './modal'; +import { useInspect } from './use_inspect'; import * as i18n from './translations'; export const BUTTON_CLASS = 'inspectButtonComponent'; @@ -35,84 +32,45 @@ export const InspectButtonContainer: React.FC = ({ ); -interface OwnProps { +interface InspectButtonProps { compact?: boolean; - queryId: string; inputId?: InputsModelId; inspectIndex?: number; isDisabled?: boolean; + multiple?: boolean; onCloseInspect?: () => void; + queryId: string; title: string | React.ReactElement | React.ReactNode; - multiple?: boolean; } -type InspectButtonProps = OwnProps & PropsFromRedux; - const InspectButtonComponent: React.FC = ({ compact = false, inputId = 'global', - inspect, inspectIndex = 0, isDisabled, - isInspected, - loading, multiple = false, // If multiple = true we ignore the inspectIndex and pass all requests and responses to the inspect modal onCloseInspect, queryId = '', - selectedInspectIndex, - setIsInspected, title = '', }) => { - const handleClick = useCallback(() => { - setIsInspected({ - id: queryId, - inputId, - isInspected: true, - selectedInspectIndex: inspectIndex, - }); - }, [setIsInspected, queryId, inputId, inspectIndex]); - - const handleCloseModal = useCallback(() => { - if (onCloseInspect != null) { - onCloseInspect(); - } - setIsInspected({ - id: queryId, - inputId, - isInspected: false, - selectedInspectIndex: inspectIndex, - }); - }, [onCloseInspect, setIsInspected, queryId, inputId, inspectIndex]); - - let request: string | null = null; - let additionalRequests: string[] | null = null; - if (inspect != null && inspect.dsl.length > 0) { - if (multiple) { - [request, ...additionalRequests] = inspect.dsl; - } else { - request = inspect.dsl[inspectIndex]; - } - } - - let response: string | null = null; - let additionalResponses: string[] | null = null; - if (inspect != null && inspect.response.length > 0) { - if (multiple) { - [response, ...additionalResponses] = inspect.response; - } else { - response = inspect.response[inspectIndex]; - } - } - - const isShowingModal = useMemo( - () => !loading && selectedInspectIndex === inspectIndex && isInspected, - [inspectIndex, isInspected, loading, selectedInspectIndex] - ); - - const isButtonDisabled = useMemo( - () => loading || isDisabled || request == null || response == null, - [isDisabled, loading, request, response] - ); + const { + additionalRequests, + additionalResponses, + handleClick, + handleCloseModal, + isButtonDisabled, + isShowingModal, + loading, + request, + response, + } = useInspect({ + inputId, + inspectIndex, + isDisabled, + multiple, + onCloseInspect, + queryId, + }); return ( <> @@ -159,25 +117,5 @@ const InspectButtonComponent: React.FC = ({ ); }; -const makeMapStateToProps = () => { - const getGlobalQuery = inputsSelectors.globalQueryByIdSelector(); - const getTimelineQuery = inputsSelectors.timelineQueryByIdSelector(); - const mapStateToProps = (state: State, { inputId = 'global', queryId }: OwnProps) => { - const props = - inputId === 'global' ? getGlobalQuery(state, queryId) : getTimelineQuery(state, queryId); - // refetch caused unnecessary component rerender and it was even not used - const propsWithoutRefetch = omit('refetch', props); - return propsWithoutRefetch; - }; - return mapStateToProps; -}; - -const mapDispatchToProps = { - setIsInspected: inputsActions.setInspectionParameter, -}; - -const connector = connect(makeMapStateToProps, mapDispatchToProps); - -type PropsFromRedux = ConnectedProps; - -export const InspectButton = connector(React.memo(InspectButtonComponent)); +InspectButtonComponent.displayName = 'InspectButtonComponent'; +export const InspectButton = React.memo(InspectButtonComponent); diff --git a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx new file mode 100644 index 00000000000000..66f00b88138a33 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx @@ -0,0 +1,106 @@ +/* + * 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 { useCallback, useMemo } from 'react'; +import { useDispatch } from 'react-redux'; +import { useDeepEqualSelector } from '../../hooks/use_selector'; +import { inputsSelectors } from '../../store'; +import { inputsActions } from '../../store/actions'; +import { InputsModelId } from '../../store/inputs/constants'; + +interface UseInspectModalProps { + inputId?: InputsModelId; + inspectIndex?: number; + isDisabled?: boolean; + multiple?: boolean; + onCloseInspect?: () => void; + queryId: string; +} + +export const useInspect = ({ + inputId = 'global', + inspectIndex = 0, + isDisabled, + multiple = false, // If multiple = true we ignore the inspectIndex and pass all requests and responses to the inspect modal + onCloseInspect, + queryId, +}: UseInspectModalProps) => { + const dispatch = useDispatch(); + + const getGlobalQuery = inputsSelectors.globalQueryByIdSelector(); + const getTimelineQuery = inputsSelectors.timelineQueryByIdSelector(); + const { loading, inspect, selectedInspectIndex, isInspected } = useDeepEqualSelector((state) => + inputId === 'global' ? getGlobalQuery(state, queryId) : getTimelineQuery(state, queryId) + ); + + const handleClick = useCallback(() => { + dispatch( + inputsActions.setInspectionParameter({ + id: queryId, + inputId, + isInspected: true, + selectedInspectIndex: inspectIndex, + }) + ); + }, [dispatch, queryId, inputId, inspectIndex]); + + const handleCloseModal = useCallback(() => { + if (onCloseInspect != null) { + onCloseInspect(); + } + dispatch( + inputsActions.setInspectionParameter({ + id: queryId, + inputId, + isInspected: false, + selectedInspectIndex: inspectIndex, + }) + ); + }, [onCloseInspect, dispatch, queryId, inputId, inspectIndex]); + + let request: string | null = null; + let additionalRequests: string[] | null = null; + if (inspect != null && inspect.dsl.length > 0) { + if (multiple) { + [request, ...additionalRequests] = inspect.dsl; + } else { + request = inspect.dsl[inspectIndex]; + } + } + + let response: string | null = null; + let additionalResponses: string[] | null = null; + if (inspect != null && inspect.response.length > 0) { + if (multiple) { + [response, ...additionalResponses] = inspect.response; + } else { + response = inspect.response[inspectIndex]; + } + } + + const isShowingModal = useMemo( + () => !loading && selectedInspectIndex === inspectIndex && isInspected, + [inspectIndex, isInspected, loading, selectedInspectIndex] + ); + + const isButtonDisabled = useMemo( + () => loading || isDisabled || request == null || response == null, + [isDisabled, loading, request, response] + ); + + return { + additionalRequests, + additionalResponses, + handleClick, + handleCloseModal, + isButtonDisabled, + isShowingModal, + loading, + request, + response, + }; +}; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx new file mode 100644 index 00000000000000..d87ce0b38364fb --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx @@ -0,0 +1,207 @@ +/* + * 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 { + EuiButtonIcon, + EuiContextMenuItem, + EuiContextMenuPanel, + EuiPopover, + useGeneratedHtmlId, +} from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; +import React, { useState } from 'react'; +import styled from 'styled-components'; +import { LensEmbeddableInput, TypedLensByValueInput } from '../../../../../lens/public'; +import { useKibana } from '../../lib/kibana/kibana_react'; + +import { InputsModelId } from '../../store/inputs/constants'; +import { ModalInspectQuery } from '../inspect/modal'; +import { useInspect } from '../inspect/use_inspect'; +import { useLensAttributes } from './use_lens_attributes'; + +export type LensAttributes = TypedLensByValueInput['attributes']; + +export interface HistogramActionsProps { + className?: string; + getLensAttributes?: (stackByField?: string) => LensAttributes; + inputId?: InputsModelId; + inspectIndex?: number; + isInspectButtonDisabled?: boolean; + isMultipleQuery?: boolean; + lensAttributes: LensAttributes; + onCloseInspect?: () => void; + queryId: string; + timerange: { from: string; to: string }; + title: React.ReactNode; + stackByField?: string; +} + +const StyledEuiPopover = styled(EuiPopover)` + &.kpi-matrix-histogram-actions { + position: absolute; + top: 0; + right: 0; + } +`; + +export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; + +export const HistogramActions = ({ + className, + getLensAttributes, + inputId = 'global', + inspectIndex = 0, + isInspectButtonDisabled, + isMultipleQuery, + lensAttributes, + onCloseInspect, + queryId, + timerange, + title, + stackByField, +}: HistogramActionsProps) => { + const { lens } = useKibana().services; + const { + canUseEditor, + navigateToPrefilledEditor, + SaveModalComponent: LensSaveModalComponent, + } = lens; + const [isPopoverOpen, setPopover] = useState(false); + const [isSaveModalVisible, setIsSaveModalVisible] = useState(false); + + const contextMenuPopoverId = useGeneratedHtmlId({ + prefix: 'contextMenuPopover', + }); + + const onButtonClick = () => { + setPopover(!isPopoverOpen); + }; + + const closePopover = () => { + setPopover(false); + }; + + const { + additionalRequests, + additionalResponses, + handleClick: handleInspectButtonClick, + handleCloseModal: handleCloseInspectModal, + isButtonDisabled: disableInspectButton, + isShowingModal, + request, + response, + } = useInspect({ + inputId, + inspectIndex, + isDisabled: isInspectButtonDisabled, + multiple: isMultipleQuery, + onCloseInspect, + queryId, + }); + + const lensAttrsWithInjectedData = useLensAttributes({ + lensAttributes, + getLensAttributes, + stackByField, + }); + + const items = [ + { + closePopover(); + navigateToPrefilledEditor( + { + id: '', + timeRange: timerange, + attributes: lensAttrsWithInjectedData, + }, + { + openInNewTab: true, + } + ); + }} + > + + , + { + setIsSaveModalVisible(true); + closePopover(); + }} + > + + , + { + handleInspectButtonClick(); + closePopover(); + }} + disabled={queryId == null || disableInspectButton} + > + + , + ]; + + const button = ( + + ); + + return ( + <> + {isSaveModalVisible && ( + {}} + onClose={() => setIsSaveModalVisible(false)} + /> + )} + + + + {isShowingModal && request !== null && response !== null && ( + + )} + + ); +}; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index cde30fb81176f2..5355cf4997c629 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -29,20 +29,25 @@ import { import { GlobalTimeArgs } from '../../containers/use_global_time'; import { setAbsoluteRangeDatePicker } from '../../store/inputs/actions'; import { InputsModelId } from '../../store/inputs/constants'; +import { HISTOGRAM_ACTIONS_BUTTON_CLASS, LensAttributes } from './histogram_actions'; +import { HoverVisibilityContainer } from '../hover_visibility_container'; export type MatrixHistogramComponentProps = MatrixHistogramProps & Omit & { defaultStackByOption: MatrixHistogramOption; errorMessage: string; + getLensAttributes?: (stackByField?: string) => LensAttributes; headerChildren?: React.ReactNode; hideHistogramIfEmpty?: boolean; histogramType: MatrixHistogramType; id: string; legendPosition?: Position; + lensAttributes?: LensAttributes; mapping?: MatrixHistogramMappingTypes; onError?: () => void; showSpacer?: boolean; setQuery: GlobalTimeArgs['setQuery']; + showInspectButton?: boolean; setAbsoluteRangeDatePickerTarget?: InputsModelId; showLegend?: boolean; stackByOptions: MatrixHistogramOption[]; @@ -70,6 +75,7 @@ export const MatrixHistogramComponent: React.FC = endDate, errorMessage, filterQuery, + getLensAttributes, headerChildren, histogramType, hideHistogramIfEmpty = false, @@ -78,12 +84,14 @@ export const MatrixHistogramComponent: React.FC = runtimeMappings, isPtrIncluded, legendPosition, + lensAttributes, mapping, onError, paddingSize = 'm', panelHeight = DEFAULT_PANEL_HEIGHT, setAbsoluteRangeDatePickerTarget = 'global', setQuery, + showInspectButton = true, showLegend, showSpacer = true, stackByOptions, @@ -196,13 +204,17 @@ export const MatrixHistogramComponent: React.FC = setIsInitialLoading, ]); + const timerange = useMemo(() => ({ from: startDate, to: endDate }), [startDate, endDate]); if (hideHistogram) { return null; } return ( <> - + = titleSize={titleSize} subtitle={subtitleWithCounts} inspectMultiple + showInspectButton={showInspectButton} isInspectDisabled={filterQuery === undefined} + lensAttributes={lensAttributes} + stackByField={selectedStackByOption.value} + timerange={timerange} + getLensAttributes={getLensAttributes} > - - - {stackByOptions.length > 1 && ( + {stackByOptions.length > 1 && ( + + - )} - - {headerChildren} - + + {headerChildren} + + )} {isInitialLoading ? ( @@ -251,7 +268,7 @@ export const MatrixHistogramComponent: React.FC = /> )} - + {showSpacer && } ); diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts index 47253d36900bd8..2be939679952cb 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts @@ -17,6 +17,7 @@ import { UpdateDateRange } from '../charts/common'; import { GlobalTimeArgs } from '../../containers/use_global_time'; import { DocValueFields } from '../../../../common/search_strategy'; import { FieldValueThreshold } from '../../../detections/components/rules/threshold_input'; +import { TypedLensByValueInput } from '../../../../../lens/public'; export type MatrixHistogramMappingTypes = Record< string, @@ -33,9 +34,11 @@ export type GetTitle = (matrixHistogramOption: MatrixHistogramOption) => string; export interface MatrixHistogramConfigs { defaultStackByOption: MatrixHistogramOption; errorMessage: string; + getLensAttributes?: (params: { stackByField?: string }) => TypedLensByValueInput['attributes']; hideHistogramIfEmpty?: boolean; histogramType: MatrixHistogramType; legendPosition?: Position; + lensAttributes?: TypedLensByValueInput['attributes']; mapping?: MatrixHistogramMappingTypes; stackByOptions: MatrixHistogramOption[]; subtitle?: string | GetSubTitle; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx new file mode 100644 index 00000000000000..2b080389dcdf86 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx @@ -0,0 +1,94 @@ +/* + * 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 { useMemo } from 'react'; +import { useParams, useLocation } from 'react-router-dom'; +import { TypedLensByValueInput } from '../../../../../lens/public'; +import { SecurityPageName } from '../../../../common/constants'; +import { NetworkRouteType } from '../../../network/pages/navigation/types'; +import { useSourcererDataView } from '../../containers/sourcerer'; +import { useDeepEqualSelector } from '../../hooks/use_selector'; +import { inputsSelectors } from '../../store'; +import { + getHostDetailsPageFilter, + filterNetworkExternalAlertData, + filterHostExternalAlertData, +} from './utils'; + +export const useLensAttributes = ({ + lensAttributes, + getLensAttributes, + stackByField, +}: { + lensAttributes?: TypedLensByValueInput['attributes']; + getLensAttributes?: (params?: { stackByField?: string }) => TypedLensByValueInput['attributes']; + stackByField?: string; +}): TypedLensByValueInput['attributes'] | null => { + const { dataViewId } = useSourcererDataView(); + const getGlobalQuerySelector = useMemo(() => inputsSelectors.globalQuerySelector(), []); + const getGlobalFiltersQuerySelector = useMemo( + () => inputsSelectors.globalFiltersQuerySelector(), + [] + ); + const query = useDeepEqualSelector(getGlobalQuerySelector); + const filters = useDeepEqualSelector(getGlobalFiltersQuerySelector); + const { detailName, tabName } = useParams<{ detailName: string | undefined; tabName: string }>(); + const location = useLocation(); + const tabsFilters = useMemo(() => { + if (location.pathname.includes(SecurityPageName.hosts) && tabName === 'externalAlerts') { + return filters.length > 0 + ? [...filters, ...filterHostExternalAlertData] + : filterHostExternalAlertData; + } + + if ( + location.pathname.includes(SecurityPageName.network) && + tabName === NetworkRouteType.alerts + ) { + return filters.length > 0 + ? [...filters, ...filterNetworkExternalAlertData] + : filterNetworkExternalAlertData; + } + + return filters; + }, [tabName, location.pathname, filters]); + + const pageFilters = useMemo(() => { + if (location.pathname.includes(SecurityPageName.hosts) && detailName != null) { + return [...filters, ...getHostDetailsPageFilter(detailName)]; + } + return filters; + }, [location.pathname, detailName, filters]); + + const lensAttrsWithInjectedData = useMemo(() => { + const attrs = lensAttributes ?? (getLensAttributes && getLensAttributes({ stackByField })); + return attrs != null + ? ({ + ...attrs, + state: { + ...attrs.state, + query, + filters: [...attrs.state.filters, ...pageFilters, ...tabsFilters], + }, + references: attrs.references.map((ref: { id: string; name: string; type: string }) => ({ + ...ref, + id: dataViewId, + })), + } as TypedLensByValueInput['attributes']) + : null; + }, [ + lensAttributes, + getLensAttributes, + stackByField, + query, + pageFilters, + tabsFilters, + dataViewId, + ]); + + return lensAttrsWithInjectedData; +}; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts index 6594dc30d5ce81..2faf438150c524 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts @@ -106,3 +106,110 @@ export const getCustomChartData = ( return { ...item, color: mapItem?.color ?? defaultLegendColors[idx] }; }); }; + +export const getHostDetailsPageFilter = (hostName?: string): Filter[] => + hostName + ? [ + { + meta: { + index: 'e5bb994d-e8fb-4ddb-a36e-730ad8cc0712', + alias: null, + negate: false, + disabled: false, + type: 'phrase', + key: 'host.name', + params: { + query: hostName, + }, + }, + query: { + match_phrase: { + 'host.name': hostName, + }, + }, + }, + ] + : []; + +export const filterHostExternalAlertData: Filter[] = [ + { + query: { + bool: { + filter: [ + { + bool: { + should: [ + { + exists: { + field: 'host.name', + }, + }, + ], + minimum_should_match: 1, + }, + }, + ], + }, + }, + meta: { + alias: '', + disabled: false, + key: 'bool', + negate: false, + type: 'custom', + value: + '{"query": {"bool": {"filter": [{"bool": {"should": [{"exists": {"field": "host.name"}}],"minimum_should_match": 1}}]}}}', + }, + }, +]; + +export const filterNetworkExternalAlertData: Filter[] = [ + { + query: { + bool: { + filter: [ + { + bool: { + should: [ + { + bool: { + should: [ + { + exists: { + field: 'source.ip', + }, + }, + ], + minimum_should_match: 1, + }, + }, + { + bool: { + should: [ + { + exists: { + field: 'destination.ip', + }, + }, + ], + minimum_should_match: 1, + }, + }, + ], + minimum_should_match: 1, + }, + }, + ], + }, + }, + meta: { + alias: '', + disabled: false, + key: 'bool', + negate: false, + type: 'custom', + value: + '{"bool":{"filter":[{"bool":{"should":[{"bool":{"should":[{"exists":{"field": "source.ip"}}],"minimum_should_match":1}},{"bool":{"should":[{"exists":{"field": "destination.ip"}}],"minimum_should_match":1}}],"minimum_should_match":1}}]}}', + }, + }, +]; diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 2d8d55a5c943f3..8d0bcbab1e00a7 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -16,7 +16,7 @@ import { IconType, } from '@elastic/eui'; import { get, getOr } from 'lodash/fp'; -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useMemo } from 'react'; import styled from 'styled-components'; import deepEqual from 'fast-deep-equal'; @@ -31,9 +31,16 @@ import { histogramDateTimeFormatter } from '../utils'; import { getEmptyTagValue } from '../empty_value'; import { InspectButton, InspectButtonContainer } from '../inspect'; +import { + HistogramActions, + HISTOGRAM_ACTIONS_BUTTON_CLASS, + LensAttributes, +} from '../matrix_histogram/histogram_actions'; +import { HoverVisibilityContainer } from '../hover_visibility_container'; const FlexItem = styled(EuiFlexItem)` min-width: 0; + position: relative; `; FlexItem.displayName = 'FlexItem'; @@ -53,6 +60,7 @@ interface StatItem { key: string; name?: string; value: number | undefined | null; + lensAttributes?: LensAttributes; } export interface StatItems { @@ -66,6 +74,8 @@ export interface StatItems { index?: number; key: string; statKey?: string; + barChartLensAttributes?: LensAttributes; + areaChartLensAttributes?: LensAttributes; } export interface StatItemsProps extends StatItems { @@ -75,6 +85,7 @@ export interface StatItemsProps extends StatItems { id: string; narrowDateRange: UpdateDateRange; to: string; + showInspectButton?: boolean; } export const numberFormatter = (value: string | number): string => value.toLocaleString(); @@ -205,10 +216,13 @@ export const StatItemsComponent = React.memo( from, grow, id, + showInspectButton = true, index, narrowDateRange, statKey = 'item', to, + barChartLensAttributes, + areaChartLensAttributes, }) => { const isBarChartDataAvailable = barChart && @@ -219,58 +233,90 @@ export const StatItemsComponent = React.memo( areaChart.length && areaChart.every((item) => item.value != null && item.value.length > 0); + const timerange = useMemo( + () => ({ + from, + to, + }), + [from, to] + ); + return ( - - - - - -
{description}
-
-
+ + + + +
{description}
+
+
+ {showInspectButton && ( -
+ )} +
- - {fields.map((field) => ( - - - {(isAreaChartDataAvailable || isBarChartDataAvailable) && field.icon && ( - - - - )} + + {fields.map((field) => ( + + + {(isAreaChartDataAvailable || isBarChartDataAvailable) && field.icon && ( + + + + )} - + +

{field.value != null ? field.value.toLocaleString() : getEmptyTagValue()}{' '} {field.description}

-
-
-
- ))} -
+ {field.lensAttributes && timerange && ( + + )} + +
+
+
+ ))} +
- {(enableAreaChart || enableBarChart) && } - - {enableBarChart && ( - - - - )} + {(enableAreaChart || enableBarChart) && } + + {enableBarChart && ( + + + + )} - {enableAreaChart && from != null && to != null && ( + {enableAreaChart && from != null && to != null && ( + <> ( xTickFormatter: histogramDateTimeFormatter([from, to]), onBrushEnd: narrowDateRange, })} + histogramActionsOptions={{ + lensAttributes: areaChartLensAttributes, + queryId: id, + inspectIndex: index, + timerange, + title: `KPI ${description}`, + }} /> - )} - - - + + )} + + ); }, diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx index c05d462226c51e..8fb33b89e1ddd4 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx @@ -8,6 +8,10 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; +import { kpiUserAuthenticationsMetricSuccess } from '../../../configs/kpi_user_authentications-metric_success'; +import { kpiUserAuthenticationsArea } from '../../../configs/kpi_user_authentications_area'; +import { kpiUserAuthenticationsBar } from '../../../configs/kpi_user_authentications_bar'; +import { kpiUserAuthenticationsMetricFailure } from '../../../configs/kpi_user_authentication_metric_failure'; import { useHostsKpiAuthentications } from '../../../containers/kpi_hosts/authentications'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; @@ -24,6 +28,7 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.authenticationsSuccess, icon: 'check', + lensAttributes: kpiUserAuthenticationsMetricSuccess, }, { key: 'authenticationsFailure', @@ -32,11 +37,14 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.authenticationsFailure, icon: 'cross', + lensAttributes: kpiUserAuthenticationsMetricFailure, }, ], enableAreaChart: true, enableBarChart: true, description: i18n.USER_AUTHENTICATIONS, + areaChartLensAttributes: kpiUserAuthenticationsArea, + barChartLensAttributes: kpiUserAuthenticationsBar, }, ]; @@ -69,6 +77,7 @@ const HostsKpiAuthenticationsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx index 206b452d838989..7e5d40d8393ed5 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx @@ -36,10 +36,11 @@ interface HostsKpiBaseComponentProps { from: string; to: string; narrowDateRange: UpdateDateRange; + showInspectButton?: boolean; } export const HostsKpiBaseComponent = React.memo( - ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange }) => { + ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange, showInspectButton }) => { const statItemsProps: StatItemsProps[] = useKpiMatrixStatus( fieldsMapping, data, @@ -56,7 +57,7 @@ export const HostsKpiBaseComponent = React.memo( return ( {statItemsProps.map((mappedStatItemProps) => ( - + ))} ); diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx index 71a8d15aceb575..e46133e71e5efc 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx @@ -8,6 +8,8 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; +import { kpiHostArea } from '../../../configs/kpi_host_area'; +import { kpiHostMetric } from '../../../configs/kpi_host_metric'; import { useHostsKpiHosts } from '../../../containers/kpi_hosts/hosts'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; @@ -22,10 +24,12 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.hosts, icon: 'storage', + lensAttributes: kpiHostMetric, }, ], enableAreaChart: true, description: i18n.HOSTS, + areaChartLensAttributes: kpiHostArea, }, ]; @@ -58,6 +62,7 @@ const HostsKpiHostsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx index ce6a1a71050687..efc873f096402c 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx @@ -8,6 +8,10 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; +import { kpiUniqueIpsArea } from '../../../configs/kpi_unique_ips-area'; +import { kpiUniqueIpsBar } from '../../../configs/kpi_unique_ips-bar'; +import { kpiUniqueIpsDestinationMetric } from '../../../configs/kpi_unique_ips-destination_metric'; +import { kpiUniqueIpsSourceMetric } from '../../../configs/kpi_unique_ips-source_metric'; import { useHostsKpiUniqueIps } from '../../../containers/kpi_hosts/unique_ips'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; @@ -24,6 +28,7 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.uniqueSourceIps, icon: 'visMapCoordinate', + lensAttributes: kpiUniqueIpsSourceMetric, }, { key: 'uniqueDestinationIps', @@ -32,11 +37,14 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.uniqueDestinationIps, icon: 'visMapCoordinate', + lensAttributes: kpiUniqueIpsDestinationMetric, }, ], enableAreaChart: true, enableBarChart: true, description: i18n.UNIQUE_IPS, + areaChartLensAttributes: kpiUniqueIpsArea, + barChartLensAttributes: kpiUniqueIpsBar, }, ]; @@ -69,6 +77,7 @@ const HostsKpiUniqueIpsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/events.ts b/x-pack/plugins/security_solution/public/hosts/configs/events.ts index eee1b1086b3b8e..71acd3eee3da75 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/events.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/events.ts @@ -5,118 +5,119 @@ * 2.0. */ -import { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; - -export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'event.action') => - ({ - title: 'Host - events', - description: '', - visualizationType: 'lnsXY', - state: { - visualization: { - title: 'Empty XY chart', - legend: { - isVisible: true, - position: 'right', - }, - valueLabels: 'hide', - preferredSeriesType: 'bar_stacked', - layers: [ - { - layerId: '0039eb0c-9a1a-4687-ae54-0f4e239bec75', - accessors: ['e09e0380-0740-4105-becc-0a4ca12e3944'], - position: 'top', - seriesType: 'bar_stacked', - showGridlines: false, - layerType: 'data', - xAccessor: 'aac9d7d0-13a3-480a-892b-08207a787926', - splitAccessor: '34919782-4546-43a5-b668-06ac934d3acd', - }, - ], - yRightExtent: { - mode: 'full', - }, - yLeftExtent: { - mode: 'full', - }, - axisTitlesVisibilitySettings: { - x: false, - yLeft: false, - yRight: true, +export const getEventsHistogramCongifs = ({ + stackByField = 'event.action', +}: { + stackByField?: string; +}) => ({ + title: 'Host - events', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + title: 'Empty XY chart', + legend: { + isVisible: true, + position: 'right', + }, + valueLabels: 'hide', + preferredSeriesType: 'bar_stacked', + layers: [ + { + layerId: '0039eb0c-9a1a-4687-ae54-0f4e239bec75', + accessors: ['e09e0380-0740-4105-becc-0a4ca12e3944'], + position: 'top', + seriesType: 'bar_stacked', + showGridlines: false, + layerType: 'data', + xAccessor: 'aac9d7d0-13a3-480a-892b-08207a787926', + splitAccessor: '34919782-4546-43a5-b668-06ac934d3acd', }, + ], + yRightExtent: { + mode: 'full', }, - query: { - query: '', - language: 'kuery', + yLeftExtent: { + mode: 'full', }, - filters: [], - datasourceStates: { - indexpattern: { - layers: { - '0039eb0c-9a1a-4687-ae54-0f4e239bec75': { - columns: { - 'aac9d7d0-13a3-480a-892b-08207a787926': { - label: '@timestamp', - dataType: 'date', - operationType: 'date_histogram', - sourceField: '@timestamp', - isBucketed: true, - scale: 'interval', - params: { - interval: 'auto', - }, - }, - 'e09e0380-0740-4105-becc-0a4ca12e3944': { - label: 'Count of records', - dataType: 'number', - operationType: 'count', - isBucketed: false, - scale: 'ratio', - sourceField: '___records___', + axisTitlesVisibilitySettings: { + x: false, + yLeft: false, + yRight: true, + }, + }, + query: { + query: '', + language: 'kuery', + }, + filters: [], + datasourceStates: { + indexpattern: { + layers: { + '0039eb0c-9a1a-4687-ae54-0f4e239bec75': { + columns: { + 'aac9d7d0-13a3-480a-892b-08207a787926': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', }, - '34919782-4546-43a5-b668-06ac934d3acd': { - label: `Top values of ${stackByField}`, // could be event.dataset or event.module - dataType: 'string', - operationType: 'terms', - scale: 'ordinal', - sourceField: `${stackByField}`, // could be event.dataset or event.module - isBucketed: true, - params: { - size: 10, - orderBy: { - type: 'column', - columnId: 'e09e0380-0740-4105-becc-0a4ca12e3944', - }, - orderDirection: 'desc', - otherBucket: true, - missingBucket: false, - parentFormat: { - id: 'terms', - }, + }, + 'e09e0380-0740-4105-becc-0a4ca12e3944': { + label: 'Count of records', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + }, + '34919782-4546-43a5-b668-06ac934d3acd': { + label: `Top values of ${stackByField}`, // could be event.dataset or event.module + dataType: 'string', + operationType: 'terms', + scale: 'ordinal', + sourceField: `${stackByField}`, // could be event.dataset or event.module + isBucketed: true, + params: { + size: 10, + orderBy: { + type: 'column', + columnId: 'e09e0380-0740-4105-becc-0a4ca12e3944', + }, + orderDirection: 'desc', + otherBucket: true, + missingBucket: false, + parentFormat: { + id: 'terms', }, }, }, - columnOrder: [ - '34919782-4546-43a5-b668-06ac934d3acd', - 'aac9d7d0-13a3-480a-892b-08207a787926', - 'e09e0380-0740-4105-becc-0a4ca12e3944', - ], - incompleteColumns: {}, }, + columnOrder: [ + '34919782-4546-43a5-b668-06ac934d3acd', + 'aac9d7d0-13a3-480a-892b-08207a787926', + 'e09e0380-0740-4105-becc-0a4ca12e3944', + ], + incompleteColumns: {}, }, }, }, }, - references: [ - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-current-indexpattern', - }, - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-layer-0039eb0c-9a1a-4687-ae54-0f4e239bec75', - }, - ], - } as LensAttributes); + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-0039eb0c-9a1a-4687-ae54-0f4e239bec75', + }, + ], +}); diff --git a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts index 555b8133a8479a..8c5fd3dfeca560 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts @@ -5,9 +5,11 @@ * 2.0. */ -import { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; - -export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event.module') => { +export const getExternalAlertConfigs = ({ + stackByField = 'event.module', +}: { + stackByField?: string; +}) => { return { title: 'external alerts', description: '', @@ -146,5 +148,5 @@ export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event id: 'security-solution-default', }, ], - } as LensAttributes; + }; }; diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx index b8dcc1dba28a07..4dc7dad70245b9 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx @@ -20,6 +20,8 @@ import { MatrixHistogram } from '../../../common/components/matrix_histogram'; import { HostsKpiChartColors } from '../../components/kpi_hosts/types'; import * as i18n from '../translations'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; +import { authentication } from '../../configs/authentication'; +import { TypedLensByValueInput } from '../../../../../lens/public'; const AuthenticationTableManage = manageQuery(AuthenticationTable); @@ -60,6 +62,7 @@ const histogramConfigs: MatrixHistogramConfigs = { mapping: authenticationsMatrixDataMappingFields, stackByOptions: authenticationsStackByOptions, title: i18n.NAVIGATION_AUTHENTICATIONS_TITLE, + lensAttributes: authentication as TypedLensByValueInput['attributes'], }; const AuthenticationsQueryTabBodyComponent: React.FC = ({ @@ -103,6 +106,7 @@ const AuthenticationsQueryTabBodyComponent: React.FC indexNames={indexNames} setQuery={setQuery} startDate={startDate} + showInspectButton={false} {...histogramConfigs} /> diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx index a4889183cdf3d9..9e0b227550dd42 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx @@ -28,6 +28,7 @@ import { SourcererScopeName } from '../../../common/store/sourcerer/model'; import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features'; import { DEFAULT_COLUMN_MIN_WIDTH } from '../../../timelines/components/timeline/body/constants'; import { defaultCellActions } from '../../../common/lib/cell_actions/default_cell_actions'; +import { getEventsHistogramCongifs } from '../../configs/events'; const EVENTS_HISTOGRAM_ID = 'eventsHistogramQuery'; @@ -57,6 +58,7 @@ export const histogramConfigs: MatrixHistogramConfigs = { stackByOptions: eventsStackByOptions, subtitle: undefined, title: i18n.NAVIGATION_EVENTS_TITLE, + getLensAttributes: getEventsHistogramCongifs, }; const EventsQueryTabBodyComponent: React.FC = ({ @@ -109,6 +111,7 @@ const EventsQueryTabBodyComponent: React.FC = ({ startDate={startDate} id={EVENTS_HISTOGRAM_ID} indexNames={indexNames} + showInspectButton={false} {...histogramConfigs} /> )} From 2a70a70ccc774fb3eadc53faab92eb27358cf498 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Sun, 27 Feb 2022 05:35:57 +0800 Subject: [PATCH 03/59] init network chart actions --- .../components/kpi_network/common/index.tsx | 14 ++++++++++++-- .../network/components/kpi_network/dns/index.tsx | 3 +++ .../kpi_network/network_events/index.tsx | 3 +++ .../kpi_network/tls_handshakes/index.tsx | 3 +++ .../components/kpi_network/unique_flows/index.tsx | 3 +++ .../kpi_network/unique_private_ips/index.tsx | 9 +++++++++ .../pages/navigation/dns_query_tab_body.tsx | 2 ++ 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx index 051fdbdb6513e2..7eab8a26a36382 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx @@ -36,8 +36,18 @@ export const NetworkKpiBaseComponent = React.memo<{ from: string; to: string; narrowDateRange: UpdateDateRange; + showInspectButton?: boolean; }>( - ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange }) => { + ({ + fieldsMapping, + data, + id, + loading = false, + from, + to, + narrowDateRange, + showInspectButton = true, + }) => { const statItemsProps: StatItemsProps[] = useKpiMatrixStatus( fieldsMapping, data, @@ -60,7 +70,7 @@ export const NetworkKpiBaseComponent = React.memo<{ return ( {statItemsProps.map((mappedStatItemProps) => ( - + ))} ); diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx index c55cfbf7ac87ff..da78e33dfd95db 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx @@ -8,6 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; +import { kpiDnsQueries } from '../../../configs/kpi_dns_queries'; import { useNetworkKpiDns } from '../../../containers/kpi_network/dns'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; @@ -20,6 +21,7 @@ export const fieldsMapping: Readonly = [ { key: 'dnsQueries', value: null, + lensAttributes: kpiDnsQueries, }, ], description: i18n.DNS_QUERIES, @@ -55,6 +57,7 @@ const NetworkKpiDnsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx index 6eeb48b5cc07b7..eee292359389d2 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx @@ -13,6 +13,7 @@ import { useNetworkKpiNetworkEvents } from '../../../containers/kpi_network/netw import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; import * as i18n from './translations'; +import { kpiNetworkEvents } from '../../../configs/kpi_network_events'; const euiVisColorPalette = euiPaletteColorBlind(); const euiColorVis1 = euiVisColorPalette[1]; @@ -25,6 +26,7 @@ export const fieldsMapping: Readonly = [ key: 'networkEvents', value: null, color: euiColorVis1, + lensAttributes: kpiNetworkEvents, }, ], description: i18n.NETWORK_EVENTS, @@ -60,6 +62,7 @@ const NetworkKpiNetworkEventsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx index e2142a347e0f6a..8061dc368af310 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx @@ -8,6 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; +import { kpiTlsHandshakes } from '../../../configs/kpi_tls_handshakes'; import { useNetworkKpiTlsHandshakes } from '../../../containers/kpi_network/tls_handshakes'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; @@ -20,6 +21,7 @@ export const fieldsMapping: Readonly = [ { key: 'tlsHandshakes', value: null, + lensAttributes: kpiTlsHandshakes, }, ], description: i18n.TLS_HANDSHAKES, @@ -55,6 +57,7 @@ const NetworkKpiTlsHandshakesComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx index b55787caf56ccb..a9aeacfd3a7038 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx @@ -8,6 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; +import { kpiUniqueFlowIds } from '../../../configs/kpi_unique_flow_ids'; import { useNetworkKpiUniqueFlows } from '../../../containers/kpi_network/unique_flows'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; @@ -20,6 +21,7 @@ export const fieldsMapping: Readonly = [ { key: 'uniqueFlowId', value: null, + lensAttributes: kpiUniqueFlowIds, }, ], description: i18n.UNIQUE_FLOW_IDS, @@ -55,6 +57,7 @@ const NetworkKpiUniqueFlowsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx index d50112d3ca57a8..bffd3f069b1486 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx @@ -13,6 +13,10 @@ import { useNetworkKpiUniquePrivateIps } from '../../../containers/kpi_network/u import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; import * as i18n from './translations'; +import { kpiUniquePrivateIpsSourceMetric } from '../../../configs/kpi_unique_private_ips-source_metric'; +import { kpiUniquePrivateIpsDestinationMetric } from '../../../configs/kpi_unique_private_ips-destination_metric'; +import { kpiUniquePrivateIpsArea } from '../../../configs/kpi_unique_private_ips-area'; +import { kpiUniquePrivateIpsBar } from '../../../configs/kpi_unique_private_ips-bar'; const euiVisColorPalette = euiPaletteColorBlind(); const euiColorVis2 = euiVisColorPalette[2]; @@ -29,6 +33,7 @@ export const fieldsMapping: Readonly = [ description: i18n.SOURCE_UNIT_LABEL, color: euiColorVis2, icon: 'visMapCoordinate', + lensAttributes: kpiUniquePrivateIpsSourceMetric, }, { key: 'uniqueDestinationPrivateIps', @@ -37,11 +42,14 @@ export const fieldsMapping: Readonly = [ description: i18n.DESTINATION_UNIT_LABEL, color: euiColorVis3, icon: 'visMapCoordinate', + lensAttributes: kpiUniquePrivateIpsDestinationMetric, }, ], description: i18n.UNIQUE_PRIVATE_IPS, enableAreaChart: true, enableBarChart: true, + areaChartLensAttributes: kpiUniquePrivateIpsArea, + barChartLensAttributes: kpiUniquePrivateIpsBar, }, ]; @@ -74,6 +82,7 @@ const NetworkKpiUniquePrivateIpsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} + showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx index 7c9b2af5159006..99361722bafde5 100644 --- a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx @@ -44,6 +44,7 @@ export const histogramConfigs: Omit = { histogramType: MatrixHistogramType.dns, stackByOptions: dnsStackByOptions, subtitle: undefined, + lensAttributes: dnsTopDomainsAttrs, }; const DnsQueryTabBodyComponent: React.FC = ({ @@ -108,6 +109,7 @@ const DnsQueryTabBodyComponent: React.FC = ({ setQuery={setQuery} showLegend={true} startDate={startDate} + showInspectButton={false} {...dnsHistogramConfigs} /> Date: Mon, 28 Feb 2022 06:40:57 +0800 Subject: [PATCH 04/59] add to new case --- .../common/components/inspect/use_inspect.tsx | 11 +- .../matrix_histogram/histogram_actions.tsx | 213 +++++++++++++++--- .../matrix_histogram/translations.ts | 16 ++ .../components/matrix_histogram/types.ts | 2 + .../use_add_to_existing_case.tsx | 141 ++++++++++++ .../matrix_histogram/use_lens_attributes.tsx | 10 +- .../components/matrix_histogram/utils.ts | 23 ++ 7 files changed, 373 insertions(+), 43 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx diff --git a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx index 66f00b88138a33..d9f633c7d01e3a 100644 --- a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx +++ b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx @@ -17,6 +17,7 @@ interface UseInspectModalProps { inspectIndex?: number; isDisabled?: boolean; multiple?: boolean; + onClick?: () => void; onCloseInspect?: () => void; queryId: string; } @@ -26,6 +27,7 @@ export const useInspect = ({ inspectIndex = 0, isDisabled, multiple = false, // If multiple = true we ignore the inspectIndex and pass all requests and responses to the inspect modal + onClick, onCloseInspect, queryId, }: UseInspectModalProps) => { @@ -38,6 +40,9 @@ export const useInspect = ({ ); const handleClick = useCallback(() => { + if (onClick) { + onClick(); + } dispatch( inputsActions.setInspectionParameter({ id: queryId, @@ -46,7 +51,7 @@ export const useInspect = ({ selectedInspectIndex: inspectIndex, }) ); - }, [dispatch, queryId, inputId, inspectIndex]); + }, [onClick, dispatch, queryId, inputId, inspectIndex]); const handleCloseModal = useCallback(() => { if (onCloseInspect != null) { @@ -88,8 +93,8 @@ export const useInspect = ({ ); const isButtonDisabled = useMemo( - () => loading || isDisabled || request == null || response == null, - [isDisabled, loading, request, response] + () => loading || isDisabled || request == null || response == null || queryId == null, + [isDisabled, loading, queryId, request, response] ); return { diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx index d87ce0b38364fb..cd7ea464a8a8d1 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx @@ -8,22 +8,36 @@ import { EuiButtonIcon, EuiContextMenuItem, EuiContextMenuPanel, + EuiFlexGroup, + EuiFlexItem, + EuiLink, EuiPopover, useGeneratedHtmlId, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -import React, { useState } from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; +import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; +import { Case, CommentType } from '../../../../../cases/common'; +import { + CasesDeepLinkId, + DRAFT_COMMENT_STORAGE_ID, + generateCaseViewPath, + GetAllCasesSelectorModalProps, + GetCreateCaseFlyoutProps, +} from '../../../../../cases/public'; import { LensEmbeddableInput, TypedLensByValueInput } from '../../../../../lens/public'; +import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; import { InputsModelId } from '../../store/inputs/constants'; import { ModalInspectQuery } from '../inspect/modal'; import { useInspect } from '../inspect/use_inspect'; +import { LensAttributes } from './types'; import { useLensAttributes } from './use_lens_attributes'; - -export type LensAttributes = TypedLensByValueInput['attributes']; - +import { useAddToExistingCase } from './use_add_to_existing_case'; +import { useGetUserCasesPermissions } from '../../lib/kibana'; +import { ADD_TO_CASE_SUCCESS, VIEW_CASE } from './translations'; export interface HistogramActionsProps { className?: string; getLensAttributes?: (stackByField?: string) => LensAttributes; @@ -49,6 +63,21 @@ const StyledEuiPopover = styled(EuiPopover)` export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; +const owner = APP_ID; +const appId = 'securitySolutionUI'; + +export const CaseToastText = ({ linkUrl }: { linkUrl: string }) => { + return ( + + + + {VIEW_CASE} + + + + ); +}; + export const HistogramActions = ({ className, getLensAttributes, @@ -63,7 +92,16 @@ export const HistogramActions = ({ title, stackByField, }: HistogramActionsProps) => { - const { lens } = useKibana().services; + const { + lens, + cases, + theme, + application: { getUrlForApp }, + notifications: { toasts }, + } = useKibana().services; + const userPermissions = useGetUserCasesPermissions(); + const userCanCrud = userPermissions?.crud ?? false; + const { canUseEditor, navigateToPrefilledEditor, @@ -84,6 +122,111 @@ export const HistogramActions = ({ setPopover(false); }; + const attributes = useLensAttributes({ + lensAttributes, + getLensAttributes, + stackByField, + }); + + const [isCreateCaseFlyoutOpen, setIsCreateCaseFlyoutOpen] = useState(false); + // const [isSaving, setIsSaving] = useState(false); + + const { + disabled: isAddToCaseDisabled, + closeAllCaseModal, + isAllCaseModalOpen, + onCaseClicked, + onAddToExistingCaseClicked, + } = useAddToExistingCase({ + onAddToCaseClicked: closePopover, + lensAttributes: attributes, + timeRange: timerange, + userCanCrud, + }); + + const onAddToNewCaseClicked = useCallback(() => { + closePopover(); + + setIsCreateCaseFlyoutOpen(true); + }, []); + + const getToastText = useCallback( + (theCase) => + toMountPoint( + , + { theme$: theme?.theme$ } + ), + [getUrlForApp, theme?.theme$] + ); + const onCreateCaseSuccess = useCallback( + async (theCase: Case) => { + setIsCreateCaseFlyoutOpen(false); + toasts.addSuccess( + { + title: ADD_TO_CASE_SUCCESS(theCase.title), + text: getToastText(theCase), + }, + { + toastLifeTimeMs: 10000, + } + ); + }, + [getToastText, toasts] + ); + + const allCasesSelectorModalProps: GetAllCasesSelectorModalProps = { + onRowClick: onCaseClicked, + userCanCrud, + owner: [owner], + onClose: closeAllCaseModal, + }; + + const createCaseFlyoutProps: GetCreateCaseFlyoutProps = useMemo(() => { + const attachments = [ + { + comment: `!{lens${JSON.stringify({ + timeRange: timerange, + attributes, + })}}`, + owner, + type: CommentType.user as const, + }, + ]; + return { + // afterCaseCreated: onCaseCreated, + onClose: () => { + setIsCreateCaseFlyoutOpen(false); + }, + onSuccess: onCreateCaseSuccess, + owner: [owner], + userCanCrud, + // features: casesFeatures, + attachments, + }; + }, [timerange, attributes, onCreateCaseSuccess, userCanCrud]); + + const onOpenInLens = useCallback(() => { + closePopover(); + navigateToPrefilledEditor( + { + id: '', + timeRange: timerange, + attributes, + }, + { + openInNewTab: true, + } + ); + }, [attributes, navigateToPrefilledEditor, timerange]); + const onSaveVisualization = useCallback(() => { + setIsSaveModalVisible(true); + closePopover(); + }, []); const { additionalRequests, additionalResponses, @@ -99,33 +242,16 @@ export const HistogramActions = ({ isDisabled: isInspectButtonDisabled, multiple: isMultipleQuery, onCloseInspect, + onClick: closePopover, queryId, }); - const lensAttrsWithInjectedData = useLensAttributes({ - lensAttributes, - getLensAttributes, - stackByField, - }); - const items = [ { - closePopover(); - navigateToPrefilledEditor( - { - id: '', - timeRange: timerange, - attributes: lensAttrsWithInjectedData, - }, - { - openInNewTab: true, - } - ); - }} + disabled={!canUseEditor() || attributes == null} + onClick={onOpenInLens} > { - setIsSaveModalVisible(true); - closePopover(); - }} + disabled={!userCanCrud} + onClick={onSaveVisualization} > { - handleInspectButtonClick(); - closePopover(); - }} - disabled={queryId == null || disableInspectButton} + onClick={handleInspectButtonClick} + disabled={disableInspectButton} > , + + + , + + + , ]; const button = ( @@ -173,7 +314,7 @@ export const HistogramActions = ({ <> {isSaveModalVisible && ( {}} onClose={() => setIsSaveModalVisible(false)} /> @@ -202,6 +343,8 @@ export const HistogramActions = ({ title={title} /> )} + {isCreateCaseFlyoutOpen && cases.getCreateCaseFlyout(createCaseFlyoutProps)} + {isAllCaseModalOpen && cases.getAllCasesSelectorModal(allCasesSelectorModalProps)} ); }; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts index fe7ac760950bc5..6a343e61ad7b2d 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts @@ -13,3 +13,19 @@ export const STACK_BY = i18n.translate( defaultMessage: 'Stack by', } ); + +export const ADD_TO_CASE_SUCCESS = (caseTitle: string) => + i18n.translate( + 'xpack.securitySolution.components.histogramActopms.addToCase.notificationSuccess', + { + defaultMessage: 'Successfully added visualization to the case: {caseTitle}', + values: { caseTitle }, + } + ); + +export const VIEW_CASE = i18n.translate( + 'xpack.securitySolution.components.histogramActopms.addToCase.notification.viewCase', + { + defaultMessage: 'View case', + } +); diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts index 2be939679952cb..acf6eeec4d1e40 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts @@ -145,3 +145,5 @@ export interface BarchartConfigs { }; customHeight: number; } + +export type LensAttributes = TypedLensByValueInput['attributes']; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx new file mode 100644 index 00000000000000..89a62ce3ac889c --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx @@ -0,0 +1,141 @@ +/* + * 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 { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; +import React, { useCallback, useMemo, useState } from 'react'; +import styled from 'styled-components'; +import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; +import { Case } from '../../../../../cases/common'; +import { + CasesDeepLinkId, + DRAFT_COMMENT_STORAGE_ID, + generateCaseViewPath, +} from '../../../../../cases/public'; +import { APP_ID } from '../../../../common/constants'; +import { useGetUserCasesPermissions } from '../../lib/kibana'; +import { useKibana } from '../../lib/kibana/kibana_react'; +import { VIEW_CASE } from './translations'; + +import { LensAttributes } from './types'; +import { addToCase } from './utils'; + +const appId = 'securitySolutionUI'; +const owner = APP_ID; + +export const useAddToExistingCase = ({ + onAddToCaseClicked, + lensAttributes, + timeRange, + userCanCrud, +}: { + onAddToCaseClicked?: () => void; + lensAttributes: LensAttributes | null; + timeRange: { from: string; to: string }; + userCanCrud: boolean; +}) => { + const { + application: { getUrlForApp, navigateToApp }, + http, + notifications: { toasts }, + storage, + theme, + } = useKibana().services; + const [isAllCaseModalOpen, setIsAllCaseModalOpen] = useState(false); + + const closeAllCaseModal = useCallback(() => { + setIsAllCaseModalOpen(false); + }, []); + + const onAddToExistingCaseClicked = useCallback(() => { + if (onAddToCaseClicked) { + onAddToCaseClicked(); + } + setIsAllCaseModalOpen(true); + }, [onAddToCaseClicked]); + + const getToastText = useCallback( + (theCase) => + toMountPoint( + + + + {VIEW_CASE} + + + , + { theme$: theme?.theme$ } + ), + [getUrlForApp, theme?.theme$] + ); + + const onCaseClicked = useCallback( + (theCase?: Case) => { + if (theCase && lensAttributes) { + setIsAllCaseModalOpen(false); + // setIsSaving(true); + addToCase(http, theCase, lensAttributes, timeRange, owner).then( + () => { + // setIsSaving(false); + toasts.addSuccess( + { + title: 'Successfully added visualization to the case: {caseTitle}', + text: getToastText(theCase), + }, + { + toastLifeTimeMs: 10000, + } + ); + }, + (error) => { + toasts.addError(error, { + // title: i18n.translate( + // 'xpack.observability.expView.heading.addToCase.notification.error', + // { + // defaultMessage: 'Failed to add visualization to the selected case.', + // } + // ), + title: 'Failed to add visualization to the selected case.', + }); + } + ); + } else { + /* save lens attributes and timerange to local storage, + ** so the description field will be automatically filled on case creation page. + */ + storage?.set(DRAFT_COMMENT_STORAGE_ID, { + commentId: 'description', + comment: `!{lens${JSON.stringify({ + timeRange, + attributes: lensAttributes, + })}}`, + position: '', + caseTitle: '', + caseTags: '', + }); + navigateToApp(appId, { + deepLinkId: CasesDeepLinkId.casesCreate, + openInNewTab: true, + }); + } + }, + [getToastText, http, lensAttributes, navigateToApp, storage, timeRange, toasts] + ); + + return { + closeAllCaseModal, + isAllCaseModalOpen, + onCaseClicked, + onAddToExistingCaseClicked, + disabled: lensAttributes == null || !userCanCrud, + }; +}; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx index 2b080389dcdf86..1b1181f0a941fb 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx @@ -7,12 +7,12 @@ import { useMemo } from 'react'; import { useParams, useLocation } from 'react-router-dom'; -import { TypedLensByValueInput } from '../../../../../lens/public'; import { SecurityPageName } from '../../../../common/constants'; import { NetworkRouteType } from '../../../network/pages/navigation/types'; import { useSourcererDataView } from '../../containers/sourcerer'; import { useDeepEqualSelector } from '../../hooks/use_selector'; import { inputsSelectors } from '../../store'; +import { LensAttributes } from './types'; import { getHostDetailsPageFilter, filterNetworkExternalAlertData, @@ -24,10 +24,10 @@ export const useLensAttributes = ({ getLensAttributes, stackByField, }: { - lensAttributes?: TypedLensByValueInput['attributes']; - getLensAttributes?: (params?: { stackByField?: string }) => TypedLensByValueInput['attributes']; + lensAttributes?: LensAttributes; + getLensAttributes?: (params?: { stackByField?: string }) => LensAttributes; stackByField?: string; -}): TypedLensByValueInput['attributes'] | null => { +}): LensAttributes | null => { const { dataViewId } = useSourcererDataView(); const getGlobalQuerySelector = useMemo(() => inputsSelectors.globalQuerySelector(), []); const getGlobalFiltersQuerySelector = useMemo( @@ -78,7 +78,7 @@ export const useLensAttributes = ({ ...ref, id: dataViewId, })), - } as TypedLensByValueInput['attributes']) + } as LensAttributes) : null; }, [ lensAttributes, diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts index 2faf438150c524..0c40ba329eeae4 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts @@ -213,3 +213,26 @@ export const filterNetworkExternalAlertData: Filter[] = [ }, }, ]; + +export const addToCase = async ( + http: HttpSetup, + theCase: Case, + attributes: LensAttributes, + timeRange?: { from: string; to: string }, + owner?: string +) => { + const apiPath = `/api/cases/${theCase?.id}/comments`; + + const vizPayload = { + attributes, + timeRange, + }; + + const payload = { + comment: `!{lens${JSON.stringify(vizPayload)}}`, + type: 'user', + owner: owner ?? 'security_solution', + }; + + return http.post(apiPath, { body: JSON.stringify(payload) }); +}; From 6698b73fdce12b8e5d8f6d24e5fbf1e563baf54f Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Mon, 28 Feb 2022 22:03:39 +0800 Subject: [PATCH 05/59] clean up --- .../components/header_section/index.tsx | 3 +- .../matrix_histogram/histogram_actions.tsx | 144 ++++-------- .../components/matrix_histogram/index.tsx | 13 +- .../matrix_histogram/translations.ts | 7 + .../components/matrix_histogram/types.ts | 8 +- .../use_add_to_existing_case.tsx | 21 +- .../matrix_histogram/use_add_to_new_case.tsx | 114 ++++++++++ .../matrix_histogram/use_lens_attributes.tsx | 39 ++-- .../components/matrix_histogram/utils.ts | 4 +- .../common/components/stat_items/index.tsx | 4 +- .../public/hosts/configs/events.ts | 207 +++++++++--------- .../public/hosts/configs/external_alert.ts | 10 +- .../pages/navigation/dns_query_tab_body.tsx | 1 + 13 files changed, 319 insertions(+), 256 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_new_case.tsx diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx index af09e14631a19c..fc908e69fc8e35 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx @@ -8,10 +8,10 @@ import { EuiFlexGroup, EuiFlexItem, EuiIconTip, EuiTitle, EuiTitleSize } from '@elastic/eui'; import React from 'react'; import styled, { css } from 'styled-components'; -import { TypedLensByValueInput } from '../../../../../lens/public'; import { InspectButton } from '../inspect'; import { HistogramActions } from '../matrix_histogram/histogram_actions'; +import { LensAttributes, GetLensAttributes } from '../matrix_histogram/types'; import { Subtitle } from '../subtitle'; interface HeaderProps { @@ -41,6 +41,7 @@ Header.displayName = 'Header'; export interface HeaderSectionProps extends HeaderProps { children?: React.ReactNode; + getLensAttributes?: GetLensAttributes; growLeftSplit?: boolean; headerFilters?: string | React.ReactNode; height?: number; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx index cd7ea464a8a8d1..690514a45b11d9 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx @@ -8,44 +8,37 @@ import { EuiButtonIcon, EuiContextMenuItem, EuiContextMenuPanel, - EuiFlexGroup, - EuiFlexItem, - EuiLink, EuiPopover, useGeneratedHtmlId, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; -import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; -import { Case, CommentType } from '../../../../../cases/common'; + import { - CasesDeepLinkId, - DRAFT_COMMENT_STORAGE_ID, - generateCaseViewPath, GetAllCasesSelectorModalProps, GetCreateCaseFlyoutProps, } from '../../../../../cases/public'; -import { LensEmbeddableInput, TypedLensByValueInput } from '../../../../../lens/public'; +import { LensEmbeddableInput } from '../../../../../lens/public'; import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; import { InputsModelId } from '../../store/inputs/constants'; import { ModalInspectQuery } from '../inspect/modal'; import { useInspect } from '../inspect/use_inspect'; -import { LensAttributes } from './types'; +import { LensAttributes, GetLensAttributes } from './types'; import { useLensAttributes } from './use_lens_attributes'; import { useAddToExistingCase } from './use_add_to_existing_case'; import { useGetUserCasesPermissions } from '../../lib/kibana'; -import { ADD_TO_CASE_SUCCESS, VIEW_CASE } from './translations'; +import { useAddToNewCase } from './use_add_to_new_case'; export interface HistogramActionsProps { className?: string; - getLensAttributes?: (stackByField?: string) => LensAttributes; + getLensAttributes?: GetLensAttributes; inputId?: InputsModelId; inspectIndex?: number; isInspectButtonDisabled?: boolean; isMultipleQuery?: boolean; - lensAttributes: LensAttributes; + lensAttributes?: LensAttributes | null; onCloseInspect?: () => void; queryId: string; timerange: { from: string; to: string }; @@ -53,7 +46,7 @@ export interface HistogramActionsProps { stackByField?: string; } -const StyledEuiPopover = styled(EuiPopover)` +const Wrapper = styled.div` &.kpi-matrix-histogram-actions { position: absolute; top: 0; @@ -64,19 +57,6 @@ const StyledEuiPopover = styled(EuiPopover)` export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; const owner = APP_ID; -const appId = 'securitySolutionUI'; - -export const CaseToastText = ({ linkUrl }: { linkUrl: string }) => { - return ( - - - - {VIEW_CASE} - - - - ); -}; export const HistogramActions = ({ className, @@ -92,13 +72,7 @@ export const HistogramActions = ({ title, stackByField, }: HistogramActionsProps) => { - const { - lens, - cases, - theme, - application: { getUrlForApp }, - notifications: { toasts }, - } = useKibana().services; + const { lens, cases } = useKibana().services; const userPermissions = useGetUserCasesPermissions(); const userCanCrud = userPermissions?.crud ?? false; @@ -128,9 +102,6 @@ export const HistogramActions = ({ stackByField, }); - const [isCreateCaseFlyoutOpen, setIsCreateCaseFlyoutOpen] = useState(false); - // const [isSaving, setIsSaving] = useState(false); - const { disabled: isAddToCaseDisabled, closeAllCaseModal, @@ -144,40 +115,18 @@ export const HistogramActions = ({ userCanCrud, }); - const onAddToNewCaseClicked = useCallback(() => { - closePopover(); - - setIsCreateCaseFlyoutOpen(true); - }, []); - - const getToastText = useCallback( - (theCase) => - toMountPoint( - , - { theme$: theme?.theme$ } - ), - [getUrlForApp, theme?.theme$] - ); - const onCreateCaseSuccess = useCallback( - async (theCase: Case) => { - setIsCreateCaseFlyoutOpen(false); - toasts.addSuccess( - { - title: ADD_TO_CASE_SUCCESS(theCase.title), - text: getToastText(theCase), - }, - { - toastLifeTimeMs: 10000, - } - ); - }, - [getToastText, toasts] - ); + const { + onClose: closeCreateCaseFlyout, + onSuccess: onCreateCaseSuccess, + attachments: chartAddedToCase, + onAddToNewCaseClicked, + isCreateCaseFlyoutOpen, + } = useAddToNewCase({ + onClick: closePopover, + timeRange: timerange, + lensAttributes: attributes, + userCanCrud, + }); const allCasesSelectorModalProps: GetAllCasesSelectorModalProps = { onRowClick: onCaseClicked, @@ -187,31 +136,20 @@ export const HistogramActions = ({ }; const createCaseFlyoutProps: GetCreateCaseFlyoutProps = useMemo(() => { - const attachments = [ - { - comment: `!{lens${JSON.stringify({ - timeRange: timerange, - attributes, - })}}`, - owner, - type: CommentType.user as const, - }, - ]; return { - // afterCaseCreated: onCaseCreated, - onClose: () => { - setIsCreateCaseFlyoutOpen(false); - }, + onClose: closeCreateCaseFlyout, onSuccess: onCreateCaseSuccess, owner: [owner], userCanCrud, - // features: casesFeatures, - attachments, + attachments: chartAddedToCase, }; - }, [timerange, attributes, onCreateCaseSuccess, userCanCrud]); + }, [closeCreateCaseFlyout, onCreateCaseSuccess, userCanCrud, chartAddedToCase]); const onOpenInLens = useCallback(() => { closePopover(); + if (!timerange || !attributes) { + return; + } navigateToPrefilledEditor( { id: '', @@ -223,10 +161,16 @@ export const HistogramActions = ({ } ); }, [attributes, navigateToPrefilledEditor, timerange]); + + const closeSaveModalVisible = useCallback(() => { + setIsSaveModalVisible(false); + }, []); + const onSaveVisualization = useCallback(() => { setIsSaveModalVisible(true); closePopover(); }, []); + const { additionalRequests, additionalResponses, @@ -249,7 +193,7 @@ export const HistogramActions = ({ const items = [ @@ -260,7 +204,7 @@ export const HistogramActions = ({ , @@ -271,7 +215,7 @@ export const HistogramActions = ({ , @@ -282,7 +226,8 @@ export const HistogramActions = ({ , , + {isSaveModalVisible && ( {}} - onClose={() => setIsSaveModalVisible(false)} + onClose={closeSaveModalVisible} /> )} - - + {isShowingModal && request !== null && response !== null && ( + ); }; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 5355cf4997c629..f1cba6acf6c5c6 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -18,8 +18,13 @@ import { MatrixLoader } from './matrix_loader'; import { Panel } from '../panel'; import { getBarchartConfigs, getCustomChartData } from './utils'; import { useMatrixHistogramCombined } from '../../containers/matrix_histogram'; -import { MatrixHistogramProps, MatrixHistogramOption, MatrixHistogramQueryProps } from './types'; -import { InspectButtonContainer } from '../inspect'; +import { + MatrixHistogramProps, + MatrixHistogramOption, + MatrixHistogramQueryProps, + LensAttributes, + GetLensAttributes, +} from './types'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; import { MatrixHistogramMappingTypes, @@ -29,14 +34,14 @@ import { import { GlobalTimeArgs } from '../../containers/use_global_time'; import { setAbsoluteRangeDatePicker } from '../../store/inputs/actions'; import { InputsModelId } from '../../store/inputs/constants'; -import { HISTOGRAM_ACTIONS_BUTTON_CLASS, LensAttributes } from './histogram_actions'; +import { HISTOGRAM_ACTIONS_BUTTON_CLASS } from './histogram_actions'; import { HoverVisibilityContainer } from '../hover_visibility_container'; export type MatrixHistogramComponentProps = MatrixHistogramProps & Omit & { defaultStackByOption: MatrixHistogramOption; errorMessage: string; - getLensAttributes?: (stackByField?: string) => LensAttributes; + getLensAttributes?: GetLensAttributes; headerChildren?: React.ReactNode; hideHistogramIfEmpty?: boolean; histogramType: MatrixHistogramType; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts index 6a343e61ad7b2d..af9fd37efbb19f 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts @@ -23,6 +23,13 @@ export const ADD_TO_CASE_SUCCESS = (caseTitle: string) => } ); +export const ADD_TO_CASE_FAILURE = i18n.translate( + 'xpack.securitySolution.components.histogramActopms.addToCase.notificationFailure', + { + defaultMessage: 'Failed to add visualization to the selected case.', + } +); + export const VIEW_CASE = i18n.translate( 'xpack.securitySolution.components.histogramActopms.addToCase.notification.viewCase', { diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts index acf6eeec4d1e40..009e99e1df610f 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts @@ -31,14 +31,16 @@ export interface MatrixHistogramOption { export type GetSubTitle = (count: number) => string; export type GetTitle = (matrixHistogramOption: MatrixHistogramOption) => string; +export type LensAttributes = TypedLensByValueInput['attributes']; +export type GetLensAttributes = (stackByField?: string) => LensAttributes; export interface MatrixHistogramConfigs { defaultStackByOption: MatrixHistogramOption; errorMessage: string; - getLensAttributes?: (params: { stackByField?: string }) => TypedLensByValueInput['attributes']; + getLensAttributes?: GetLensAttributes; hideHistogramIfEmpty?: boolean; histogramType: MatrixHistogramType; legendPosition?: Position; - lensAttributes?: TypedLensByValueInput['attributes']; + lensAttributes?: LensAttributes; mapping?: MatrixHistogramMappingTypes; stackByOptions: MatrixHistogramOption[]; subtitle?: string | GetSubTitle; @@ -145,5 +147,3 @@ export interface BarchartConfigs { }; customHeight: number; } - -export type LensAttributes = TypedLensByValueInput['attributes']; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx index 89a62ce3ac889c..75b1cf33b8a08e 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx @@ -5,9 +5,7 @@ * 2.0. */ import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n-react'; -import React, { useCallback, useMemo, useState } from 'react'; -import styled from 'styled-components'; +import React, { useCallback, useState } from 'react'; import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; import { Case } from '../../../../../cases/common'; import { @@ -16,9 +14,8 @@ import { generateCaseViewPath, } from '../../../../../cases/public'; import { APP_ID } from '../../../../common/constants'; -import { useGetUserCasesPermissions } from '../../lib/kibana'; import { useKibana } from '../../lib/kibana/kibana_react'; -import { VIEW_CASE } from './translations'; +import { ADD_TO_CASE_FAILURE, ADD_TO_CASE_SUCCESS, VIEW_CASE } from './translations'; import { LensAttributes } from './types'; import { addToCase } from './utils'; @@ -43,7 +40,7 @@ export const useAddToExistingCase = ({ notifications: { toasts }, storage, theme, - } = useKibana().services; + } = useKibana().services; const [isAllCaseModalOpen, setIsAllCaseModalOpen] = useState(false); const closeAllCaseModal = useCallback(() => { @@ -82,13 +79,11 @@ export const useAddToExistingCase = ({ (theCase?: Case) => { if (theCase && lensAttributes) { setIsAllCaseModalOpen(false); - // setIsSaving(true); addToCase(http, theCase, lensAttributes, timeRange, owner).then( () => { - // setIsSaving(false); toasts.addSuccess( { - title: 'Successfully added visualization to the case: {caseTitle}', + title: ADD_TO_CASE_SUCCESS(theCase.title), text: getToastText(theCase), }, { @@ -98,13 +93,7 @@ export const useAddToExistingCase = ({ }, (error) => { toasts.addError(error, { - // title: i18n.translate( - // 'xpack.observability.expView.heading.addToCase.notification.error', - // { - // defaultMessage: 'Failed to add visualization to the selected case.', - // } - // ), - title: 'Failed to add visualization to the selected case.', + title: ADD_TO_CASE_FAILURE, }); } ); diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_new_case.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_new_case.tsx new file mode 100644 index 00000000000000..f7619b363964e1 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_new_case.tsx @@ -0,0 +1,114 @@ +/* + * 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 { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; +import React, { useCallback, useMemo, useState } from 'react'; +import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; +import { Case, CommentType } from '../../../../../cases/common'; +import { CasesDeepLinkId, generateCaseViewPath } from '../../../../../cases/public'; +import { APP_ID } from '../../../../common/constants'; +import { useKibana } from '../../lib/kibana/kibana_react'; + +import { LensAttributes } from './types'; +import { ADD_TO_CASE_SUCCESS, VIEW_CASE } from './translations'; + +export interface UseAddToNewCaseProps { + onClick?: () => void; + timeRange: { from: string; to: string }; + lensAttributes: LensAttributes | null; + userCanCrud: boolean; +} + +export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; + +const owner = APP_ID; +const appId = 'securitySolutionUI'; + +export const useAddToNewCase = ({ + onClick, + timeRange, + lensAttributes, + userCanCrud, +}: UseAddToNewCaseProps) => { + const { + theme, + application: { getUrlForApp }, + notifications: { toasts }, + } = useKibana().services; + + const [isCreateCaseFlyoutOpen, setIsCreateCaseFlyoutOpen] = useState(false); + + const onAddToNewCaseClicked = useCallback(() => { + if (onClick) { + onClick(); + } + + setIsCreateCaseFlyoutOpen(true); + }, [onClick]); + + const getToastText = useCallback( + (theCase) => + toMountPoint( + + + + {VIEW_CASE} + + + , + { theme$: theme?.theme$ } + ), + [getUrlForApp, theme?.theme$] + ); + + const onCreateCaseSuccess = useCallback( + async (theCase: Case) => { + setIsCreateCaseFlyoutOpen(false); + toasts.addSuccess( + { + title: ADD_TO_CASE_SUCCESS(theCase.title), + text: getToastText(theCase), + }, + { + toastLifeTimeMs: 10000, + } + ); + }, + [getToastText, toasts] + ); + + const attachments = useMemo(() => { + return [ + { + comment: `!{lens${JSON.stringify({ + timeRange, + attributes: lensAttributes, + })}}`, + owner, + type: CommentType.user as const, + }, + ]; + }, [lensAttributes, timeRange]); + + const closeCreateCaseFlyout = useCallback(() => { + setIsCreateCaseFlyoutOpen(false); + }, []); + + return { + onClose: closeCreateCaseFlyout, + onSuccess: onCreateCaseSuccess, + attachments, + onAddToNewCaseClicked, + isCreateCaseFlyoutOpen, + disabled: lensAttributes == null || !userCanCrud, + }; +}; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx index 1b1181f0a941fb..25e1c90de90319 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx @@ -12,7 +12,7 @@ import { NetworkRouteType } from '../../../network/pages/navigation/types'; import { useSourcererDataView } from '../../containers/sourcerer'; import { useDeepEqualSelector } from '../../hooks/use_selector'; import { inputsSelectors } from '../../store'; -import { LensAttributes } from './types'; +import { LensAttributes, GetLensAttributes } from './types'; import { getHostDetailsPageFilter, filterNetworkExternalAlertData, @@ -24,8 +24,8 @@ export const useLensAttributes = ({ getLensAttributes, stackByField, }: { - lensAttributes?: LensAttributes; - getLensAttributes?: (params?: { stackByField?: string }) => LensAttributes; + lensAttributes?: LensAttributes | null; + getLensAttributes?: GetLensAttributes; stackByField?: string; }): LensAttributes | null => { const { dataViewId } = useSourcererDataView(); @@ -65,21 +65,24 @@ export const useLensAttributes = ({ }, [location.pathname, detailName, filters]); const lensAttrsWithInjectedData = useMemo(() => { - const attrs = lensAttributes ?? (getLensAttributes && getLensAttributes({ stackByField })); - return attrs != null - ? ({ - ...attrs, - state: { - ...attrs.state, - query, - filters: [...attrs.state.filters, ...pageFilters, ...tabsFilters], - }, - references: attrs.references.map((ref: { id: string; name: string; type: string }) => ({ - ...ref, - id: dataViewId, - })), - } as LensAttributes) - : null; + if (lensAttributes == null && (getLensAttributes == null || stackByField == null)) { + return null; + } + const attrs: LensAttributes = + lensAttributes ?? + ((getLensAttributes && stackByField && getLensAttributes(stackByField)) as LensAttributes); + return { + ...attrs, + state: { + ...attrs.state, + query, + filters: [...attrs.state.filters, ...pageFilters, ...tabsFilters], + }, + references: attrs.references.map((ref: { id: string; name: string; type: string }) => ({ + ...ref, + id: dataViewId, + })), + } as LensAttributes; }, [ lensAttributes, getLensAttributes, diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts index 0c40ba329eeae4..44f9a5d20d5d2e 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts @@ -9,9 +9,11 @@ import { ScaleType, Position } from '@elastic/charts'; import { get, groupBy, map, toPairs } from 'lodash/fp'; import { UpdateDateRange, ChartSeriesData } from '../charts/common'; -import { MatrixHistogramMappingTypes, BarchartConfigs } from './types'; +import { MatrixHistogramMappingTypes, BarchartConfigs, LensAttributes } from './types'; import { MatrixHistogramData } from '../../../../common/search_strategy'; import { histogramDateTimeFormatter } from '../utils'; +import { HttpSetup } from '../../../../../../../src/core/public'; +import { Case } from '../../../../../cases/common'; interface GetBarchartConfigsProps { chartHeight?: number; diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 8d0bcbab1e00a7..3c463134953158 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -30,13 +30,13 @@ import { ChartSeriesData, ChartData, ChartSeriesConfigs, UpdateDateRange } from import { histogramDateTimeFormatter } from '../utils'; import { getEmptyTagValue } from '../empty_value'; -import { InspectButton, InspectButtonContainer } from '../inspect'; +import { InspectButton } from '../inspect'; import { HistogramActions, HISTOGRAM_ACTIONS_BUTTON_CLASS, - LensAttributes, } from '../matrix_histogram/histogram_actions'; import { HoverVisibilityContainer } from '../hover_visibility_container'; +import { LensAttributes } from '../matrix_histogram/types'; const FlexItem = styled(EuiFlexItem)` min-width: 0; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/events.ts b/x-pack/plugins/security_solution/public/hosts/configs/events.ts index 71acd3eee3da75..eee1b1086b3b8e 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/events.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/events.ts @@ -5,119 +5,118 @@ * 2.0. */ -export const getEventsHistogramCongifs = ({ - stackByField = 'event.action', -}: { - stackByField?: string; -}) => ({ - title: 'Host - events', - description: '', - visualizationType: 'lnsXY', - state: { - visualization: { - title: 'Empty XY chart', - legend: { - isVisible: true, - position: 'right', - }, - valueLabels: 'hide', - preferredSeriesType: 'bar_stacked', - layers: [ - { - layerId: '0039eb0c-9a1a-4687-ae54-0f4e239bec75', - accessors: ['e09e0380-0740-4105-becc-0a4ca12e3944'], - position: 'top', - seriesType: 'bar_stacked', - showGridlines: false, - layerType: 'data', - xAccessor: 'aac9d7d0-13a3-480a-892b-08207a787926', - splitAccessor: '34919782-4546-43a5-b668-06ac934d3acd', +import { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; + +export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'event.action') => + ({ + title: 'Host - events', + description: '', + visualizationType: 'lnsXY', + state: { + visualization: { + title: 'Empty XY chart', + legend: { + isVisible: true, + position: 'right', + }, + valueLabels: 'hide', + preferredSeriesType: 'bar_stacked', + layers: [ + { + layerId: '0039eb0c-9a1a-4687-ae54-0f4e239bec75', + accessors: ['e09e0380-0740-4105-becc-0a4ca12e3944'], + position: 'top', + seriesType: 'bar_stacked', + showGridlines: false, + layerType: 'data', + xAccessor: 'aac9d7d0-13a3-480a-892b-08207a787926', + splitAccessor: '34919782-4546-43a5-b668-06ac934d3acd', + }, + ], + yRightExtent: { + mode: 'full', + }, + yLeftExtent: { + mode: 'full', + }, + axisTitlesVisibilitySettings: { + x: false, + yLeft: false, + yRight: true, }, - ], - yRightExtent: { - mode: 'full', - }, - yLeftExtent: { - mode: 'full', }, - axisTitlesVisibilitySettings: { - x: false, - yLeft: false, - yRight: true, + query: { + query: '', + language: 'kuery', }, - }, - query: { - query: '', - language: 'kuery', - }, - filters: [], - datasourceStates: { - indexpattern: { - layers: { - '0039eb0c-9a1a-4687-ae54-0f4e239bec75': { - columns: { - 'aac9d7d0-13a3-480a-892b-08207a787926': { - label: '@timestamp', - dataType: 'date', - operationType: 'date_histogram', - sourceField: '@timestamp', - isBucketed: true, - scale: 'interval', - params: { - interval: 'auto', - }, - }, - 'e09e0380-0740-4105-becc-0a4ca12e3944': { - label: 'Count of records', - dataType: 'number', - operationType: 'count', - isBucketed: false, - scale: 'ratio', - sourceField: '___records___', - }, - '34919782-4546-43a5-b668-06ac934d3acd': { - label: `Top values of ${stackByField}`, // could be event.dataset or event.module - dataType: 'string', - operationType: 'terms', - scale: 'ordinal', - sourceField: `${stackByField}`, // could be event.dataset or event.module - isBucketed: true, - params: { - size: 10, - orderBy: { - type: 'column', - columnId: 'e09e0380-0740-4105-becc-0a4ca12e3944', + filters: [], + datasourceStates: { + indexpattern: { + layers: { + '0039eb0c-9a1a-4687-ae54-0f4e239bec75': { + columns: { + 'aac9d7d0-13a3-480a-892b-08207a787926': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { + interval: 'auto', }, - orderDirection: 'desc', - otherBucket: true, - missingBucket: false, - parentFormat: { - id: 'terms', + }, + 'e09e0380-0740-4105-becc-0a4ca12e3944': { + label: 'Count of records', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + }, + '34919782-4546-43a5-b668-06ac934d3acd': { + label: `Top values of ${stackByField}`, // could be event.dataset or event.module + dataType: 'string', + operationType: 'terms', + scale: 'ordinal', + sourceField: `${stackByField}`, // could be event.dataset or event.module + isBucketed: true, + params: { + size: 10, + orderBy: { + type: 'column', + columnId: 'e09e0380-0740-4105-becc-0a4ca12e3944', + }, + orderDirection: 'desc', + otherBucket: true, + missingBucket: false, + parentFormat: { + id: 'terms', + }, }, }, }, + columnOrder: [ + '34919782-4546-43a5-b668-06ac934d3acd', + 'aac9d7d0-13a3-480a-892b-08207a787926', + 'e09e0380-0740-4105-becc-0a4ca12e3944', + ], + incompleteColumns: {}, }, - columnOrder: [ - '34919782-4546-43a5-b668-06ac934d3acd', - 'aac9d7d0-13a3-480a-892b-08207a787926', - 'e09e0380-0740-4105-becc-0a4ca12e3944', - ], - incompleteColumns: {}, }, }, }, }, - }, - references: [ - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-current-indexpattern', - }, - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-layer-0039eb0c-9a1a-4687-ae54-0f4e239bec75', - }, - ], -}); + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-0039eb0c-9a1a-4687-ae54-0f4e239bec75', + }, + ], + } as LensAttributes); diff --git a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts index 8c5fd3dfeca560..555b8133a8479a 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts @@ -5,11 +5,9 @@ * 2.0. */ -export const getExternalAlertConfigs = ({ - stackByField = 'event.module', -}: { - stackByField?: string; -}) => { +import { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; + +export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event.module') => { return { title: 'external alerts', description: '', @@ -148,5 +146,5 @@ export const getExternalAlertConfigs = ({ id: 'security-solution-default', }, ], - }; + } as LensAttributes; }; diff --git a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx index 99361722bafde5..e241f3c5ed2faa 100644 --- a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx @@ -23,6 +23,7 @@ import { MatrixHistogram } from '../../../common/components/matrix_histogram'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; import { networkSelectors } from '../../store'; import { useShallowEqualSelector } from '../../../common/hooks/use_selector'; +import { dnsTopDomainsAttrs } from '../../configs/dns_top_domains'; const HISTOGRAM_ID = 'networkDnsHistogramQuery'; From e6664882d61ab1313e06aa6cb8cf0f727d68f591 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 1 Mar 2022 01:33:33 +0800 Subject: [PATCH 06/59] clean up --- .../common/components/charts/areachart.tsx | 8 +- .../common/components/charts/barchart.tsx | 7 +- .../components/header_section/index.tsx | 4 +- .../components/matrix_histogram/index.tsx | 11 +- .../matrix_histogram/translations.ts | 23 --- .../components/matrix_histogram/types.ts | 4 +- .../components/matrix_histogram/utils.ts | 27 +--- .../common/components/stat_items/index.tsx | 7 +- .../index.tsx} | 18 +-- .../visualization_actions/toast_text.tsx | 29 ++++ .../visualization_actions/translations.ts | 31 ++++ .../components/visualization_actions/types.ts | 27 ++++ .../use_add_to_existing_case.tsx | 26 ++-- .../use_add_to_new_case.tsx | 30 ++-- .../use_lens_attributes.tsx | 0 .../components/visualization_actions/utils.ts | 142 ++++++++++++++++++ 16 files changed, 265 insertions(+), 129 deletions(-) rename x-pack/plugins/security_solution/public/common/components/{matrix_histogram/histogram_actions.tsx => visualization_actions/index.tsx} (93%) create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts rename x-pack/plugins/security_solution/public/common/components/{matrix_histogram => visualization_actions}/use_add_to_existing_case.tsx (84%) rename x-pack/plugins/security_solution/public/common/components/{matrix_histogram => visualization_actions}/use_add_to_new_case.tsx (80%) rename x-pack/plugins/security_solution/public/common/components/{matrix_histogram => visualization_actions}/use_lens_attributes.tsx (100%) create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index 9d51906eaafe82..61ecab5c132d2e 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -33,11 +33,9 @@ import { useTheme, Wrapper, } from './common'; -import { - HistogramActions, - HistogramActionsProps, - HISTOGRAM_ACTIONS_BUTTON_CLASS, -} from '../matrix_histogram/histogram_actions'; +import { HistogramActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; +import { HistogramActionsProps } from '../visualization_actions/types'; + import { HoverVisibilityContainer } from '../hover_visibility_container'; // custom series styles: https://ela.st/areachart-styling diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index 3c0c6ee8f8211b..f03c580db72d20 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -36,11 +36,8 @@ import { import { DraggableLegend } from './draggable_legend'; import { LegendItem } from './draggable_legend_item'; import type { ChartData } from './common'; -import { - HistogramActions, - HistogramActionsProps, - HISTOGRAM_ACTIONS_BUTTON_CLASS, -} from '../matrix_histogram/histogram_actions'; +import { HistogramActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; +import { HistogramActionsProps } from '../visualization_actions/types'; import { HoverVisibilityContainer } from '../hover_visibility_container'; const LegendFlexItem = styled(EuiFlexItem)` diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx index fc908e69fc8e35..843182d4ac9a3e 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx @@ -10,8 +10,8 @@ import React from 'react'; import styled, { css } from 'styled-components'; import { InspectButton } from '../inspect'; -import { HistogramActions } from '../matrix_histogram/histogram_actions'; -import { LensAttributes, GetLensAttributes } from '../matrix_histogram/types'; +import { HistogramActions } from '../visualization_actions'; +import { LensAttributes, GetLensAttributes } from '../visualization_actions/types'; import { Subtitle } from '../subtitle'; interface HeaderProps { diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index f1cba6acf6c5c6..7c6a70089db0c7 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -18,13 +18,7 @@ import { MatrixLoader } from './matrix_loader'; import { Panel } from '../panel'; import { getBarchartConfigs, getCustomChartData } from './utils'; import { useMatrixHistogramCombined } from '../../containers/matrix_histogram'; -import { - MatrixHistogramProps, - MatrixHistogramOption, - MatrixHistogramQueryProps, - LensAttributes, - GetLensAttributes, -} from './types'; +import { MatrixHistogramProps, MatrixHistogramOption, MatrixHistogramQueryProps } from './types'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; import { MatrixHistogramMappingTypes, @@ -34,8 +28,9 @@ import { import { GlobalTimeArgs } from '../../containers/use_global_time'; import { setAbsoluteRangeDatePicker } from '../../store/inputs/actions'; import { InputsModelId } from '../../store/inputs/constants'; -import { HISTOGRAM_ACTIONS_BUTTON_CLASS } from './histogram_actions'; import { HoverVisibilityContainer } from '../hover_visibility_container'; +import { HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; +import { GetLensAttributes, LensAttributes } from '../visualization_actions/types'; export type MatrixHistogramComponentProps = MatrixHistogramProps & Omit & { diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts index af9fd37efbb19f..fe7ac760950bc5 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/translations.ts @@ -13,26 +13,3 @@ export const STACK_BY = i18n.translate( defaultMessage: 'Stack by', } ); - -export const ADD_TO_CASE_SUCCESS = (caseTitle: string) => - i18n.translate( - 'xpack.securitySolution.components.histogramActopms.addToCase.notificationSuccess', - { - defaultMessage: 'Successfully added visualization to the case: {caseTitle}', - values: { caseTitle }, - } - ); - -export const ADD_TO_CASE_FAILURE = i18n.translate( - 'xpack.securitySolution.components.histogramActopms.addToCase.notificationFailure', - { - defaultMessage: 'Failed to add visualization to the selected case.', - } -); - -export const VIEW_CASE = i18n.translate( - 'xpack.securitySolution.components.histogramActopms.addToCase.notification.viewCase', - { - defaultMessage: 'View case', - } -); diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts index 009e99e1df610f..d73a543de50fd6 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/types.ts @@ -17,7 +17,7 @@ import { UpdateDateRange } from '../charts/common'; import { GlobalTimeArgs } from '../../containers/use_global_time'; import { DocValueFields } from '../../../../common/search_strategy'; import { FieldValueThreshold } from '../../../detections/components/rules/threshold_input'; -import { TypedLensByValueInput } from '../../../../../lens/public'; +import { GetLensAttributes, LensAttributes } from '../visualization_actions/types'; export type MatrixHistogramMappingTypes = Record< string, @@ -31,8 +31,6 @@ export interface MatrixHistogramOption { export type GetSubTitle = (count: number) => string; export type GetTitle = (matrixHistogramOption: MatrixHistogramOption) => string; -export type LensAttributes = TypedLensByValueInput['attributes']; -export type GetLensAttributes = (stackByField?: string) => LensAttributes; export interface MatrixHistogramConfigs { defaultStackByOption: MatrixHistogramOption; errorMessage: string; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts index 44f9a5d20d5d2e..2faf438150c524 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts @@ -9,11 +9,9 @@ import { ScaleType, Position } from '@elastic/charts'; import { get, groupBy, map, toPairs } from 'lodash/fp'; import { UpdateDateRange, ChartSeriesData } from '../charts/common'; -import { MatrixHistogramMappingTypes, BarchartConfigs, LensAttributes } from './types'; +import { MatrixHistogramMappingTypes, BarchartConfigs } from './types'; import { MatrixHistogramData } from '../../../../common/search_strategy'; import { histogramDateTimeFormatter } from '../utils'; -import { HttpSetup } from '../../../../../../../src/core/public'; -import { Case } from '../../../../../cases/common'; interface GetBarchartConfigsProps { chartHeight?: number; @@ -215,26 +213,3 @@ export const filterNetworkExternalAlertData: Filter[] = [ }, }, ]; - -export const addToCase = async ( - http: HttpSetup, - theCase: Case, - attributes: LensAttributes, - timeRange?: { from: string; to: string }, - owner?: string -) => { - const apiPath = `/api/cases/${theCase?.id}/comments`; - - const vizPayload = { - attributes, - timeRange, - }; - - const payload = { - comment: `!{lens${JSON.stringify(vizPayload)}}`, - type: 'user', - owner: owner ?? 'security_solution', - }; - - return http.post(apiPath, { body: JSON.stringify(payload) }); -}; diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 3c463134953158..a1dc0da94a634c 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -31,12 +31,9 @@ import { histogramDateTimeFormatter } from '../utils'; import { getEmptyTagValue } from '../empty_value'; import { InspectButton } from '../inspect'; -import { - HistogramActions, - HISTOGRAM_ACTIONS_BUTTON_CLASS, -} from '../matrix_histogram/histogram_actions'; +import { HistogramActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; import { HoverVisibilityContainer } from '../hover_visibility_container'; -import { LensAttributes } from '../matrix_histogram/types'; +import { LensAttributes } from '../visualization_actions/types'; const FlexItem = styled(EuiFlexItem)` min-width: 0; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx similarity index 93% rename from x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 690514a45b11d9..95ec12c53e260f 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/histogram_actions.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -22,29 +22,13 @@ import { import { LensEmbeddableInput } from '../../../../../lens/public'; import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; - -import { InputsModelId } from '../../store/inputs/constants'; import { ModalInspectQuery } from '../inspect/modal'; + import { useInspect } from '../inspect/use_inspect'; -import { LensAttributes, GetLensAttributes } from './types'; import { useLensAttributes } from './use_lens_attributes'; import { useAddToExistingCase } from './use_add_to_existing_case'; import { useGetUserCasesPermissions } from '../../lib/kibana'; import { useAddToNewCase } from './use_add_to_new_case'; -export interface HistogramActionsProps { - className?: string; - getLensAttributes?: GetLensAttributes; - inputId?: InputsModelId; - inspectIndex?: number; - isInspectButtonDisabled?: boolean; - isMultipleQuery?: boolean; - lensAttributes?: LensAttributes | null; - onCloseInspect?: () => void; - queryId: string; - timerange: { from: string; to: string }; - title: React.ReactNode; - stackByField?: string; -} const Wrapper = styled.div` &.kpi-matrix-histogram-actions { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx new file mode 100644 index 00000000000000..9bb0875664aabf --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx @@ -0,0 +1,29 @@ +/* + * 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 { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; + +import { VIEW_CASE } from './translations'; + +interface ToaseTextProps { + caseId: string; + href: string; +} + +const ToaseTextComponent: React.FC = ({ caseId, href }) => { + return ( + + + + {VIEW_CASE} + + + + ); +}; +ToaseTextComponent.displayName = 'ToaseTextComponent'; +export const ToaseText = React.memo(ToaseTextComponent); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts new file mode 100644 index 00000000000000..06109a09eb62e9 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts @@ -0,0 +1,31 @@ +/* + * 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 ADD_TO_CASE_SUCCESS = (caseTitle: string) => + i18n.translate( + 'xpack.securitySolution.components.histogramActopms.addToCase.notificationSuccess', + { + defaultMessage: 'Successfully added visualization to the case: {caseTitle}', + values: { caseTitle }, + } + ); + +export const ADD_TO_CASE_FAILURE = i18n.translate( + 'xpack.securitySolution.components.histogramActopms.addToCase.notificationFailure', + { + defaultMessage: 'Failed to add visualization to the selected case.', + } +); + +export const VIEW_CASE = i18n.translate( + 'xpack.securitySolution.components.histogramActopms.addToCase.notification.viewCase', + { + defaultMessage: 'View case', + } +); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts new file mode 100644 index 00000000000000..4b87d8da3c6f92 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts @@ -0,0 +1,27 @@ +/* + * 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 { TypedLensByValueInput } from '../../../../../lens/public'; +import { InputsModelId } from '../../store/inputs/constants'; + +export type LensAttributes = TypedLensByValueInput['attributes']; +export type GetLensAttributes = (stackByField?: string) => LensAttributes; + +export interface HistogramActionsProps { + className?: string; + getLensAttributes?: GetLensAttributes; + inputId?: InputsModelId; + inspectIndex?: number; + isInspectButtonDisabled?: boolean; + isMultipleQuery?: boolean; + lensAttributes?: LensAttributes | null; + onCloseInspect?: () => void; + queryId: string; + timerange: { from: string; to: string }; + title: React.ReactNode; + stackByField?: string; +} diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx similarity index 84% rename from x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx index 75b1cf33b8a08e..3696188dc4ec07 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_existing_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx @@ -4,7 +4,6 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; import React, { useCallback, useState } from 'react'; import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; import { Case } from '../../../../../cases/common'; @@ -15,10 +14,11 @@ import { } from '../../../../../cases/public'; import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; -import { ADD_TO_CASE_FAILURE, ADD_TO_CASE_SUCCESS, VIEW_CASE } from './translations'; +import { ADD_TO_CASE_FAILURE, ADD_TO_CASE_SUCCESS } from './translations'; import { LensAttributes } from './types'; import { addToCase } from './utils'; +import { ToaseText } from './toast_text'; const appId = 'securitySolutionUI'; const owner = APP_ID; @@ -55,21 +55,15 @@ export const useAddToExistingCase = ({ }, [onAddToCaseClicked]); const getToastText = useCallback( - (theCase) => + (theCase: Case) => toMountPoint( - - - - {VIEW_CASE} - - - , + , { theme$: theme?.theme$ } ), [getUrlForApp, theme?.theme$] diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_new_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx similarity index 80% rename from x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_new_case.tsx rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx index f7619b363964e1..da530aa1731d85 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_add_to_new_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx @@ -4,16 +4,16 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; import React, { useCallback, useMemo, useState } from 'react'; import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; import { Case, CommentType } from '../../../../../cases/common'; -import { CasesDeepLinkId, generateCaseViewPath } from '../../../../../cases/public'; import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; import { LensAttributes } from './types'; -import { ADD_TO_CASE_SUCCESS, VIEW_CASE } from './translations'; +import { ADD_TO_CASE_SUCCESS } from './translations'; +import { CasesDeepLinkId, generateCaseViewPath } from '../../../../../cases/public'; +import { ToaseText } from './toast_text'; export interface UseAddToNewCaseProps { onClick?: () => void; @@ -22,8 +22,6 @@ export interface UseAddToNewCaseProps { userCanCrud: boolean; } -export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; - const owner = APP_ID; const appId = 'securitySolutionUI'; @@ -35,8 +33,8 @@ export const useAddToNewCase = ({ }: UseAddToNewCaseProps) => { const { theme, - application: { getUrlForApp }, notifications: { toasts }, + application: { getUrlForApp }, } = useKibana().services; const [isCreateCaseFlyoutOpen, setIsCreateCaseFlyoutOpen] = useState(false); @@ -52,19 +50,13 @@ export const useAddToNewCase = ({ const getToastText = useCallback( (theCase) => toMountPoint( - - - - {VIEW_CASE} - - - , + , { theme$: theme?.theme$ } ), [getUrlForApp, theme?.theme$] diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx similarity index 100% rename from x-pack/plugins/security_solution/public/common/components/matrix_histogram/use_lens_attributes.tsx rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts new file mode 100644 index 00000000000000..9f86ece7dd7e40 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts @@ -0,0 +1,142 @@ +/* + * 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 { Filter } from '@kbn/es-query'; +import { LensAttributes } from './types'; + +import { HttpSetup } from '../../../../../../../src/core/public'; +import { Case } from '../../../../../cases/common'; + +export const getHostDetailsPageFilter = (hostName?: string): Filter[] => + hostName + ? [ + { + meta: { + index: 'e5bb994d-e8fb-4ddb-a36e-730ad8cc0712', + alias: null, + negate: false, + disabled: false, + type: 'phrase', + key: 'host.name', + params: { + query: hostName, + }, + }, + query: { + match_phrase: { + 'host.name': hostName, + }, + }, + }, + ] + : []; + +export const filterHostExternalAlertData: Filter[] = [ + { + query: { + bool: { + filter: [ + { + bool: { + should: [ + { + exists: { + field: 'host.name', + }, + }, + ], + minimum_should_match: 1, + }, + }, + ], + }, + }, + meta: { + alias: '', + disabled: false, + key: 'bool', + negate: false, + type: 'custom', + value: + '{"query": {"bool": {"filter": [{"bool": {"should": [{"exists": {"field": "host.name"}}],"minimum_should_match": 1}}]}}}', + }, + }, +]; + +export const filterNetworkExternalAlertData: Filter[] = [ + { + query: { + bool: { + filter: [ + { + bool: { + should: [ + { + bool: { + should: [ + { + exists: { + field: 'source.ip', + }, + }, + ], + minimum_should_match: 1, + }, + }, + { + bool: { + should: [ + { + exists: { + field: 'destination.ip', + }, + }, + ], + minimum_should_match: 1, + }, + }, + ], + minimum_should_match: 1, + }, + }, + ], + }, + }, + meta: { + alias: '', + disabled: false, + key: 'bool', + negate: false, + type: 'custom', + value: + '{"bool":{"filter":[{"bool":{"should":[{"bool":{"should":[{"exists":{"field": "source.ip"}}],"minimum_should_match":1}},{"bool":{"should":[{"exists":{"field": "destination.ip"}}],"minimum_should_match":1}}],"minimum_should_match":1}}]}}', + }, + }, +]; + +export const addToCase = async ( + http: HttpSetup, + theCase: Case, + attributes: LensAttributes, + timeRange?: { from: string; to: string }, + owner?: string +) => { + const apiPath = `/api/cases/${theCase?.id}/comments`; + + const vizPayload = { + attributes, + timeRange, + }; + + const payload = { + comment: `!{lens${JSON.stringify(vizPayload)}}`, + type: 'user', + owner: owner ?? 'security_solution', + }; + + return http.post(apiPath, { body: JSON.stringify(payload) }); +}; From b951e07f2019b623c5bd67d0e573221a65c50947 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 1 Mar 2022 03:25:21 +0800 Subject: [PATCH 07/59] clean up configs --- .../components/matrix_histogram/utils.ts | 107 ------------------ .../public/hosts/configs/authentication.ts | 2 +- .../public/hosts/configs/events.ts | 5 +- .../public/hosts/configs/external_alert.ts | 5 +- .../public/hosts/configs/kpi_host_area.ts | 2 +- .../public/hosts/configs/kpi_host_metric.ts | 2 +- .../hosts/configs/kpi_unique_ips-area.ts | 2 +- .../hosts/configs/kpi_unique_ips-bar.ts | 2 +- .../kpi_unique_ips-destination_metric.ts | 2 +- .../configs/kpi_unique_ips-source_metric.ts | 2 +- .../kpi_user_authentication_metric_failure.ts | 2 +- ...kpi_user_authentications-metric_success.ts | 2 +- .../configs/kpi_user_authentications_area.ts | 2 +- .../configs/kpi_user_authentications_bar.ts | 2 +- .../public/network/configs/dns_top_domains.ts | 2 +- .../public/network/configs/kpi_dns_queries.ts | 2 +- .../network/configs/kpi_network_events.ts | 2 +- .../network/configs/kpi_tls_handshakes.ts | 2 +- .../network/configs/kpi_unique_flow_ids.ts | 2 +- .../configs/kpi_unique_private_ips-area.ts | 2 +- .../configs/kpi_unique_private_ips-bar.ts | 2 +- ...i_unique_private_ips-destination_metric.ts | 2 +- .../kpi_unique_private_ips-source_metric.ts | 2 +- 23 files changed, 28 insertions(+), 129 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts index 2faf438150c524..6594dc30d5ce81 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/utils.ts @@ -106,110 +106,3 @@ export const getCustomChartData = ( return { ...item, color: mapItem?.color ?? defaultLegendColors[idx] }; }); }; - -export const getHostDetailsPageFilter = (hostName?: string): Filter[] => - hostName - ? [ - { - meta: { - index: 'e5bb994d-e8fb-4ddb-a36e-730ad8cc0712', - alias: null, - negate: false, - disabled: false, - type: 'phrase', - key: 'host.name', - params: { - query: hostName, - }, - }, - query: { - match_phrase: { - 'host.name': hostName, - }, - }, - }, - ] - : []; - -export const filterHostExternalAlertData: Filter[] = [ - { - query: { - bool: { - filter: [ - { - bool: { - should: [ - { - exists: { - field: 'host.name', - }, - }, - ], - minimum_should_match: 1, - }, - }, - ], - }, - }, - meta: { - alias: '', - disabled: false, - key: 'bool', - negate: false, - type: 'custom', - value: - '{"query": {"bool": {"filter": [{"bool": {"should": [{"exists": {"field": "host.name"}}],"minimum_should_match": 1}}]}}}', - }, - }, -]; - -export const filterNetworkExternalAlertData: Filter[] = [ - { - query: { - bool: { - filter: [ - { - bool: { - should: [ - { - bool: { - should: [ - { - exists: { - field: 'source.ip', - }, - }, - ], - minimum_should_match: 1, - }, - }, - { - bool: { - should: [ - { - exists: { - field: 'destination.ip', - }, - }, - ], - minimum_should_match: 1, - }, - }, - ], - minimum_should_match: 1, - }, - }, - ], - }, - }, - meta: { - alias: '', - disabled: false, - key: 'bool', - negate: false, - type: 'custom', - value: - '{"bool":{"filter":[{"bool":{"should":[{"bool":{"should":[{"exists":{"field": "source.ip"}}],"minimum_should_match":1}},{"bool":{"should":[{"exists":{"field": "destination.ip"}}],"minimum_should_match":1}}],"minimum_should_match":1}}]}}', - }, - }, -]; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts b/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts index aba4ffe9f39412..839756b2e7eb97 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const authentication: LensAttributes = { title: 'Authentication', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/events.ts b/x-pack/plugins/security_solution/public/hosts/configs/events.ts index eee1b1086b3b8e..c5ff8c02d74766 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/events.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/events.ts @@ -5,7 +5,10 @@ * 2.0. */ -import { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; +import { + GetLensAttributes, + LensAttributes, +} from '../../common/components/visualization_actions/types'; export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'event.action') => ({ diff --git a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts index 555b8133a8479a..520a5fcb2465b5 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts @@ -5,7 +5,10 @@ * 2.0. */ -import { LensAttributes, GetLensAttributes } from '../../common/components/matrix_histogram/types'; +import { + GetLensAttributes, + LensAttributes, +} from '../../common/components/visualization_actions/types'; export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event.module') => { return { diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts index 21aed9ea7b4e99..17167b4ed88b82 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiHostArea: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts index 6e42a0fac4ee4b..3cc50c9ac6a18a 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiHostMetric: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts index f1bce738e3fb74..0de00f856f3816 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; import { DESTINATION_CHART_LABEL, SOURCE_CHART_LABEL, diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts index 065ce05957c45f..a9ce0c5788063a 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; import { SOURCE_CHART_LABEL, DESTINATION_CHART_LABEL, diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts index 4a87e1afed709f..543d21c6ae8caf 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUniqueIpsDestinationMetric: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts index 1375587ef1c9a8..07af9ef38091d3 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUniqueIpsSourceMetric: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts index be400c9d7684f1..622a78515eb13c 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUserAuthenticationsMetricFailure: LensAttributes = { title: '[Host] KPI User authentications - metric failure ', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts index 29263bc1148ef4..997d63d8834e42 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUserAuthenticationsMetricSuccess: LensAttributes = { title: '[Host] KPI User authentications - metric success ', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts index 529a0c40a80e4b..481dd75cb69cd8 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUserAuthenticationsArea: LensAttributes = { title: '[Host] KPI User authentications - area ', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts index a59e9ca7558357..c8c1a466ce07d0 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts +++ b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; import { FAIL_CHART_LABEL, SUCCESS_CHART_LABEL, diff --git a/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts b/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts index 96b5c9246a7279..452fe7cf32f29e 100644 --- a/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts +++ b/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; /* Exported from Kibana Saved Object */ export const dnsTopDomainsAttrs: LensAttributes = { diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts index ef1b92ed2bbd8b..012ba2c2015284 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiDnsQueries: LensAttributes = { title: '[Network] KPI Unique private IPs - source metric', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts index 5a9f3b4937527d..a79fd529a03ad7 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiNetworkEvents: LensAttributes = { title: '[Network] KPI Network events', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts index 5e5d476fe51ccf..d5f2929941a1df 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiTlsHandshakes: LensAttributes = { title: '[Network] KPI TLS handshakes', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts index 7df97d6420e119..8db0e884f05824 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUniqueFlowIds: LensAttributes = { title: '[Network] KPI Unique flow IDs', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts index f07b0233e45175..4e76ea3facb1e6 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUniquePrivateIpsArea: LensAttributes = { title: '[Network] KPI Unique private IPs - area chart', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts index f36dcaee6e78b6..290aa2344935d9 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts @@ -9,7 +9,7 @@ import { SOURCE_CHART_LABEL, DESTINATION_CHART_LABEL, } from '../components/kpi_network/unique_private_ips/translations'; -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUniquePrivateIpsBar = { title: '[Network] KPI Unique private IPs - bar chart', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts index 258b4a5c315fd2..7fb5b439faede3 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUniquePrivateIpsDestinationMetric = { description: '', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts index 4bc70224430c8c..751dee806789bc 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LensAttributes } from '../../common/components/matrix_histogram/types'; +import { LensAttributes } from '../../common/components/visualization_actions/types'; export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { description: '', From 753e0d69e8dae66e560789ca4592aec76b6994f1 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 1 Mar 2022 18:12:31 +0800 Subject: [PATCH 08/59] rename configs --- .../hosts/components/kpi_hosts/unique_ips/index.tsx | 8 ++++---- .../{kpi_unique_ips-area.ts => kpi_unique_ips_area.ts} | 0 .../{kpi_unique_ips-bar.ts => kpi_unique_ips_bar.ts} | 0 ...ion_metric.ts => kpi_unique_ips_destination_metric.ts} | 0 ...s-source_metric.ts => kpi_unique_ips_source_metric.ts} | 0 .../components/kpi_network/unique_private_ips/index.tsx | 8 ++++---- ...private_ips-area.ts => kpi_unique_private_ips_area.ts} | 0 ...e_private_ips-bar.ts => kpi_unique_private_ips_bar.ts} | 0 ...ic.ts => kpi_unique_private_ips_destination_metric.ts} | 0 ..._metric.ts => kpi_unique_private_ips_source_metric.ts} | 0 10 files changed, 8 insertions(+), 8 deletions(-) rename x-pack/plugins/security_solution/public/hosts/configs/{kpi_unique_ips-area.ts => kpi_unique_ips_area.ts} (100%) rename x-pack/plugins/security_solution/public/hosts/configs/{kpi_unique_ips-bar.ts => kpi_unique_ips_bar.ts} (100%) rename x-pack/plugins/security_solution/public/hosts/configs/{kpi_unique_ips-destination_metric.ts => kpi_unique_ips_destination_metric.ts} (100%) rename x-pack/plugins/security_solution/public/hosts/configs/{kpi_unique_ips-source_metric.ts => kpi_unique_ips_source_metric.ts} (100%) rename x-pack/plugins/security_solution/public/network/configs/{kpi_unique_private_ips-area.ts => kpi_unique_private_ips_area.ts} (100%) rename x-pack/plugins/security_solution/public/network/configs/{kpi_unique_private_ips-bar.ts => kpi_unique_private_ips_bar.ts} (100%) rename x-pack/plugins/security_solution/public/network/configs/{kpi_unique_private_ips-destination_metric.ts => kpi_unique_private_ips_destination_metric.ts} (100%) rename x-pack/plugins/security_solution/public/network/configs/{kpi_unique_private_ips-source_metric.ts => kpi_unique_private_ips_source_metric.ts} (100%) diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx index efc873f096402c..e1a0676edcd314 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx @@ -8,10 +8,10 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUniqueIpsArea } from '../../../configs/kpi_unique_ips-area'; -import { kpiUniqueIpsBar } from '../../../configs/kpi_unique_ips-bar'; -import { kpiUniqueIpsDestinationMetric } from '../../../configs/kpi_unique_ips-destination_metric'; -import { kpiUniqueIpsSourceMetric } from '../../../configs/kpi_unique_ips-source_metric'; +import { kpiUniqueIpsArea } from '../../../configs/kpi_unique_ips_area'; +import { kpiUniqueIpsBar } from '../../../configs/kpi_unique_ips_bar'; +import { kpiUniqueIpsDestinationMetric } from '../../../configs/kpi_unique_ips_destination_metric'; +import { kpiUniqueIpsSourceMetric } from '../../../configs/kpi_unique_ips_source_metric'; import { useHostsKpiUniqueIps } from '../../../containers/kpi_hosts/unique_ips'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_area.ts similarity index 100% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-area.ts rename to x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_area.ts diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_bar.ts similarity index 100% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-bar.ts rename to x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_bar.ts diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_destination_metric.ts similarity index 100% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-destination_metric.ts rename to x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_destination_metric.ts diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_source_metric.ts similarity index 100% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips-source_metric.ts rename to x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_source_metric.ts diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx index bffd3f069b1486..7b256177313da6 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx @@ -13,10 +13,10 @@ import { useNetworkKpiUniquePrivateIps } from '../../../containers/kpi_network/u import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; import * as i18n from './translations'; -import { kpiUniquePrivateIpsSourceMetric } from '../../../configs/kpi_unique_private_ips-source_metric'; -import { kpiUniquePrivateIpsDestinationMetric } from '../../../configs/kpi_unique_private_ips-destination_metric'; -import { kpiUniquePrivateIpsArea } from '../../../configs/kpi_unique_private_ips-area'; -import { kpiUniquePrivateIpsBar } from '../../../configs/kpi_unique_private_ips-bar'; +import { kpiUniquePrivateIpsSourceMetric } from '../../../configs/kpi_unique_private_ips_source_metric'; +import { kpiUniquePrivateIpsDestinationMetric } from '../../../configs/kpi_unique_private_ips_destination_metric'; +import { kpiUniquePrivateIpsArea } from '../../../configs/kpi_unique_private_ips_area'; +import { kpiUniquePrivateIpsBar } from '../../../configs/kpi_unique_private_ips_bar'; const euiVisColorPalette = euiPaletteColorBlind(); const euiColorVis2 = euiVisColorPalette[2]; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_area.ts similarity index 100% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-area.ts rename to x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_area.ts diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_bar.ts similarity index 100% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-bar.ts rename to x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_bar.ts diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts similarity index 100% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-destination_metric.ts rename to x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_source_metric.ts similarity index 100% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips-source_metric.ts rename to x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_source_metric.ts From 743565211a3b01fbff29d3ce34b7809ab1b28285 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 1 Mar 2022 18:44:27 +0800 Subject: [PATCH 09/59] rename histogram actions to viz actions component --- .../public/common/components/charts/areachart.tsx | 7 +++++-- .../public/common/components/charts/barchart.tsx | 7 +++++-- .../public/common/components/header_section/index.tsx | 4 ++-- .../public/common/components/stat_items/index.tsx | 4 ++-- .../common/components/visualization_actions/index.tsx | 8 ++++++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index 61ecab5c132d2e..fff24991e43982 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -33,7 +33,7 @@ import { useTheme, Wrapper, } from './common'; -import { HistogramActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; +import { VisualizationActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; import { HistogramActionsProps } from '../visualization_actions/types'; import { HoverVisibilityContainer } from '../hover_visibility_container'; @@ -181,7 +181,10 @@ export const AreaChartComponent: React.FC = ({ {!isVlidSeriesExist && ( )} - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index f03c580db72d20..baa0fd867739f8 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -36,7 +36,7 @@ import { import { DraggableLegend } from './draggable_legend'; import { LegendItem } from './draggable_legend_item'; import type { ChartData } from './common'; -import { HistogramActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; +import { VisualizationActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; import { HistogramActionsProps } from '../visualization_actions/types'; import { HoverVisibilityContainer } from '../hover_visibility_container'; @@ -211,7 +211,10 @@ export const BarChartComponent: React.FC = ({ )} {histogramActionsOptions?.lensAttributes && histogramActionsOptions?.timerange && ( - + )} diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx index 843182d4ac9a3e..7fd5bb504561e5 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx @@ -10,7 +10,7 @@ import React from 'react'; import styled, { css } from 'styled-components'; import { InspectButton } from '../inspect'; -import { HistogramActions } from '../visualization_actions'; +import { VisualizationActions } from '../visualization_actions'; import { LensAttributes, GetLensAttributes } from '../visualization_actions/types'; import { Subtitle } from '../subtitle'; @@ -123,7 +123,7 @@ const HeaderSectionComponent: React.FC = ({ )} {(getLensAttributes || lensAttributes) && timerange && ( - (

{field.lensAttributes && timerange && ( - = ({ className, getLensAttributes, inputId = 'global', @@ -55,7 +56,7 @@ export const HistogramActions = ({ timerange, title, stackByField, -}: HistogramActionsProps) => { +}) => { const { lens, cases } = useKibana().services; const userPermissions = useGetUserCasesPermissions(); const userCanCrud = userPermissions?.crud ?? false; @@ -276,3 +277,6 @@ export const HistogramActions = ({ ); }; + +VisualizationActionsComponent.displayName = 'VisualizationActionsComponent'; +export const VisualizationActions = React.memo(VisualizationActionsComponent); From 32d9c80d9094516c193646189995bf225f0e8614 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 1 Mar 2022 18:47:19 +0800 Subject: [PATCH 10/59] fix up --- .../public/common/components/charts/areachart.tsx | 8 ++++---- .../public/common/components/charts/barchart.tsx | 10 +++++----- .../public/common/components/stat_items/index.tsx | 4 ++-- .../common/components/visualization_actions/index.tsx | 4 ++-- .../common/components/visualization_actions/types.ts | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index fff24991e43982..081e6e462344d7 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -34,7 +34,7 @@ import { Wrapper, } from './common'; import { VisualizationActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; -import { HistogramActionsProps } from '../visualization_actions/types'; +import { VisualizationActionsProps } from '../visualization_actions/types'; import { HoverVisibilityContainer } from '../hover_visibility_container'; @@ -145,13 +145,13 @@ AreaChartBase.displayName = 'AreaChartBase'; interface AreaChartComponentProps { areaChart: ChartSeriesData[] | null | undefined; configs?: ChartSeriesConfigs | undefined; - histogramActionsOptions?: HistogramActionsProps; + visualizationActionsOptions?: VisualizationActionsProps; } export const AreaChartComponent: React.FC = ({ areaChart, configs, - histogramActionsOptions, + visualizationActionsOptions, }) => { const { ref: measureRef, width, height } = useThrottledResizeObserver(); const customHeight = get('customHeight', configs); @@ -182,7 +182,7 @@ export const AreaChartComponent: React.FC = ({ )} diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index baa0fd867739f8..b0f7cd4c53fc0f 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -37,7 +37,7 @@ import { DraggableLegend } from './draggable_legend'; import { LegendItem } from './draggable_legend_item'; import type { ChartData } from './common'; import { VisualizationActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; -import { HistogramActionsProps } from '../visualization_actions/types'; +import { VisualizationActionsProps } from '../visualization_actions/types'; import { HoverVisibilityContainer } from '../hover_visibility_container'; const LegendFlexItem = styled(EuiFlexItem)` @@ -148,7 +148,7 @@ interface BarChartComponentProps { configs?: ChartSeriesConfigs | undefined; stackByField?: string; timelineId?: string; - histogramActionsOptions?: HistogramActionsProps; + visualizationActionsOptions?: VisualizationActionsProps; } const NO_LEGEND_DATA: LegendItem[] = []; @@ -158,7 +158,7 @@ export const BarChartComponent: React.FC = ({ configs, stackByField, timelineId, - histogramActionsOptions, + visualizationActionsOptions, }) => { const { ref: measureRef, width, height } = useThrottledResizeObserver(); const legendItems: LegendItem[] = useMemo( @@ -210,9 +210,9 @@ export const BarChartComponent: React.FC = ({ {!isVlidSeriesExist && ( )} - {histogramActionsOptions?.lensAttributes && histogramActionsOptions?.timerange && ( + {visualizationActionsOptions?.lensAttributes && visualizationActionsOptions?.timerange && ( )} diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 49603c0f1abce2..7c1e25497e7fee 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -301,7 +301,7 @@ export const StatItemsComponent = React.memo( ( xTickFormatter: histogramDateTimeFormatter([from, to]), onBrushEnd: narrowDateRange, })} - histogramActionsOptions={{ + visualizationActionsOptions={{ lensAttributes: areaChartLensAttributes, queryId: id, inspectIndex: index, diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 28f6b2ab8ba779..26cce3b4cd1fad 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -29,7 +29,7 @@ import { useLensAttributes } from './use_lens_attributes'; import { useAddToExistingCase } from './use_add_to_existing_case'; import { useGetUserCasesPermissions } from '../../lib/kibana'; import { useAddToNewCase } from './use_add_to_new_case'; -import { HistogramActionsProps } from './types'; +import { VisualizationActionsProps } from './types'; const Wrapper = styled.div` &.kpi-matrix-histogram-actions { @@ -43,7 +43,7 @@ export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; const owner = APP_ID; -const VisualizationActionsComponent: React.FC = ({ +const VisualizationActionsComponent: React.FC = ({ className, getLensAttributes, inputId = 'global', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts index 4b87d8da3c6f92..97a59b4a95893c 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts @@ -11,7 +11,7 @@ import { InputsModelId } from '../../store/inputs/constants'; export type LensAttributes = TypedLensByValueInput['attributes']; export type GetLensAttributes = (stackByField?: string) => LensAttributes; -export interface HistogramActionsProps { +export interface VisualizationActionsProps { className?: string; getLensAttributes?: GetLensAttributes; inputId?: InputsModelId; From 0c7cbcbeaff2c9bd86142b46c5c0a720aae9fcd2 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 2 Mar 2022 01:27:38 +0800 Subject: [PATCH 11/59] add vizType --- .../network/visualization_actions.spec.ts | 35 +++++++++++++ .../cypress/screens/inspect.ts | 37 +++++++++----- .../cypress/tasks/inspect.ts | 2 +- .../common/components/charts/areachart.tsx | 10 ++-- .../common/components/charts/barchart.tsx | 2 +- .../common/components/inspect/use_inspect.tsx | 19 +++++-- .../common/components/stat_items/index.tsx | 3 ++ .../visualization_actions/index.tsx | 49 +++++++++---------- .../components/visualization_actions/types.ts | 3 +- .../public/common/store/inputs/actions.ts | 1 + .../public/common/store/inputs/helpers.ts | 4 +- .../public/common/store/inputs/model.ts | 1 + .../public/common/store/inputs/reducer.ts | 6 ++- .../public/common/store/inputs/selectors.ts | 2 + ...i_unique_private_ips_destination_metric.ts | 3 +- 15 files changed, 125 insertions(+), 52 deletions(-) create mode 100644 x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts diff --git a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts new file mode 100644 index 00000000000000..8df4a7c1fb6832 --- /dev/null +++ b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts @@ -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 { INSPECT_MODAL, VIZ_ACTIONS_BUTTONS_IN_SECURITY } from '../../screens/inspect'; +import { cleanKibana } from '../../tasks/common'; + +import { closesModal } from '../../tasks/inspect'; +import { loginAndWaitForPage } from '../../tasks/login'; + +import { NETWORK_URL } from '../../urls/navigation'; + +describe('Visualization actions', () => { + context('inspect', () => { + before(() => { + cleanKibana(); + loginAndWaitForPage(NETWORK_URL); + }); + afterEach(() => { + closesModal(); + }); + + VIZ_ACTIONS_BUTTONS_IN_SECURITY.forEach((button) => + it(`inspects the ${button.title}`, () => { + cy.get(button.id).click({ force: true }); + + cy.get('[data-test-subj="viz-actions-inspect"]').click({ force: true }); + cy.get(INSPECT_MODAL).should('be.visible'); + }) + ); + }); +}); diff --git a/x-pack/plugins/security_solution/cypress/screens/inspect.ts b/x-pack/plugins/security_solution/cypress/screens/inspect.ts index f2b332b1772b20..a5003cdf4c7fa0 100644 --- a/x-pack/plugins/security_solution/cypress/screens/inspect.ts +++ b/x-pack/plugins/security_solution/cypress/screens/inspect.ts @@ -47,27 +47,42 @@ export const INSPECT_HOSTS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ }, ]; -export const INSPECT_NETWORK_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ +export const VIZ_ACTIONS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ + { + id: '[data-test-subj="stat-networkKpiNetworkEventsQuery-networkEvents-metric"]', + title: 'Inspect KPI Network events', + }, + { + id: '[data-test-subj="stat-networkKpiDnsQuery-dnsQueries-metric"]', + title: 'Inspect KPI DNS queries', + }, { - id: '[data-test-subj="stat-networkEvents"]', - title: 'Network events Stat', + id: '[data-test-subj="stat-networkKpiUniqueFlowsQuery-uniqueFlowId-metric"]', + title: 'Inspect KPI Unique flow IDs', }, { - id: '[data-test-subj="stat-dnsQueries"]', - title: 'DNS queries Stat', + id: '[data-test-subj="stat-networkKpiTlsHandshakesQuery-tlsHandshakes-metric"]', + title: 'Inspect KPI TLS handshakes', }, { - id: '[data-test-subj="stat-uniqueFlowId"]', - title: 'Unique flow IDs Stat', + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueSourcePrivateIps-metric"]', + title: 'Inspect KPI Unique private IPs - source', }, { - id: '[data-test-subj="stat-tlsHandshakes"]', - title: 'TLS handshakes Stat', + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueDestinationPrivateIps-metric"]', + title: 'Inspect KPI Unique private IPs - dest.', }, { - id: '[data-test-subj="stat-UniqueIps"]', - title: 'Unique private IPs Stat', + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-bar_horizontal_stacked"]', + title: 'Inspect KPI Unique private IPs - bar chart', }, + { + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-area"]', + title: 'Inspect KPI Unique private IPs - area chart', + }, +]; + +export const INSPECT_NETWORK_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ { id: '[data-test-subj="table-topNFlowSource-loading-false"]', title: 'Source IPs Table', diff --git a/x-pack/plugins/security_solution/cypress/tasks/inspect.ts b/x-pack/plugins/security_solution/cypress/tasks/inspect.ts index 112bf9a208b39c..006e3337aca4be 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/inspect.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/inspect.ts @@ -8,7 +8,7 @@ import { INSPECT_BUTTON_ICON, InspectButtonMetadata } from '../screens/inspect'; export const closesModal = () => { - cy.get('[data-test-subj="modal-inspect-close"]').click(); + cy.get('[data-test-subj="modal-inspect-close"]').click({ multiple: true }); }; export const clickInspectButton = (container: string) => { diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index 081e6e462344d7..b5fc289b9683b4 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -181,10 +181,12 @@ export const AreaChartComponent: React.FC = ({ {!isVlidSeriesExist && ( )} - + {visualizationActionsOptions != null && ( + + )} ); diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index b0f7cd4c53fc0f..ef7ce9c44445e8 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -210,7 +210,7 @@ export const BarChartComponent: React.FC = ({ {!isVlidSeriesExist && ( )} - {visualizationActionsOptions?.lensAttributes && visualizationActionsOptions?.timerange && ( + {visualizationActionsOptions != null && ( void; onCloseInspect?: () => void; queryId: string; + vizType: string; } export const useInspect = ({ @@ -30,12 +31,19 @@ export const useInspect = ({ onClick, onCloseInspect, queryId, + vizType, }: UseInspectModalProps) => { const dispatch = useDispatch(); const getGlobalQuery = inputsSelectors.globalQueryByIdSelector(); const getTimelineQuery = inputsSelectors.timelineQueryByIdSelector(); - const { loading, inspect, selectedInspectIndex, isInspected } = useDeepEqualSelector((state) => + const { + loading, + inspect, + selectedInspectIndex, + isInspected, + vizType: activeVizType, + } = useDeepEqualSelector((state) => inputId === 'global' ? getGlobalQuery(state, queryId) : getTimelineQuery(state, queryId) ); @@ -49,9 +57,10 @@ export const useInspect = ({ inputId, isInspected: true, selectedInspectIndex: inspectIndex, + vizType, }) ); - }, [onClick, dispatch, queryId, inputId, inspectIndex]); + }, [onClick, dispatch, queryId, inputId, inspectIndex, vizType]); const handleCloseModal = useCallback(() => { if (onCloseInspect != null) { @@ -63,6 +72,7 @@ export const useInspect = ({ inputId, isInspected: false, selectedInspectIndex: inspectIndex, + vizType: null, }) ); }, [onCloseInspect, dispatch, queryId, inputId, inspectIndex]); @@ -88,8 +98,9 @@ export const useInspect = ({ } const isShowingModal = useMemo( - () => !loading && selectedInspectIndex === inspectIndex && isInspected, - [inspectIndex, isInspected, loading, selectedInspectIndex] + () => + !loading && selectedInspectIndex === inspectIndex && isInspected && activeVizType === vizType, + [activeVizType, vizType, inspectIndex, isInspected, loading, selectedInspectIndex] ); const isButtonDisabled = useMemo( diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 7c1e25497e7fee..5589271bf44fcd 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -279,6 +279,7 @@ export const StatItemsComponent = React.memo( {field.lensAttributes && timerange && ( ( inspectIndex: index, timerange, title: `KPI ${description}`, + vizType: 'bar_horizontal_stacked', }} /> @@ -327,6 +329,7 @@ export const StatItemsComponent = React.memo( inspectIndex: index, timerange, title: `KPI ${description}`, + vizType: 'area', }} /> diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 26cce3b4cd1fad..f54d25e1753c31 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -4,17 +4,10 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { - EuiButtonIcon, - EuiContextMenuItem, - EuiContextMenuPanel, - EuiPopover, - useGeneratedHtmlId, -} from '@elastic/eui'; +import { EuiButtonIcon, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; - import { GetAllCasesSelectorModalProps, GetCreateCaseFlyoutProps, @@ -50,6 +43,7 @@ const VisualizationActionsComponent: React.FC = ({ inspectIndex = 0, isInspectButtonDisabled, isMultipleQuery, + vizType, lensAttributes, onCloseInspect, queryId, @@ -69,10 +63,6 @@ const VisualizationActionsComponent: React.FC = ({ const [isPopoverOpen, setPopover] = useState(false); const [isSaveModalVisible, setIsSaveModalVisible] = useState(false); - const contextMenuPopoverId = useGeneratedHtmlId({ - prefix: 'contextMenuPopover', - }); - const onButtonClick = () => { setPopover(!isPopoverOpen); }; @@ -87,6 +77,8 @@ const VisualizationActionsComponent: React.FC = ({ stackByField, }); + const dataTestSubj = ['stat', queryId, vizType].join('-'); + const { disabled: isAddToCaseDisabled, closeAllCaseModal, @@ -173,61 +165,67 @@ const VisualizationActionsComponent: React.FC = ({ onCloseInspect, onClick: closePopover, queryId, + vizType, }); const items = [ , , , , , @@ -238,11 +236,12 @@ const VisualizationActionsComponent: React.FC = ({ className={HISTOGRAM_ACTIONS_BUTTON_CLASS} iconType="boxesHorizontal" onClick={onButtonClick} + data-test-subj={dataTestSubj} /> ); return ( - + {isSaveModalVisible && ( = ({ /> )} = ({ anchorPosition="downLeft" panelClassName="withHoverActions__popover" > - + {isShowingModal && request !== null && response !== null && ( void; queryId: string; + stackByField?: string; timerange: { from: string; to: string }; title: React.ReactNode; - stackByField?: string; } diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts b/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts index 3da18090eb443e..33d699695dd9a8 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts @@ -65,6 +65,7 @@ export const setInspectionParameter = actionCreator<{ inputId: InputsModelId; isInspected: boolean; selectedInspectIndex: number; + vizType: string | null; }>('SET_INSPECTION_PARAMETER'); export const deleteAllQuery = actionCreator<{ id: InputsModelId }>('DELETE_ALL_QUERY'); diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts index 94e7ff6fbc981f..524a64fca0894f 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts @@ -121,6 +121,7 @@ export interface SetIsInspectedParams { isInspected: boolean; selectedInspectIndex: number; state: InputsModel; + vizType: string | null; } export const setIsInspected = ({ @@ -129,6 +130,7 @@ export const setIsInspected = ({ isInspected, selectedInspectIndex, state, + vizType, }: SetIsInspectedParams): InputsModel => { const myQueryIndex = state[inputId].queries.findIndex((q) => q.id === id); const myQuery = myQueryIndex > -1 ? state[inputId].queries[myQueryIndex] : null; @@ -141,7 +143,7 @@ export const setIsInspected = ({ myQueryIndex > -1 ? [ ...state[inputId].queries.slice(0, myQueryIndex), - { ...myQuery, isInspected, selectedInspectIndex }, + { ...myQuery, isInspected, selectedInspectIndex, vizType }, ...state[inputId].queries.slice(myQueryIndex + 1), ] : [...state[inputId].queries], diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts index f5e31d42e22eab..8f8233abd0a36a 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts @@ -62,6 +62,7 @@ export interface GlobalGenericQuery { loading: boolean; selectedInspectIndex: number; invalidKqlQuery?: Error; + vizType: string | null; } export interface GlobalGraphqlQuery extends GlobalGenericQuery { diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts b/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts index 848d5adbffc9af..1b339e64b85787 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts @@ -218,8 +218,10 @@ export const inputsReducer = reducerWithInitialState(initialInputsState) }, })) .case(toggleTimelineLinkTo, (state, { linkToId }) => toggleLockTimeline(linkToId, state)) - .case(setInspectionParameter, (state, { id, inputId, isInspected, selectedInspectIndex }) => - setIsInspected({ id, inputId, isInspected, selectedInspectIndex, state }) + .case( + setInspectionParameter, + (state, { id, inputId, isInspected, selectedInspectIndex, vizType }) => + setIsInspected({ id, inputId, isInspected, selectedInspectIndex, state, vizType }) ) .case(removeGlobalLinkTo, (state) => removeGlobalLink(state)) .case(addGlobalLinkTo, (state, { linkToId }) => addGlobalLink(linkToId, state)) diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts b/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts index 864a473a820993..d6307f872d927d 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts @@ -26,6 +26,7 @@ const selectGlobalQuery = (state: State, id: string): GlobalQuery => loading: false, refetch: null, selectedInspectIndex: 0, + vizType: null, }; const selectTimelineQuery = (state: State, id: string): GlobalQuery => @@ -37,6 +38,7 @@ const selectTimelineQuery = (state: State, id: string): GlobalQuery => loading: false, refetch: null, selectedInspectIndex: 0, + vizType: null, }; export const inputsSelector = () => createSelector(selectInputs, (inputs) => inputs); diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts index 7fb5b439faede3..b5e02bc875c714 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts @@ -4,9 +4,10 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ + import { LensAttributes } from '../../common/components/visualization_actions/types'; -export const kpiUniquePrivateIpsDestinationMetric = { +export const kpiUniquePrivateIpsDestinationMetric: LensAttributes = { description: '', state: { datasourceStates: { From fb711a149a91cfba9452c558584db5dc319294b5 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 2 Mar 2022 21:25:50 +0800 Subject: [PATCH 12/59] cypress hosts inspect --- .../hosts/visualization_actions.spec.ts | 68 +++++++ .../network/visualization_actions.spec.ts | 3 +- .../cypress/screens/inspect.ts | 109 ++++++++++- .../cypress/tasks/inspect.ts | 2 +- .../cypress/tasks/visualization_actions.ts | 12 ++ .../common/components/charts/areachart.tsx | 5 +- .../common/components/charts/barchart.tsx | 5 +- .../common/components/stat_items/index.tsx | 2 +- .../visualization_actions/index.tsx | 172 ++++++++++-------- 9 files changed, 288 insertions(+), 90 deletions(-) create mode 100644 x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts create mode 100644 x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts diff --git a/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts new file mode 100644 index 00000000000000..05ee6c6a1e20cb --- /dev/null +++ b/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts @@ -0,0 +1,68 @@ +/* + * 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 { + INSPECT_HOSTS_BUTTONS_IN_SECURITY, + INSPECT_MODAL, + VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY, + VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY, +} from '../../screens/inspect'; +import { HOST_OVERVIEW } from '../../screens/hosts/main'; +import { cleanKibana } from '../../tasks/common'; + +import { clickInspectButton, closesModal, openStatsAndTables } from '../../tasks/inspect'; +import { loginAndWaitForHostDetailsPage, loginAndWaitForPage } from '../../tasks/login'; + +import { HOSTS_URL } from '../../urls/navigation'; +import { clickVizActionsInspect } from '../../tasks/visualization_actions'; + +describe('Visualization actions', () => { + before(() => { + cleanKibana(); + }); + context('Hosts', () => { + before(() => { + loginAndWaitForPage(HOSTS_URL); + }); + afterEach(() => { + closesModal(); + }); + + VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY.forEach((button) => + it(`inspects the ${button.title}`, () => { + if (button.tabId) { + cy.get(button.tabId).click(); + } + cy.get(button.id).click({ force: true }); + + clickVizActionsInspect(); + cy.get(INSPECT_MODAL).should('be.visible'); + }) + ); + }); + + context('Host details', () => { + before(() => { + loginAndWaitForHostDetailsPage(); + }); + afterEach(() => { + closesModal(); + }); + + VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY.forEach((button) => + it(`inspects the ${button.title}`, () => { + if (button.tabId) { + cy.get(button.tabId).click(); + } + cy.get(button.id).click({ force: true }); + + clickVizActionsInspect(); + cy.get(INSPECT_MODAL).should('be.visible'); + }) + ); + }); +}); diff --git a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts index 8df4a7c1fb6832..2f9f120b4f14f5 100644 --- a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts @@ -10,6 +10,7 @@ import { cleanKibana } from '../../tasks/common'; import { closesModal } from '../../tasks/inspect'; import { loginAndWaitForPage } from '../../tasks/login'; +import { clickVizActionsInspect } from '../../tasks/visualization_actions'; import { NETWORK_URL } from '../../urls/navigation'; @@ -27,7 +28,7 @@ describe('Visualization actions', () => { it(`inspects the ${button.title}`, () => { cy.get(button.id).click({ force: true }); - cy.get('[data-test-subj="viz-actions-inspect"]').click({ force: true }); + clickVizActionsInspect(); cy.get(INSPECT_MODAL).should('be.visible'); }) ); diff --git a/x-pack/plugins/security_solution/cypress/screens/inspect.ts b/x-pack/plugins/security_solution/cypress/screens/inspect.ts index a5003cdf4c7fa0..f313b722945990 100644 --- a/x-pack/plugins/security_solution/cypress/screens/inspect.ts +++ b/x-pack/plugins/security_solution/cypress/screens/inspect.ts @@ -7,6 +7,7 @@ export const INSPECT_BUTTON_ICON = '[data-test-subj="inspect-icon-button"]'; export const INSPECT_MODAL = '[data-test-subj="modal-inspect-euiModal"]'; +export const VIZ_INSPECT_BUTTON = '[data-test-subj="viz-actions-inspect"]'; export interface InspectButtonMetadata { altInspectId?: string; @@ -15,15 +16,115 @@ export interface InspectButtonMetadata { tabId?: string; } -export const INSPECT_HOSTS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ +export const VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', + title: 'Unique IPs Stat - Success', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', + title: 'Unique IPs Stat - Failure', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', + title: 'User authentication - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', + title: 'User authentication - area', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', + title: 'Unique IPs - source', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', + title: 'Unique IPs - destination', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', + title: 'Unique IPs - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', + title: 'Unique IPs - area', + }, + { + id: '[data-test-subj="stat-authenticationsHistogramQuery"]', + title: 'Authentications histogram', + tabId: '[data-test-subj="navigation-authentications"]', + }, + { + id: '[data-test-subj="stat-eventsHistogramQuery"]', + title: 'Events histogram', + tabId: '[data-test-subj="navigation-events"]', + }, + { + id: '[data-test-subj="stat-alertsHistogramQuery"]', + title: 'External alert trend histogram', + tabId: '[data-test-subj="navigation-externalAlerts"]', + }, +]; + +export const VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ { - id: '[data-test-subj="stat-hosts"]', + id: '[data-test-subj="stat-hostsKpiHostsQuery-hosts-metric"]', title: 'Hosts Stat', }, { - id: '[data-test-subj="stat-uniqueIps"]', - title: 'Unique IPs Stat', + id: '[data-test-subj="stat-hostsKpiHostsQuery-area"]', + title: 'Hosts Stat - area', }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', + title: 'Unique IPs Stat - Success', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', + title: 'Unique IPs Stat - Failure', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', + title: 'User authentication - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', + title: 'User authentication - area', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', + title: 'Unique IPs - source', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', + title: 'Unique IPs - destination', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', + title: 'Unique IPs - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', + title: 'Unique IPs - area', + }, + { + id: '[data-test-subj="stat-authenticationsHistogramQuery"]', + title: 'Authentications histogram', + tabId: '[data-test-subj="navigation-authentications"]', + }, + { + id: '[data-test-subj="stat-eventsHistogramQuery"]', + title: 'Events histogram', + tabId: '[data-test-subj="navigation-events"]', + }, + { + id: '[data-test-subj="stat-alertsHistogramQuery"]', + title: 'External alert trend histogram', + tabId: '[data-test-subj="navigation-externalAlerts"]', + }, +]; + +export const INSPECT_HOSTS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ { id: '[data-test-subj="table-allHosts-loading-false"]', title: 'All Hosts Table', diff --git a/x-pack/plugins/security_solution/cypress/tasks/inspect.ts b/x-pack/plugins/security_solution/cypress/tasks/inspect.ts index 006e3337aca4be..112bf9a208b39c 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/inspect.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/inspect.ts @@ -8,7 +8,7 @@ import { INSPECT_BUTTON_ICON, InspectButtonMetadata } from '../screens/inspect'; export const closesModal = () => { - cy.get('[data-test-subj="modal-inspect-close"]').click({ multiple: true }); + cy.get('[data-test-subj="modal-inspect-close"]').click(); }; export const clickInspectButton = (container: string) => { diff --git a/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts b/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts new file mode 100644 index 00000000000000..c6143c76af8333 --- /dev/null +++ b/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts @@ -0,0 +1,12 @@ +/* + * 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 { VIZ_INSPECT_BUTTON } from '../screens/inspect'; + +export const clickVizActionsInspect = () => { + cy.get(VIZ_INSPECT_BUTTON).click({ force: true }); +}; diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index b5fc289b9683b4..d484da27323d0f 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -182,10 +182,7 @@ export const AreaChartComponent: React.FC = ({ )} {visualizationActionsOptions != null && ( - + )} diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index ef7ce9c44445e8..be5cdf29347343 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -211,10 +211,7 @@ export const BarChartComponent: React.FC = ({ )} {visualizationActionsOptions != null && ( - + )} diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 5589271bf44fcd..ce70305612f0ae 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -285,7 +285,7 @@ export const StatItemsComponent = React.memo( inspectIndex={index} timerange={timerange} title={`KPI ${description}`} - className="kpi-matrix-histogram-actions" + className="viz-actions" /> )} diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index f54d25e1753c31..ebacfb633531c6 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -25,7 +25,7 @@ import { useAddToNewCase } from './use_add_to_new_case'; import { VisualizationActionsProps } from './types'; const Wrapper = styled.div` - &.kpi-matrix-histogram-actions { + &.viz-actions { position: absolute; top: 0; right: 0; @@ -77,10 +77,10 @@ const VisualizationActionsComponent: React.FC = ({ stackByField, }); - const dataTestSubj = ['stat', queryId, vizType].join('-'); + const dataTestSubj = ['stat', queryId, vizType].filter((i) => i != null).join('-'); const { - disabled: isAddToCaseDisabled, + disabled: isAddToExistingCaseDisabled, closeAllCaseModal, isAllCaseModalOpen, onCaseClicked, @@ -98,6 +98,7 @@ const VisualizationActionsComponent: React.FC = ({ attachments: chartAddedToCase, onAddToNewCaseClicked, isCreateCaseFlyoutOpen, + disabled: isAddToNewCaseDisabled, } = useAddToNewCase({ onClick: closePopover, timeRange: timerange, @@ -168,68 +169,87 @@ const VisualizationActionsComponent: React.FC = ({ vizType, }); - const items = [ - - - , - - - , - - - , - - - , - - - , - ]; + const disaledOpenInLens = useMemo( + () => !canUseEditor() || attributes == null, + [attributes, canUseEditor] + ); + + const items = useMemo( + () => [ + + + , + + + , + + + , + + + , + + + , + ], + [ + disableInspectButton, + disaledOpenInLens, + handleInspectButtonClick, + isAddToExistingCaseDisabled, + isAddToNewCaseDisabled, + onAddToExistingCaseClicked, + onAddToNewCaseClicked, + onOpenInLens, + onSaveVisualization, + userCanCrud, + ] + ); const button = ( = ({ onClose={closeSaveModalVisible} /> )} - - - + {request !== null && response !== null && ( + + + + )} {isShowingModal && request !== null && response !== null && ( Date: Thu, 3 Mar 2022 00:36:38 +0800 Subject: [PATCH 13/59] add viz actions cypress tests --- .../hosts/visualization_actions.spec.ts | 138 +++++++++++--- .../network/visualization_actions.spec.ts | 78 +++++++- .../cypress/screens/inspect.ts | 144 --------------- .../cypress/screens/visualization_actions.ts | 171 ++++++++++++++++++ .../cypress/tasks/visualization_actions.ts | 55 +++++- 5 files changed, 404 insertions(+), 182 deletions(-) create mode 100644 x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts diff --git a/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts index 05ee6c6a1e20cb..4114c1eeb4dbc4 100644 --- a/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts @@ -5,20 +5,33 @@ * 2.0. */ -import { - INSPECT_HOSTS_BUTTONS_IN_SECURITY, - INSPECT_MODAL, - VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY, - VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY, -} from '../../screens/inspect'; +import { INSPECT_MODAL, VIZ_INSPECT_BUTTON } from '../../screens/inspect'; import { HOST_OVERVIEW } from '../../screens/hosts/main'; import { cleanKibana } from '../../tasks/common'; -import { clickInspectButton, closesModal, openStatsAndTables } from '../../tasks/inspect'; +import { closesModal } from '../../tasks/inspect'; import { loginAndWaitForHostDetailsPage, loginAndWaitForPage } from '../../tasks/login'; import { HOSTS_URL } from '../../urls/navigation'; -import { clickVizActionsInspect } from '../../tasks/visualization_actions'; +import { + clickVizActionsAddToExistingCase, + clickVizActionsAddToNewCase, + clickVizActionsButton, + clickVizActionsInspect, + clickVizActionsOpenInLens, + clickVizActionsSave, + closeAllCasesModal, + closeCreateCaseFlyout, + closeSaveObjectModal, + vizActionsMenuShouldBeClosed, +} from '../../tasks/visualization_actions'; +import { + CREATE_CASE_FLYOUT, + SAVE_LENS_MODAL, + SELECT_CASE_MODAL, + VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY, + VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY, +} from '../../screens/visualization_actions'; describe('Visualization actions', () => { before(() => { @@ -28,41 +41,112 @@ describe('Visualization actions', () => { before(() => { loginAndWaitForPage(HOSTS_URL); }); - afterEach(() => { - closesModal(); - }); - VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY.forEach((button) => + VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY.forEach((button) => { it(`inspects the ${button.title}`, () => { - if (button.tabId) { - cy.get(button.tabId).click(); - } - cy.get(button.id).click({ force: true }); - + clickVizActionsButton(button.id, button.tabId); clickVizActionsInspect(); + vizActionsMenuShouldBeClosed(); cy.get(INSPECT_MODAL).should('be.visible'); - }) - ); + closesModal(); + }); + + it(`save the ${button.title}`, () => { + clickVizActionsButton(button.id, button.tabId); + clickVizActionsSave(); + vizActionsMenuShouldBeClosed(); + cy.get(SAVE_LENS_MODAL).should('be.visible'); + + closeSaveObjectModal(); + }); + + it(`open the ${button.title} chart in Lens`, () => { + clickVizActionsButton(button.id, button.tabId); + + cy.window().then((win) => { + cy.stub(win, 'open').as('openInLens'); + }); + clickVizActionsOpenInLens(); + vizActionsMenuShouldBeClosed(); + + cy.get('@openInLens').should('be.called'); + }); + + it(`add the ${button.title} chart to a new case`, () => { + clickVizActionsButton(button.id, button.tabId); + + clickVizActionsAddToNewCase(); + vizActionsMenuShouldBeClosed(); + cy.get(CREATE_CASE_FLYOUT).should('exist'); + closeCreateCaseFlyout(); + }); + + it(`add the ${button.title} chart to an existing case`, () => { + clickVizActionsButton(button.id, button.tabId); + + clickVizActionsAddToExistingCase(); + vizActionsMenuShouldBeClosed(); + cy.get(SELECT_CASE_MODAL).should('exist'); + closeAllCasesModal(); + }); + }); }); context('Host details', () => { before(() => { loginAndWaitForHostDetailsPage(); }); - afterEach(() => { - closesModal(); - }); - VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY.forEach((button) => + VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY.forEach((button) => { it(`inspects the ${button.title}`, () => { + clickVizActionsButton(button.id, button.tabId); + clickVizActionsInspect(); + vizActionsMenuShouldBeClosed(); + cy.get(INSPECT_MODAL).should('be.visible'); + closesModal(); + }); + + it(`save the ${button.title}`, () => { + clickVizActionsButton(button.id, button.tabId); + clickVizActionsSave(); + vizActionsMenuShouldBeClosed(); + cy.get(SAVE_LENS_MODAL).should('be.visible'); + + closeSaveObjectModal(); + }); + + it(`open the ${button.title} chart in Lens`, () => { + clickVizActionsButton(button.id, button.tabId); + + cy.window().then((win) => { + cy.stub(win, 'open').as('openInLens'); + }); + clickVizActionsOpenInLens(); + vizActionsMenuShouldBeClosed(); + + cy.get('@openInLens').should('be.called'); + }); + + it(`add the ${button.title} chart to a new case`, () => { + clickVizActionsButton(button.id, button.tabId); + + clickVizActionsAddToNewCase(); + vizActionsMenuShouldBeClosed(); + cy.get(CREATE_CASE_FLYOUT).should('exist'); + closeCreateCaseFlyout(); + }); + + it(`add the ${button.title} chart to a new case`, () => { if (button.tabId) { cy.get(button.tabId).click(); } cy.get(button.id).click({ force: true }); - clickVizActionsInspect(); - cy.get(INSPECT_MODAL).should('be.visible'); - }) - ); + clickVizActionsAddToExistingCase(); + vizActionsMenuShouldBeClosed(); + cy.get(SELECT_CASE_MODAL).should('exist'); + closeAllCasesModal(); + }); + }); }); }); diff --git a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts index 2f9f120b4f14f5..cdf44de9385b41 100644 --- a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts @@ -5,12 +5,30 @@ * 2.0. */ -import { INSPECT_MODAL, VIZ_ACTIONS_BUTTONS_IN_SECURITY } from '../../screens/inspect'; +import { INSPECT_MODAL } from '../../screens/inspect'; +import { + CREATE_CASE_FLYOUT, + SAVE_LENS_MODAL, + SELECT_CASE_MODAL, + VIZ_ACTIONS_BUTTONS_IN_SECURITY, + VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY, +} from '../../screens/visualization_actions'; import { cleanKibana } from '../../tasks/common'; import { closesModal } from '../../tasks/inspect'; import { loginAndWaitForPage } from '../../tasks/login'; -import { clickVizActionsInspect } from '../../tasks/visualization_actions'; +import { + clickVizActionsAddToExistingCase, + clickVizActionsAddToNewCase, + clickVizActionsButton, + clickVizActionsInspect, + clickVizActionsOpenInLens, + clickVizActionsSave, + closeAllCasesModal, + closeCreateCaseFlyout, + closeSaveObjectModal, + vizActionsMenuShouldBeClosed, +} from '../../tasks/visualization_actions'; import { NETWORK_URL } from '../../urls/navigation'; @@ -20,17 +38,57 @@ describe('Visualization actions', () => { cleanKibana(); loginAndWaitForPage(NETWORK_URL); }); - afterEach(() => { - closesModal(); - }); - VIZ_ACTIONS_BUTTONS_IN_SECURITY.forEach((button) => + VIZ_ACTIONS_BUTTONS_IN_SECURITY.forEach((button) => { it(`inspects the ${button.title}`, () => { - cy.get(button.id).click({ force: true }); - + clickVizActionsButton(button.id, button.tabId); clickVizActionsInspect(); + vizActionsMenuShouldBeClosed(); cy.get(INSPECT_MODAL).should('be.visible'); - }) - ); + closesModal(); + }); + + it(`save the ${button.title}`, () => { + clickVizActionsButton(button.id, button.tabId); + clickVizActionsSave(); + vizActionsMenuShouldBeClosed(); + cy.get(SAVE_LENS_MODAL).should('be.visible'); + + closeSaveObjectModal(); + }); + + it(`open the ${button.title} chart in Lens`, () => { + clickVizActionsButton(button.id, button.tabId); + + cy.window().then((win) => { + cy.stub(win, 'open').as('openInLens'); + }); + clickVizActionsOpenInLens(); + vizActionsMenuShouldBeClosed(); + + cy.get('@openInLens').should('be.called'); + }); + + it(`add the ${button.title} chart to a new case`, () => { + clickVizActionsButton(button.id, button.tabId); + + clickVizActionsAddToNewCase(); + vizActionsMenuShouldBeClosed(); + cy.get(CREATE_CASE_FLYOUT).should('exist'); + closeCreateCaseFlyout(); + }); + + it(`add the ${button.title} chart to a new case`, () => { + if (button.tabId) { + cy.get(button.tabId).click(); + } + cy.get(button.id).click({ force: true }); + + clickVizActionsAddToExistingCase(); + vizActionsMenuShouldBeClosed(); + cy.get(SELECT_CASE_MODAL).should('exist'); + closeAllCasesModal(); + }); + }); }); }); diff --git a/x-pack/plugins/security_solution/cypress/screens/inspect.ts b/x-pack/plugins/security_solution/cypress/screens/inspect.ts index f313b722945990..f0fbf7e6a30890 100644 --- a/x-pack/plugins/security_solution/cypress/screens/inspect.ts +++ b/x-pack/plugins/security_solution/cypress/screens/inspect.ts @@ -7,7 +7,6 @@ export const INSPECT_BUTTON_ICON = '[data-test-subj="inspect-icon-button"]'; export const INSPECT_MODAL = '[data-test-subj="modal-inspect-euiModal"]'; -export const VIZ_INSPECT_BUTTON = '[data-test-subj="viz-actions-inspect"]'; export interface InspectButtonMetadata { altInspectId?: string; @@ -16,114 +15,6 @@ export interface InspectButtonMetadata { tabId?: string; } -export const VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', - title: 'Unique IPs Stat - Success', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', - title: 'Unique IPs Stat - Failure', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', - title: 'User authentication - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', - title: 'User authentication - area', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', - title: 'Unique IPs - source', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', - title: 'Unique IPs - destination', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', - title: 'Unique IPs - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', - title: 'Unique IPs - area', - }, - { - id: '[data-test-subj="stat-authenticationsHistogramQuery"]', - title: 'Authentications histogram', - tabId: '[data-test-subj="navigation-authentications"]', - }, - { - id: '[data-test-subj="stat-eventsHistogramQuery"]', - title: 'Events histogram', - tabId: '[data-test-subj="navigation-events"]', - }, - { - id: '[data-test-subj="stat-alertsHistogramQuery"]', - title: 'External alert trend histogram', - tabId: '[data-test-subj="navigation-externalAlerts"]', - }, -]; - -export const VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ - { - id: '[data-test-subj="stat-hostsKpiHostsQuery-hosts-metric"]', - title: 'Hosts Stat', - }, - { - id: '[data-test-subj="stat-hostsKpiHostsQuery-area"]', - title: 'Hosts Stat - area', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', - title: 'Unique IPs Stat - Success', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', - title: 'Unique IPs Stat - Failure', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', - title: 'User authentication - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', - title: 'User authentication - area', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', - title: 'Unique IPs - source', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', - title: 'Unique IPs - destination', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', - title: 'Unique IPs - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', - title: 'Unique IPs - area', - }, - { - id: '[data-test-subj="stat-authenticationsHistogramQuery"]', - title: 'Authentications histogram', - tabId: '[data-test-subj="navigation-authentications"]', - }, - { - id: '[data-test-subj="stat-eventsHistogramQuery"]', - title: 'Events histogram', - tabId: '[data-test-subj="navigation-events"]', - }, - { - id: '[data-test-subj="stat-alertsHistogramQuery"]', - title: 'External alert trend histogram', - tabId: '[data-test-subj="navigation-externalAlerts"]', - }, -]; - export const INSPECT_HOSTS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ { id: '[data-test-subj="table-allHosts-loading-false"]', @@ -148,41 +39,6 @@ export const INSPECT_HOSTS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ }, ]; -export const VIZ_ACTIONS_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ - { - id: '[data-test-subj="stat-networkKpiNetworkEventsQuery-networkEvents-metric"]', - title: 'Inspect KPI Network events', - }, - { - id: '[data-test-subj="stat-networkKpiDnsQuery-dnsQueries-metric"]', - title: 'Inspect KPI DNS queries', - }, - { - id: '[data-test-subj="stat-networkKpiUniqueFlowsQuery-uniqueFlowId-metric"]', - title: 'Inspect KPI Unique flow IDs', - }, - { - id: '[data-test-subj="stat-networkKpiTlsHandshakesQuery-tlsHandshakes-metric"]', - title: 'Inspect KPI TLS handshakes', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueSourcePrivateIps-metric"]', - title: 'Inspect KPI Unique private IPs - source', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueDestinationPrivateIps-metric"]', - title: 'Inspect KPI Unique private IPs - dest.', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-bar_horizontal_stacked"]', - title: 'Inspect KPI Unique private IPs - bar chart', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-area"]', - title: 'Inspect KPI Unique private IPs - area chart', - }, -]; - export const INSPECT_NETWORK_BUTTONS_IN_SECURITY: InspectButtonMetadata[] = [ { id: '[data-test-subj="table-topNFlowSource-loading-false"]', diff --git a/x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts b/x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts new file mode 100644 index 00000000000000..2e252e8f9e2b32 --- /dev/null +++ b/x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts @@ -0,0 +1,171 @@ +/* + * 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. + */ + +export const VIZ_INSPECT_BUTTON = '[data-test-subj="viz-actions-inspect"]'; +export const VIZ_SAVE_BUTTON = `[data-test-subj="viz-actions-save"]`; +export const VIZ_OPEN_IN_LENS_BUTTON = '[data-test-subj="viz-actions-open-in-lens"]'; +export const VIZ_ADD_TO_NEW_CASE_BUTTON = '[data-test-subj="viz-actions-add-to-new-case"]'; +export const VIZ_ADD_TO_EXISTING_CASE_BUTTON = + '[data-test-subj="viz-actions-add-to-existing-case"]'; + +export const SELECT_CASE_MODAL = '[data-test-subj="all-cases-modal"]'; +export const SELECT_CASE_MODAL_CLOSE_BUTTON = `${SELECT_CASE_MODAL} .euiModal__closeIcon`; + +export const SAVE_LENS_MODAL = '[data-test-subj="savedObjectSaveModal"]'; +export const SAVE_LENS_MODAL_CLOSE_BUTTON = `${SAVE_LENS_MODAL} .euiModal__closeIcon`; +export const CREATE_CASE_FLYOUT = '[data-test-subj="create-case-flyout"]'; +export const CREATE_CASE_FLYOUT_CLOSE_BUTTON = `${CREATE_CASE_FLYOUT} [data-test-subj="euiFlyoutCloseButton"]`; + +export interface VizActionsButtonMetadata { + altInspectId?: string; + id: string; + title: string; + tabId?: string; +} + +export const VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY: VizActionsButtonMetadata[] = [ + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', + title: 'Unique IPs Stat - Success', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', + title: 'Unique IPs Stat - Failure', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', + title: 'User authentication - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', + title: 'User authentication - area', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', + title: 'Unique IPs - source', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', + title: 'Unique IPs - destination', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', + title: 'Unique IPs - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', + title: 'Unique IPs - area', + }, + { + id: '[data-test-subj="stat-authenticationsHistogramQuery"]', + title: 'Authentications histogram', + tabId: '[data-test-subj="navigation-authentications"]', + }, + { + id: '[data-test-subj="stat-eventsHistogramQuery"]', + title: 'Events histogram', + tabId: '[data-test-subj="navigation-events"]', + }, + { + id: '[data-test-subj="stat-alertsHistogramQuery"]', + title: 'External alert trend histogram', + tabId: '[data-test-subj="navigation-externalAlerts"]', + }, +]; + +export const VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY: VizActionsButtonMetadata[] = [ + { + id: '[data-test-subj="stat-hostsKpiHostsQuery-hosts-metric"]', + title: 'Hosts Stat', + }, + { + id: '[data-test-subj="stat-hostsKpiHostsQuery-area"]', + title: 'Hosts Stat - area', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', + title: 'Unique IPs Stat - Success', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', + title: 'Unique IPs Stat - Failure', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', + title: 'User authentication - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', + title: 'User authentication - area', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', + title: 'Unique IPs - source', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', + title: 'Unique IPs - destination', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', + title: 'Unique IPs - bar', + }, + { + id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', + title: 'Unique IPs - area', + }, + { + id: '[data-test-subj="stat-authenticationsHistogramQuery"]', + title: 'Authentications histogram', + tabId: '[data-test-subj="navigation-authentications"]', + }, + { + id: '[data-test-subj="stat-eventsHistogramQuery"]', + title: 'Events histogram', + tabId: '[data-test-subj="navigation-events"]', + }, + { + id: '[data-test-subj="stat-alertsHistogramQuery"]', + title: 'External alert trend histogram', + tabId: '[data-test-subj="navigation-externalAlerts"]', + }, +]; + +export const VIZ_ACTIONS_BUTTONS_IN_SECURITY: VizActionsButtonMetadata[] = [ + { + id: '[data-test-subj="stat-networkKpiNetworkEventsQuery-networkEvents-metric"]', + title: 'Inspect KPI Network events', + }, + { + id: '[data-test-subj="stat-networkKpiDnsQuery-dnsQueries-metric"]', + title: 'Inspect KPI DNS queries', + }, + { + id: '[data-test-subj="stat-networkKpiUniqueFlowsQuery-uniqueFlowId-metric"]', + title: 'Inspect KPI Unique flow IDs', + }, + { + id: '[data-test-subj="stat-networkKpiTlsHandshakesQuery-tlsHandshakes-metric"]', + title: 'Inspect KPI TLS handshakes', + }, + { + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueSourcePrivateIps-metric"]', + title: 'Inspect KPI Unique private IPs - source', + }, + { + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueDestinationPrivateIps-metric"]', + title: 'Inspect KPI Unique private IPs - dest.', + }, + { + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-bar_horizontal_stacked"]', + title: 'Inspect KPI Unique private IPs - bar chart', + }, + { + id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-area"]', + title: 'Inspect KPI Unique private IPs - area chart', + }, +]; diff --git a/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts b/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts index c6143c76af8333..80c3507e2db36d 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts @@ -5,8 +5,61 @@ * 2.0. */ -import { VIZ_INSPECT_BUTTON } from '../screens/inspect'; +import { + CREATE_CASE_FLYOUT_CLOSE_BUTTON, + SAVE_LENS_MODAL_CLOSE_BUTTON, + SELECT_CASE_MODAL, + SELECT_CASE_MODAL_CLOSE_BUTTON, + VIZ_ADD_TO_EXISTING_CASE_BUTTON, + VIZ_ADD_TO_NEW_CASE_BUTTON, + VIZ_INSPECT_BUTTON, + VIZ_OPEN_IN_LENS_BUTTON, + VIZ_SAVE_BUTTON, +} from '../screens/visualization_actions'; + +export const clickVizActionsButton = (button: string, tab?: string) => { + if (tab) { + cy.get(tab).click(); + } + cy.get(button).click({ force: true }); +}; export const clickVizActionsInspect = () => { cy.get(VIZ_INSPECT_BUTTON).click({ force: true }); }; + +export const clickVizActionsSave = () => { + cy.get(VIZ_SAVE_BUTTON).click({ force: true }); +}; + +export const clickVizActionsOpenInLens = () => { + cy.get(VIZ_OPEN_IN_LENS_BUTTON).click({ force: true }); +}; + +export const clickVizActionsAddToNewCase = () => { + cy.get(VIZ_ADD_TO_NEW_CASE_BUTTON).click({ force: true }); +}; + +export const clickVizActionsAddToExistingCase = () => { + cy.get(VIZ_ADD_TO_EXISTING_CASE_BUTTON).click({ force: true }); +}; + +export const vizActionsMenuShouldBeClosed = () => { + cy.get(VIZ_INSPECT_BUTTON).should('not.exist'); + cy.get(VIZ_SAVE_BUTTON).should('not.exist'); + cy.get(VIZ_OPEN_IN_LENS_BUTTON).should('not.exist'); + cy.get(VIZ_ADD_TO_NEW_CASE_BUTTON).should('not.exist'); + cy.get(VIZ_ADD_TO_EXISTING_CASE_BUTTON).should('not.exist'); +}; + +export const closeSaveObjectModal = () => { + cy.get(SAVE_LENS_MODAL_CLOSE_BUTTON).click(); +}; + +export const closeCreateCaseFlyout = () => { + cy.get(CREATE_CASE_FLYOUT_CLOSE_BUTTON).click(); +}; + +export const closeAllCasesModal = () => { + cy.get(SELECT_CASE_MODAL_CLOSE_BUTTON).click(); +}; From 2301e5b0a1a82441237bbe693830213de3f26fa6 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 3 Mar 2022 02:34:13 +0800 Subject: [PATCH 14/59] fix type --- .../cypress/integration/hosts/visualization_actions.spec.ts | 3 +-- .../cypress/integration/network/visualization_actions.spec.ts | 1 - .../security_solution/cypress/tasks/visualization_actions.ts | 1 - .../public/common/components/charts/areachart.tsx | 2 +- .../public/common/components/charts/barchart.tsx | 2 +- .../public/common/components/inspect/use_inspect.tsx | 4 ++-- .../public/common/components/visualization_actions/types.ts | 2 +- .../security_solution/public/common/store/inputs/model.ts | 2 +- 8 files changed, 7 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts index 4114c1eeb4dbc4..a3c5b14e83ed6b 100644 --- a/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts @@ -5,8 +5,7 @@ * 2.0. */ -import { INSPECT_MODAL, VIZ_INSPECT_BUTTON } from '../../screens/inspect'; -import { HOST_OVERVIEW } from '../../screens/hosts/main'; +import { INSPECT_MODAL } from '../../screens/inspect'; import { cleanKibana } from '../../tasks/common'; import { closesModal } from '../../tasks/inspect'; diff --git a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts index cdf44de9385b41..c5992c9034596d 100644 --- a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts @@ -11,7 +11,6 @@ import { SAVE_LENS_MODAL, SELECT_CASE_MODAL, VIZ_ACTIONS_BUTTONS_IN_SECURITY, - VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY, } from '../../screens/visualization_actions'; import { cleanKibana } from '../../tasks/common'; diff --git a/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts b/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts index 80c3507e2db36d..077e763acf08cc 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts @@ -8,7 +8,6 @@ import { CREATE_CASE_FLYOUT_CLOSE_BUTTON, SAVE_LENS_MODAL_CLOSE_BUTTON, - SELECT_CASE_MODAL, SELECT_CASE_MODAL_CLOSE_BUTTON, VIZ_ADD_TO_EXISTING_CASE_BUTTON, VIZ_ADD_TO_NEW_CASE_BUTTON, diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index d484da27323d0f..12a70e846ed3c5 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -164,7 +164,7 @@ export const AreaChartComponent: React.FC = ({ return ( - {isVlidSeriesExist && ( + {isVlidSeriesExist && areaChart && ( diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index be5cdf29347343..2b314bd80050f0 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -187,7 +187,7 @@ export const BarChartComponent: React.FC = ({ return ( - {isVlidSeriesExist && ( + {isVlidSeriesExist && barChart && ( diff --git a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx index 38296ff7bd79e9..0197128e4e7f3c 100644 --- a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx +++ b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx @@ -20,7 +20,7 @@ interface UseInspectModalProps { onClick?: () => void; onCloseInspect?: () => void; queryId: string; - vizType: string; + vizType?: string | null; } export const useInspect = ({ @@ -31,7 +31,7 @@ export const useInspect = ({ onClick, onCloseInspect, queryId, - vizType, + vizType = null, }: UseInspectModalProps) => { const dispatch = useDispatch(); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts index 123a5935182332..f893adbe4bc698 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts @@ -18,11 +18,11 @@ export interface VisualizationActionsProps { inspectIndex?: number; isInspectButtonDisabled?: boolean; isMultipleQuery?: boolean; - vizType: string; lensAttributes?: LensAttributes | null; onCloseInspect?: () => void; queryId: string; stackByField?: string; timerange: { from: string; to: string }; title: React.ReactNode; + vizType?: string | null; } diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts index 8f8233abd0a36a..40f818f23dd3df 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts @@ -62,7 +62,7 @@ export interface GlobalGenericQuery { loading: boolean; selectedInspectIndex: number; invalidKqlQuery?: Error; - vizType: string | null; + vizType?: string | null; } export interface GlobalGraphqlQuery extends GlobalGenericQuery { From 4bafba505f45c739a09f0d0b5a5c6bbf069882c5 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 3 Mar 2022 03:12:51 +0800 Subject: [PATCH 15/59] stat_items unit test --- .../public/common/components/stat_items/index.tsx | 2 +- .../public/network/components/kpi_network/mock.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index ce70305612f0ae..cb977a0dd5001b 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -134,7 +134,7 @@ export const addValueToAreaChart = ( ): ChartSeriesData[] => fields .filter((field) => get(`${field.key}Histogram`, data) != null) - .map((field) => ({ + .map(({ lensAttributes, ...field }) => ({ ...field, value: get(`${field.key}Histogram`, data), key: `${field.key}Histogram`, diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts b/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts index 699d91b149ae7c..b741f8c3ffcabe 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts @@ -7,6 +7,10 @@ import { NetworkKpiStrategyResponse } from '../../../../common/search_strategy'; import { StatItems } from '../../../common/components/stat_items'; +import { kpiUniquePrivateIpsArea } from '../../configs/kpi_unique_private_ips_area'; +import { kpiUniquePrivateIpsBar } from '../../configs/kpi_unique_private_ips_bar'; +import { kpiUniquePrivateIpsDestinationMetric } from '../../configs/kpi_unique_private_ips_destination_metric'; +import { kpiUniquePrivateIpsSourceMetric } from '../../configs/kpi_unique_private_ips_source_metric'; export const mockNarrowDateRange = jest.fn(); @@ -107,6 +111,7 @@ export const mockEnableChartsInitialData = { description: 'source', color: '#D36086', icon: 'visMapCoordinate', + lensAttributes: kpiUniquePrivateIpsSourceMetric, }, { key: 'uniqueDestinationPrivateIps', @@ -115,11 +120,14 @@ export const mockEnableChartsInitialData = { description: 'destination', color: '#9170B8', icon: 'visMapCoordinate', + lensAttributes: kpiUniquePrivateIpsDestinationMetric, }, ], description: 'Unique private IPs', enableAreaChart: true, enableBarChart: true, + areaChartLensAttributes: kpiUniquePrivateIpsArea, + barChartLensAttributes: kpiUniquePrivateIpsBar, areaChart: [], barChart: [ { @@ -205,6 +213,7 @@ export const mockEnableChartsData = { description: 'source', color: '#D36086', icon: 'visMapCoordinate', + lensAttributes: kpiUniquePrivateIpsSourceMetric, }, { key: 'uniqueDestinationPrivateIps', @@ -213,6 +222,7 @@ export const mockEnableChartsData = { description: 'destination', color: '#9170B8', icon: 'visMapCoordinate', + lensAttributes: kpiUniquePrivateIpsDestinationMetric, }, ], from: '2019-06-15T06:00:00.000Z', @@ -220,4 +230,6 @@ export const mockEnableChartsData = { statKey: 'UniqueIps', to: '2019-06-18T06:00:00.000Z', narrowDateRange: mockNarrowDateRange, + areaChartLensAttributes: kpiUniquePrivateIpsArea, + barChartLensAttributes: kpiUniquePrivateIpsBar, }; From b042b033eb9a9d45915d4ee0bc36cc203c86986d Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 3 Mar 2022 19:57:06 +0800 Subject: [PATCH 16/59] fix unit tests for alerts by category --- .../navigation/alerts_query_tab_body.tsx | 38 ++----------- .../navigation/alerts_query_tab_body.tsx | 55 +------------------ .../public/network/pages/network.tsx | 6 +- .../alerts_by_category/index.test.tsx | 14 ++++- .../components/alerts_by_category/index.tsx | 1 + .../components/event_counts/index.tsx | 10 ++-- .../components/events_by_dataset/index.tsx | 1 + 7 files changed, 32 insertions(+), 93 deletions(-) diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/alerts_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/alerts_query_tab_body.tsx index 41c0f93760cb7c..548520676184ad 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/alerts_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/alerts_query_tab_body.tsx @@ -7,46 +7,18 @@ import React, { useMemo } from 'react'; -import type { Filter } from '@kbn/es-query'; import { TimelineId } from '../../../../common/types/timeline'; import { AlertsView } from '../../../common/components/alerts_viewer'; +import { filterHostExternalAlertData } from '../../../common/components/visualization_actions/utils'; import { AlertsComponentQueryProps } from './types'; -export const filterHostData: Filter[] = [ - { - query: { - bool: { - filter: [ - { - bool: { - should: [ - { - exists: { - field: 'host.name', - }, - }, - ], - minimum_should_match: 1, - }, - }, - ], - }, - }, - meta: { - alias: '', - disabled: false, - key: 'bool', - negate: false, - type: 'custom', - value: - '{"query": {"bool": {"filter": [{"bool": {"should": [{"exists": {"field": "host.name"}}],"minimum_should_match": 1}}]}}}', - }, - }, -]; export const HostAlertsQueryTabBody = React.memo((alertsProps: AlertsComponentQueryProps) => { const { pageFilters, ...rest } = alertsProps; const hostPageFilters = useMemo( - () => (pageFilters != null ? [...filterHostData, ...pageFilters] : filterHostData), + () => + pageFilters != null + ? [...filterHostExternalAlertData, ...pageFilters] + : filterHostExternalAlertData, [pageFilters] ); diff --git a/x-pack/plugins/security_solution/public/network/pages/navigation/alerts_query_tab_body.tsx b/x-pack/plugins/security_solution/public/network/pages/navigation/alerts_query_tab_body.tsx index 026aa9f68871f2..ad07147bfc4ed3 100644 --- a/x-pack/plugins/security_solution/public/network/pages/navigation/alerts_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/navigation/alerts_query_tab_body.tsx @@ -7,68 +7,17 @@ import React from 'react'; -import type { Filter } from '@kbn/es-query'; import { TimelineId } from '../../../../common/types/timeline'; import { AlertsView } from '../../../common/components/alerts_viewer'; import { NetworkComponentQueryProps } from './types'; - -export const filterNetworkData: Filter[] = [ - { - query: { - bool: { - filter: [ - { - bool: { - should: [ - { - bool: { - should: [ - { - exists: { - field: 'source.ip', - }, - }, - ], - minimum_should_match: 1, - }, - }, - { - bool: { - should: [ - { - exists: { - field: 'destination.ip', - }, - }, - ], - minimum_should_match: 1, - }, - }, - ], - minimum_should_match: 1, - }, - }, - ], - }, - }, - meta: { - alias: '', - disabled: false, - key: 'bool', - negate: false, - type: 'custom', - value: - '{"bool":{"filter":[{"bool":{"should":[{"bool":{"should":[{"exists":{"field": "source.ip"}}],"minimum_should_match":1}},{"bool":{"should":[{"exists":{"field": "destination.ip"}}],"minimum_should_match":1}}],"minimum_should_match":1}}]}}', - }, - }, -]; +import { filterNetworkExternalAlertData } from '../../../common/components/visualization_actions/utils'; export const NetworkAlertsQueryTabBody = React.memo((alertsProps: NetworkComponentQueryProps) => ( )); diff --git a/x-pack/plugins/security_solution/public/network/pages/network.tsx b/x-pack/plugins/security_solution/public/network/pages/network.tsx index cee068975b19b3..422d2877a85047 100644 --- a/x-pack/plugins/security_solution/public/network/pages/network.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/network.tsx @@ -36,7 +36,6 @@ import { SpyRoute } from '../../common/utils/route/spy_routes'; import { Display } from '../../hosts/pages/display'; import { networkModel } from '../store'; import { navTabsNetwork, NetworkRoutes, NetworkRoutesLoading } from './navigation'; -import { filterNetworkData } from './navigation/alerts_query_tab_body'; import { OverviewEmpty } from '../../overview/components/overview_empty'; import * as i18n from './translations'; import { NetworkComponentProps } from './types'; @@ -52,6 +51,7 @@ import { timelineDefaults } from '../../timelines/store/timeline/defaults'; import { useSourcererDataView } from '../../common/containers/sourcerer'; import { useDeepEqualSelector, useShallowEqualSelector } from '../../common/hooks/use_selector'; import { useInvalidFilterQuery } from '../../common/hooks/use_invalid_filter_query'; +import { filterNetworkExternalAlertData } from '../../common/components/visualization_actions/utils'; /** * Need a 100% height here to account for the graph/analyze tool, which sets no explicit height parameters, but fills the available space. */ @@ -89,7 +89,9 @@ const NetworkComponent = React.memo( const tabsFilters = useMemo(() => { if (tabName === NetworkRouteType.alerts) { - return filters.length > 0 ? [...filters, ...filterNetworkData] : filterNetworkData; + return filters.length > 0 + ? [...filters, ...filterNetworkExternalAlertData] + : filterNetworkExternalAlertData; } return filters; }, [tabName, filters]); diff --git a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx index 0f70c6de362eb9..98a77a5cad3cc8 100644 --- a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx @@ -17,7 +17,12 @@ import { mockIndexPattern, TestProviders } from '../../../common/mock'; import { AlertsByCategory } from '.'; jest.mock('../../../common/components/link_to'); -jest.mock('../../../common/lib/kibana'); +jest.mock('../../../common/components/visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); + jest.mock('../../../common/containers/matrix_histogram', () => ({ useMatrixHistogramCombined: jest.fn(), })); @@ -139,5 +144,12 @@ describe('Alerts by category', () => { expect(wrapper.find(`.echChart`).exists()).toBe(true); }); }); + + test('it shows visualization actions', async () => { + await waitFor(() => { + expect(wrapper.find('[data-test-subj="inspect-icon-button"]').exists()).not.toBe(true); + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true); + }); + }); }); }); diff --git a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx index acf85dcf55d181..6e852808a05419 100644 --- a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx @@ -128,6 +128,7 @@ const AlertsByCategoryComponent: React.FC = ({ indexNames={indexNames} setQuery={setQuery} startDate={from} + showInspectButton={false} {...alertsByCategoryHistogramConfigs} /> ); diff --git a/x-pack/plugins/security_solution/public/overview/components/event_counts/index.tsx b/x-pack/plugins/security_solution/public/overview/components/event_counts/index.tsx index b8e04e40e6dfe7..efc5a61d227c06 100644 --- a/x-pack/plugins/security_solution/public/overview/components/event_counts/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/event_counts/index.tsx @@ -13,13 +13,15 @@ import type { DataViewBase, Filter, Query } from '@kbn/es-query'; import { ID as OverviewHostQueryId } from '../../containers/overview_host'; import { OverviewHost } from '../overview_host'; import { OverviewNetwork } from '../overview_network'; -import { filterHostData } from '../../../hosts/pages/navigation/alerts_query_tab_body'; import { useKibana } from '../../../common/lib/kibana'; import { convertToBuildEsQuery } from '../../../common/lib/keury'; -import { filterNetworkData } from '../../../network/pages/navigation/alerts_query_tab_body'; import { getEsQueryConfig } from '../../../../../../../src/plugins/data/common'; import { GlobalTimeArgs } from '../../../common/containers/use_global_time'; import { useInvalidFilterQuery } from '../../../common/hooks/use_invalid_filter_query'; +import { + filterHostExternalAlertData, + filterNetworkExternalAlertData, +} from '../../../common/components/visualization_actions/utils'; const HorizontalSpacer = styled(EuiFlexItem)` width: 24px; @@ -49,7 +51,7 @@ const EventCountsComponent: React.FC = ({ config: getEsQueryConfig(uiSettings), indexPattern, queries: [query], - filters: [...filters, ...filterHostData], + filters: [...filters, ...filterHostExternalAlertData], }), [filters, indexPattern, query, uiSettings] ); @@ -60,7 +62,7 @@ const EventCountsComponent: React.FC = ({ config: getEsQueryConfig(uiSettings), indexPattern, queries: [query], - filters: [...filters, ...filterNetworkData], + filters: [...filters, ...filterNetworkExternalAlertData], }), [filters, indexPattern, uiSettings, query] ); diff --git a/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx b/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx index fc62a3cb8060b7..4c0d90811517fb 100644 --- a/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx @@ -185,6 +185,7 @@ const EventsByDatasetComponent: React.FC = ({ setAbsoluteRangeDatePickerTarget={setAbsoluteRangeDatePickerTarget} setQuery={setQuery} showSpacer={showSpacer} + showInspectButton={false} showLegend={showLegend} skip={filterQuery === undefined} startDate={from} From 8da3cccf1751e734f15c6ad2a6c1458934687fd7 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 3 Mar 2022 21:09:19 +0800 Subject: [PATCH 17/59] fix unit tests --- .../public/common/components/top_n/index.test.tsx | 6 +++++- .../public/hosts/pages/details/details_tabs.test.tsx | 5 +++++ .../security_solution/public/hosts/pages/hosts.test.tsx | 5 +++++ .../security_solution/public/network/pages/network.test.tsx | 5 +++++ .../public/overview/pages/overview.test.tsx | 6 ++++++ .../components/side_panel/__snapshots__/index.test.tsx.snap | 2 ++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx index 83c05c28837238..86a59aa6706396 100644 --- a/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx @@ -38,7 +38,11 @@ jest.mock('react-router-dom', () => { jest.mock('../link_to'); jest.mock('../../lib/kibana'); jest.mock('../../../timelines/store/timeline/actions'); - +jest.mock('../visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); const field = 'process.name'; const value = 'nice'; diff --git a/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx b/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx index f2b0a64cbe60c5..3b0f3ffea3c204 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx @@ -54,6 +54,11 @@ jest.mock('../../../common/components/query_bar', () => ({ const mockUseResizeObserver: jest.Mock = useResizeObserver as jest.Mock; jest.mock('use-resize-observer/polyfilled'); mockUseResizeObserver.mockImplementation(() => ({})); +jest.mock('../../../common/components/visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); describe('body', () => { const scenariosMap = { diff --git a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx index 2305c2faad8adb..d176d1c502fe2c 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx @@ -35,6 +35,11 @@ jest.mock('../../common/components/search_bar', () => ({ jest.mock('../../common/components/query_bar', () => ({ QueryBar: () => null, })); +jest.mock('../../common/components/visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); type Action = 'PUSH' | 'POP' | 'REPLACE'; const pop: Action = 'POP'; diff --git a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx index e7f0d415b194b2..7d4cd1c3e6a5b9 100644 --- a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx @@ -35,6 +35,11 @@ jest.mock('../../common/components/search_bar', () => ({ jest.mock('../../common/components/query_bar', () => ({ QueryBar: () => null, })); +jest.mock('../../common/components/visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); type Action = 'PUSH' | 'POP' | 'REPLACE'; const pop: Action = 'POP'; diff --git a/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx b/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx index 0226617725e62e..254efe734a9a3c 100644 --- a/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx @@ -69,6 +69,12 @@ jest.mock('../../common/containers/local_storage/use_messages_storage'); jest.mock('../containers/overview_cti_links'); +jest.mock('../../common/components/visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); + const useCtiDashboardLinksMock = useCtiDashboardLinks as jest.Mock; useCtiDashboardLinksMock.mockReturnValue(mockCtiLinksResponse); diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap index 7324213975a742..5531a254d29747 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap @@ -505,6 +505,7 @@ Array [ "loading": false, "refetch": null, "selectedInspectIndex": 0, + "vizType": null, } } > @@ -789,6 +790,7 @@ Array [ "loading": false, "refetch": null, "selectedInspectIndex": 0, + "vizType": null, } } > From 3bc029fb0fa55483c6d2090c45364eb309941713 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 4 Mar 2022 00:15:21 +0800 Subject: [PATCH 18/59] unit tests --- .../common/components/matrix_histogram/index.tsx | 14 +++++++------- .../public/common/components/top_n/top_n.test.tsx | 5 +++++ .../public/common/store/inputs/helpers.ts | 15 ++++++++++++--- .../public/hosts/pages/hosts.tsx | 8 +++++--- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 7c6a70089db0c7..0acdd928579d8b 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -242,19 +242,19 @@ export const MatrixHistogramComponent: React.FC = timerange={timerange} getLensAttributes={getLensAttributes} > - {stackByOptions.length > 1 && ( - - + + + {stackByOptions.length > 1 && ( - - {headerChildren} - - )} + )} + + {headerChildren} + {isInitialLoading ? ( diff --git a/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx b/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx index c5a8e93145353b..c5ad4c297084d4 100644 --- a/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx @@ -29,6 +29,11 @@ jest.mock('react-router-dom', () => { jest.mock('../../lib/kibana'); jest.mock('../link_to'); +jest.mock('../visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); jest.mock('uuid', () => { return { diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts index 524a64fca0894f..7bf318855bfead 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts @@ -103,13 +103,22 @@ export const upsertQuery = ({ isInspected: state[inputId].queries[queryIndex].isInspected, loading, refetch, + vizType: null, selectedInspectIndex: state[inputId].queries[queryIndex].selectedInspectIndex, }, ...state[inputId].queries.slice(queryIndex + 1), ] : [ ...state[inputId].queries, - { id, inspect, isInspected: false, loading, refetch, selectedInspectIndex: 0 }, + { + id, + inspect, + isInspected: false, + loading, + refetch, + selectedInspectIndex: 0, + vizType: null, + }, ], }, }; @@ -121,7 +130,7 @@ export interface SetIsInspectedParams { isInspected: boolean; selectedInspectIndex: number; state: InputsModel; - vizType: string | null; + vizType?: string | null; } export const setIsInspected = ({ @@ -130,7 +139,7 @@ export const setIsInspected = ({ isInspected, selectedInspectIndex, state, - vizType, + vizType = null, }: SetIsInspectedParams): InputsModel => { const myQueryIndex = state[inputId].queries.findIndex((q) => q.id === id); const myQuery = myQueryIndex > -1 ? state[inputId].queries[myQueryIndex] : null; diff --git a/x-pack/plugins/security_solution/public/hosts/pages/hosts.tsx b/x-pack/plugins/security_solution/public/hosts/pages/hosts.tsx index f850ff4c630266..5ca7aa1f1dd497 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/hosts.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/hosts.tsx @@ -40,7 +40,6 @@ import { Display } from './display'; import { HostsTabs } from './hosts_tabs'; import { navTabsHosts } from './nav_tabs'; import * as i18n from './translations'; -import { filterHostData } from './navigation'; import { hostsModel, hostsSelectors } from '../store'; import { generateSeverityFilter } from '../store/helpers'; import { HostsTableType } from '../store/model'; @@ -56,6 +55,7 @@ import { useDeepEqualSelector, useShallowEqualSelector } from '../../common/hook import { useInvalidFilterQuery } from '../../common/hooks/use_invalid_filter_query'; import { ID } from '../containers/hosts'; import { useIsExperimentalFeatureEnabled } from '../../common/hooks/use_experimental_features'; +import { filterHostExternalAlertData } from '../../common/components/visualization_actions/utils'; /** * Need a 100% height here to account for the graph/analyze tool, which sets no explicit height parameters, but fills the available space. @@ -100,13 +100,15 @@ const HostsComponent = () => { const { tabName } = useParams<{ tabName: string }>(); const tabsFilters = React.useMemo(() => { if (tabName === HostsTableType.alerts) { - return filters.length > 0 ? [...filters, ...filterHostData] : filterHostData; + return filters.length > 0 + ? [...filters, ...filterHostExternalAlertData] + : filterHostExternalAlertData; } if (tabName === HostsTableType.risk) { const severityFilter = generateSeverityFilter(severitySelection); - return [...severityFilter, ...filterHostData, ...filters]; + return [...severityFilter, ...filterHostExternalAlertData, ...filters]; } return filters; }, [severitySelection, tabName, filters]); From 11f56a8e283e0dac5aba793a7c8a30ce3986a384 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 4 Mar 2022 02:34:08 +0800 Subject: [PATCH 19/59] unit tests --- .../components/hover_actions/actions/show_top_n.test.tsx | 6 ++++++ .../public/common/store/inputs/helpers.test.ts | 5 +++++ .../hosts/components/kpi_hosts/authentications/index.tsx | 2 +- ...uccess.ts => kpi_user_authentications_metric_success.ts} | 0 4 files changed, 12 insertions(+), 1 deletion(-) rename x-pack/plugins/security_solution/public/hosts/configs/{kpi_user_authentications-metric_success.ts => kpi_user_authentications_metric_success.ts} (100%) diff --git a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx index 06b90a129136b0..99ffe717cac432 100644 --- a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx @@ -10,6 +10,12 @@ import React from 'react'; import { TestProviders } from '../../../mock'; import { ShowTopNButton } from './show_top_n'; +jest.mock('../../visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); + describe('show topN button', () => { const defaultProps = { field: 'signal.rule.name', diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts index c8848e6f7ffc7f..74b8f4290cb37a 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts @@ -126,6 +126,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, + vizType: null, }); }); @@ -152,6 +153,7 @@ describe('Inputs', () => { loading: true, refetch, selectedInspectIndex: 0, + vizType: null, }); }); }); @@ -187,6 +189,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, + vizType: null, }); }); @@ -207,6 +210,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, + vizType: null, }); }); }); @@ -272,6 +276,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, + vizType: null, }, ], timerange: { diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx index 8fb33b89e1ddd4..de906a85f1e00a 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUserAuthenticationsMetricSuccess } from '../../../configs/kpi_user_authentications-metric_success'; +import { kpiUserAuthenticationsMetricSuccess } from '../../../configs/kpi_user_authentications_metric_success'; import { kpiUserAuthenticationsArea } from '../../../configs/kpi_user_authentications_area'; import { kpiUserAuthenticationsBar } from '../../../configs/kpi_user_authentications_bar'; import { kpiUserAuthenticationsMetricFailure } from '../../../configs/kpi_user_authentication_metric_failure'; diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts b/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_metric_success.ts similarity index 100% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications-metric_success.ts rename to x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_metric_success.ts From fc45201287c083bd5911429eb457cd363a3ff5fc Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 4 Mar 2022 03:03:07 +0800 Subject: [PATCH 20/59] rename vizType from store to inspectedVizType --- .../common/components/inspect/use_inspect.tsx | 24 +++++++++---------- .../public/common/store/inputs/actions.ts | 2 +- .../common/store/inputs/helpers.test.ts | 10 ++++---- .../public/common/store/inputs/helpers.ts | 10 ++++---- .../public/common/store/inputs/model.ts | 2 +- .../public/common/store/inputs/reducer.ts | 4 ++-- .../public/common/store/inputs/selectors.ts | 4 ++-- .../__snapshots__/index.test.tsx.snap | 6 ++--- 8 files changed, 30 insertions(+), 32 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx index 0197128e4e7f3c..8d4a67716d30da 100644 --- a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx +++ b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx @@ -37,15 +37,10 @@ export const useInspect = ({ const getGlobalQuery = inputsSelectors.globalQueryByIdSelector(); const getTimelineQuery = inputsSelectors.timelineQueryByIdSelector(); - const { - loading, - inspect, - selectedInspectIndex, - isInspected, - vizType: activeVizType, - } = useDeepEqualSelector((state) => - inputId === 'global' ? getGlobalQuery(state, queryId) : getTimelineQuery(state, queryId) - ); + const { loading, inspect, selectedInspectIndex, isInspected, inspectedVizType } = + useDeepEqualSelector((state) => + inputId === 'global' ? getGlobalQuery(state, queryId) : getTimelineQuery(state, queryId) + ); const handleClick = useCallback(() => { if (onClick) { @@ -57,7 +52,7 @@ export const useInspect = ({ inputId, isInspected: true, selectedInspectIndex: inspectIndex, - vizType, + inspectedVizType: vizType, }) ); }, [onClick, dispatch, queryId, inputId, inspectIndex, vizType]); @@ -72,7 +67,7 @@ export const useInspect = ({ inputId, isInspected: false, selectedInspectIndex: inspectIndex, - vizType: null, + inspectedVizType: null, }) ); }, [onCloseInspect, dispatch, queryId, inputId, inspectIndex]); @@ -99,8 +94,11 @@ export const useInspect = ({ const isShowingModal = useMemo( () => - !loading && selectedInspectIndex === inspectIndex && isInspected && activeVizType === vizType, - [activeVizType, vizType, inspectIndex, isInspected, loading, selectedInspectIndex] + !loading && + selectedInspectIndex === inspectIndex && + isInspected && + inspectedVizType === vizType, + [inspectedVizType, vizType, inspectIndex, isInspected, loading, selectedInspectIndex] ); const isButtonDisabled = useMemo( diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts b/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts index 33d699695dd9a8..dbb3d7910bbf2c 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/actions.ts @@ -65,7 +65,7 @@ export const setInspectionParameter = actionCreator<{ inputId: InputsModelId; isInspected: boolean; selectedInspectIndex: number; - vizType: string | null; + inspectedVizType: string | null; }>('SET_INSPECTION_PARAMETER'); export const deleteAllQuery = actionCreator<{ id: InputsModelId }>('DELETE_ALL_QUERY'); diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts index 74b8f4290cb37a..c2db80e87a05a5 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts @@ -126,7 +126,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }); }); @@ -153,7 +153,7 @@ describe('Inputs', () => { loading: true, refetch, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }); }); }); @@ -189,7 +189,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }); }); @@ -210,7 +210,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }); }); }); @@ -276,7 +276,7 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }, ], timerange: { diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts index 7bf318855bfead..24bc1ff02d0842 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts @@ -103,7 +103,7 @@ export const upsertQuery = ({ isInspected: state[inputId].queries[queryIndex].isInspected, loading, refetch, - vizType: null, + inspectedVizType: null, selectedInspectIndex: state[inputId].queries[queryIndex].selectedInspectIndex, }, ...state[inputId].queries.slice(queryIndex + 1), @@ -117,7 +117,7 @@ export const upsertQuery = ({ loading, refetch, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }, ], }, @@ -130,7 +130,7 @@ export interface SetIsInspectedParams { isInspected: boolean; selectedInspectIndex: number; state: InputsModel; - vizType?: string | null; + inspectedVizType?: string | null; } export const setIsInspected = ({ @@ -139,7 +139,7 @@ export const setIsInspected = ({ isInspected, selectedInspectIndex, state, - vizType = null, + inspectedVizType = null, }: SetIsInspectedParams): InputsModel => { const myQueryIndex = state[inputId].queries.findIndex((q) => q.id === id); const myQuery = myQueryIndex > -1 ? state[inputId].queries[myQueryIndex] : null; @@ -152,7 +152,7 @@ export const setIsInspected = ({ myQueryIndex > -1 ? [ ...state[inputId].queries.slice(0, myQueryIndex), - { ...myQuery, isInspected, selectedInspectIndex, vizType }, + { ...myQuery, isInspected, selectedInspectIndex, inspectedVizType }, ...state[inputId].queries.slice(myQueryIndex + 1), ] : [...state[inputId].queries], diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts index 40f818f23dd3df..9c0e033c37c598 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts @@ -62,7 +62,7 @@ export interface GlobalGenericQuery { loading: boolean; selectedInspectIndex: number; invalidKqlQuery?: Error; - vizType?: string | null; + inspectedVizType?: string | null; } export interface GlobalGraphqlQuery extends GlobalGenericQuery { diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts b/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts index 1b339e64b85787..80a30662395d55 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts @@ -220,8 +220,8 @@ export const inputsReducer = reducerWithInitialState(initialInputsState) .case(toggleTimelineLinkTo, (state, { linkToId }) => toggleLockTimeline(linkToId, state)) .case( setInspectionParameter, - (state, { id, inputId, isInspected, selectedInspectIndex, vizType }) => - setIsInspected({ id, inputId, isInspected, selectedInspectIndex, state, vizType }) + (state, { id, inputId, isInspected, selectedInspectIndex, inspectedVizType }) => + setIsInspected({ id, inputId, isInspected, selectedInspectIndex, state, inspectedVizType }) ) .case(removeGlobalLinkTo, (state) => removeGlobalLink(state)) .case(addGlobalLinkTo, (state, { linkToId }) => addGlobalLink(linkToId, state)) diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts b/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts index d6307f872d927d..4aebe1b8bc84e5 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts @@ -26,7 +26,7 @@ const selectGlobalQuery = (state: State, id: string): GlobalQuery => loading: false, refetch: null, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }; const selectTimelineQuery = (state: State, id: string): GlobalQuery => @@ -38,7 +38,7 @@ const selectTimelineQuery = (state: State, id: string): GlobalQuery => loading: false, refetch: null, selectedInspectIndex: 0, - vizType: null, + inspectedVizType: null, }; export const inputsSelector = () => createSelector(selectInputs, (inputs) => inputs); diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap index 5531a254d29747..fa051fb217cafe 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: +exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: @@ -790,7 +790,7 @@ Array [ "loading": false, "refetch": null, "selectedInspectIndex": 0, - "vizType": null, + "inspectedVizType": null, } } > From b22632f30890c538b387bdce5016f5a7582fbef3 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 4 Mar 2022 03:17:42 +0800 Subject: [PATCH 21/59] move out i18n --- .../visualization_actions/index.tsx | 33 ++++++---------- .../visualization_actions/translations.ts | 38 +++++++++++++++++-- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index ebacfb633531c6..530db00fb75c8e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -5,7 +5,6 @@ * 2.0. */ import { EuiButtonIcon, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n-react'; import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; import { @@ -23,6 +22,13 @@ import { useAddToExistingCase } from './use_add_to_existing_case'; import { useGetUserCasesPermissions } from '../../lib/kibana'; import { useAddToNewCase } from './use_add_to_new_case'; import { VisualizationActionsProps } from './types'; +import { + ADD_TO_EXISTING_CASE, + ADD_TO_NEW_CASE, + INSPECT, + OPEN_IN_LENS, + SAVE_VISUALIZATION, +} from './translations'; const Wrapper = styled.div` &.viz-actions { @@ -183,10 +189,7 @@ const VisualizationActionsComponent: React.FC = ({ disabled={disaledOpenInLens} onClick={onOpenInLens} > - + {OPEN_IN_LENS}
, = ({ disabled={!userCanCrud} onClick={onSaveVisualization} > - + {SAVE_VISUALIZATION} , = ({ disabled={disableInspectButton} data-test-subj="viz-actions-inspect" > - + {INSPECT} , = ({ onClick={onAddToNewCaseClicked} data-test-subj="viz-actions-add-to-new-case" > - + {ADD_TO_NEW_CASE} , = ({ key="visualizationActionsAddToExistingCase" onClick={onAddToExistingCaseClicked} > - + {ADD_TO_EXISTING_CASE} , ], [ diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts index 06109a09eb62e9..9239f38d709974 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n'; export const ADD_TO_CASE_SUCCESS = (caseTitle: string) => i18n.translate( - 'xpack.securitySolution.components.histogramActopms.addToCase.notificationSuccess', + 'xpack.securitySolution.components.visualizationActions.addToCase.notificationSuccess', { defaultMessage: 'Successfully added visualization to the case: {caseTitle}', values: { caseTitle }, @@ -17,15 +17,47 @@ export const ADD_TO_CASE_SUCCESS = (caseTitle: string) => ); export const ADD_TO_CASE_FAILURE = i18n.translate( - 'xpack.securitySolution.components.histogramActopms.addToCase.notificationFailure', + 'xpack.securitySolution.components.visualizationActions.addToCase.notificationFailure', { defaultMessage: 'Failed to add visualization to the selected case.', } ); export const VIEW_CASE = i18n.translate( - 'xpack.securitySolution.components.histogramActopms.addToCase.notification.viewCase', + 'xpack.securitySolution.components.visualizationActions.addToCase.notification.viewCase', { defaultMessage: 'View case', } ); + +export const INSPECT = i18n.translate('xpack.securitySolution.visualizationActions.inspect', { + defaultMessage: 'Inspect', +}); + +export const SAVE_VISUALIZATION = i18n.translate( + 'xpack.securitySolution.visualizationActions.saveVisualization', + { + defaultMessage: 'Save Visualization', + } +); + +export const OPEN_IN_LENS = i18n.translate( + 'xpack.securitySolution.visualizationActions.openInLens', + { + defaultMessage: 'Open in Lens', + } +); + +export const ADD_TO_NEW_CASE = i18n.translate( + 'xpack.securitySolution.visualizationActions.addToNewCase', + { + defaultMessage: 'Add to new Case', + } +); + +export const ADD_TO_EXISTING_CASE = i18n.translate( + 'xpack.securitySolution.visualizationActions.addToExistingCase', + { + defaultMessage: 'Add to Existing Case', + } +); From f5b3ff318beba027e5fd1f759c2795eac5e84c63 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 4 Mar 2022 18:03:37 +0800 Subject: [PATCH 22/59] unit test --- .../components/side_panel/__snapshots__/index.test.tsx.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap index fa051fb217cafe..ca1de4655eaeb0 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: +exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: @@ -786,11 +786,11 @@ Array [ Object { "id": "", "inspect": null, + "inspectedVizType": null, "isInspected": false, "loading": false, "refetch": null, "selectedInspectIndex": 0, - "inspectedVizType": null, } } > From b7656f58eef648f29986f7002d68f2fe1b763da7 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 4 Mar 2022 22:52:33 +0800 Subject: [PATCH 23/59] add index filter --- .../use_lens_attributes.tsx | 34 ++++++++++++------- .../components/visualization_actions/utils.ts | 28 +++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx index 25e1c90de90319..91ef076da7a72d 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx @@ -17,6 +17,7 @@ import { getHostDetailsPageFilter, filterNetworkExternalAlertData, filterHostExternalAlertData, + getIndexFilters, } from './utils'; export const useLensAttributes = ({ @@ -28,7 +29,7 @@ export const useLensAttributes = ({ getLensAttributes?: GetLensAttributes; stackByField?: string; }): LensAttributes | null => { - const { dataViewId } = useSourcererDataView(); + const { selectedPatterns, dataViewId } = useSourcererDataView(); const getGlobalQuerySelector = useMemo(() => inputsSelectors.globalQuerySelector(), []); const getGlobalFiltersQuerySelector = useMemo( () => inputsSelectors.globalFiltersQuerySelector(), @@ -40,29 +41,27 @@ export const useLensAttributes = ({ const location = useLocation(); const tabsFilters = useMemo(() => { if (location.pathname.includes(SecurityPageName.hosts) && tabName === 'externalAlerts') { - return filters.length > 0 - ? [...filters, ...filterHostExternalAlertData] - : filterHostExternalAlertData; + return filterHostExternalAlertData; } if ( location.pathname.includes(SecurityPageName.network) && tabName === NetworkRouteType.alerts ) { - return filters.length > 0 - ? [...filters, ...filterNetworkExternalAlertData] - : filterNetworkExternalAlertData; + return filterNetworkExternalAlertData; } - return filters; - }, [tabName, location.pathname, filters]); + return []; + }, [tabName, location.pathname]); const pageFilters = useMemo(() => { if (location.pathname.includes(SecurityPageName.hosts) && detailName != null) { - return [...filters, ...getHostDetailsPageFilter(detailName)]; + return getHostDetailsPageFilter(detailName); } - return filters; - }, [location.pathname, detailName, filters]); + return []; + }, [location.pathname, detailName]); + + const indexFilters = useMemo(() => getIndexFilters(selectedPatterns), [selectedPatterns]); const lensAttrsWithInjectedData = useMemo(() => { if (lensAttributes == null && (getLensAttributes == null || stackByField == null)) { @@ -71,12 +70,19 @@ export const useLensAttributes = ({ const attrs: LensAttributes = lensAttributes ?? ((getLensAttributes && stackByField && getLensAttributes(stackByField)) as LensAttributes); + return { ...attrs, state: { ...attrs.state, query, - filters: [...attrs.state.filters, ...pageFilters, ...tabsFilters], + filters: [ + ...attrs.state.filters, + ...filters, + ...pageFilters, + ...tabsFilters, + ...indexFilters, + ], }, references: attrs.references.map((ref: { id: string; name: string; type: string }) => ({ ...ref, @@ -88,8 +94,10 @@ export const useLensAttributes = ({ getLensAttributes, stackByField, query, + filters, pageFilters, tabsFilters, + indexFilters, dataViewId, ]); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts index 9f86ece7dd7e40..4fc604ac3629fc 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts @@ -118,6 +118,34 @@ export const filterNetworkExternalAlertData: Filter[] = [ }, ]; +export const getIndexFilters = (selectedPatterns: string[]) => + selectedPatterns.length >= 1 + ? [ + { + meta: { + index: '62d8e968-7ce3-4062-98b8-64b0e0bbff59', + type: 'phrases', + key: '_index', + params: selectedPatterns, + alias: null, + negate: false, + disabled: false, + }, + query: { + bool: { + should: selectedPatterns.map((selectedPattern) => ({ + match_phrase: { _index: selectedPattern }, + })), + minimum_should_match: 1, + }, + }, + $state: { + store: 'appState', + }, + }, + ] + : []; + export const addToCase = async ( http: HttpSetup, theCase: Case, From 356d132d4459673b416e9077670b4378599f017a Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Sat, 5 Mar 2022 01:39:15 +0800 Subject: [PATCH 24/59] clean up configs --- .../alerts_viewer/histogram_configs.ts | 2 +- .../configs/common}/external_alert.ts | 7 +- .../configs/hosts}/authentication.ts | 2 +- .../configs/hosts}/events.ts | 5 +- .../configs/hosts}/kpi_host_area.ts | 2 +- .../configs/hosts}/kpi_host_metric.ts | 2 +- .../configs/hosts}/kpi_unique_ips_area.ts | 7 +- .../configs/hosts}/kpi_unique_ips_bar.ts | 7 +- .../kpi_unique_ips_destination_metric.ts | 2 +- .../hosts}/kpi_unique_ips_source_metric.ts | 2 +- .../kpi_user_authentication_metric_failure.ts | 2 +- .../hosts}/kpi_user_authentications_area.ts | 2 +- .../hosts}/kpi_user_authentications_bar.ts | 7 +- ...kpi_user_authentications_metric_success.ts | 2 +- .../configs/network}/dns_top_domains.ts | 2 +- .../configs/network/kpi_dns_queries.ts | 105 +++++++++++++ .../configs/network}/kpi_network_events.ts | 2 +- .../configs/network/kpi_tls_handshakes.ts | 129 ++++++++++++++++ .../configs/network}/kpi_unique_flow_ids.ts | 37 ++++- .../network}/kpi_unique_private_ips_area.ts | 2 +- .../network}/kpi_unique_private_ips_bar.ts | 142 ++++++++++++++++-- ...i_unique_private_ips_destination_metric.ts | 13 +- .../kpi_unique_private_ips_source_metric.ts | 13 +- .../visualization_actions/translations.ts | 42 ++++++ .../kpi_hosts/authentications/index.tsx | 8 +- .../components/kpi_hosts/hosts/index.tsx | 4 +- .../components/kpi_hosts/unique_ips/index.tsx | 8 +- .../authentications_query_tab_body.tsx | 6 +- .../navigation/events_query_tab_body.tsx | 2 +- .../components/kpi_network/dns/index.tsx | 2 +- .../network/components/kpi_network/mock.ts | 8 +- .../kpi_network/network_events/index.tsx | 2 +- .../kpi_network/tls_handshakes/index.tsx | 2 +- .../kpi_network/unique_flows/index.tsx | 2 +- .../kpi_network/unique_private_ips/index.tsx | 8 +- .../public/network/configs/kpi_dns_queries.ts | 60 -------- .../network/configs/kpi_tls_handshakes.ts | 59 -------- .../pages/navigation/dns_query_tab_body.tsx | 2 +- 38 files changed, 508 insertions(+), 203 deletions(-) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/common}/external_alert.ts (96%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/authentication.ts (98%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/events.ts (97%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_host_area.ts (97%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_host_metric.ts (95%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_unique_ips_area.ts (95%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_unique_ips_bar.ts (95%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_unique_ips_destination_metric.ts (95%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_unique_ips_source_metric.ts (95%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_user_authentication_metric_failure.ts (96%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_user_authentications_area.ts (98%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_user_authentications_bar.ts (96%) rename x-pack/plugins/security_solution/public/{hosts/configs => common/components/visualization_actions/configs/hosts}/kpi_user_authentications_metric_success.ts (96%) rename x-pack/plugins/security_solution/public/{network/configs => common/components/visualization_actions/configs/network}/dns_top_domains.ts (98%) create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts rename x-pack/plugins/security_solution/public/{network/configs => common/components/visualization_actions/configs/network}/kpi_network_events.ts (96%) create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts rename x-pack/plugins/security_solution/public/{network/configs => common/components/visualization_actions/configs/network}/kpi_unique_flow_ids.ts (65%) rename x-pack/plugins/security_solution/public/{network/configs => common/components/visualization_actions/configs/network}/kpi_unique_private_ips_area.ts (98%) rename x-pack/plugins/security_solution/public/{network/configs => common/components/visualization_actions/configs/network}/kpi_unique_private_ips_bar.ts (50%) rename x-pack/plugins/security_solution/public/{network/configs => common/components/visualization_actions/configs/network}/kpi_unique_private_ips_destination_metric.ts (78%) rename x-pack/plugins/security_solution/public/{network/configs => common/components/visualization_actions/configs/network}/kpi_unique_private_ips_source_metric.ts (80%) delete mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts delete mode 100644 x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts index bc31cdc55f1610..f350cf6b33049f 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts +++ b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts @@ -8,7 +8,7 @@ import * as i18n from './translations'; import { MatrixHistogramOption, MatrixHistogramConfigs } from '../matrix_histogram/types'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution/matrix_histogram'; -import { getExternalAlertConfigs } from '../../../hosts/configs/external_alert'; +import { getExternalAlertConfigs } from '../visualization_actions/configs/common/external_alert'; export const alertsStackByOptions: MatrixHistogramOption[] = [ { diff --git a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts similarity index 96% rename from x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts index 520a5fcb2465b5..082629372c818a 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/external_alert.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts @@ -5,14 +5,11 @@ * 2.0. */ -import { - GetLensAttributes, - LensAttributes, -} from '../../common/components/visualization_actions/types'; +import { GetLensAttributes, LensAttributes } from '../../types'; export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event.module') => { return { - title: 'external alerts', + title: 'External alerts', description: '', visualizationType: 'lnsXY', state: { diff --git a/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts similarity index 98% rename from x-pack/plugins/security_solution/public/hosts/configs/authentication.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts index 839756b2e7eb97..0c75e7a83c09c5 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/authentication.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const authentication: LensAttributes = { title: 'Authentication', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/events.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts similarity index 97% rename from x-pack/plugins/security_solution/public/hosts/configs/events.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts index c5ff8c02d74766..2c5a6d211dff7b 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/events.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts @@ -5,10 +5,7 @@ * 2.0. */ -import { - GetLensAttributes, - LensAttributes, -} from '../../common/components/visualization_actions/types'; +import { GetLensAttributes, LensAttributes } from '../../types'; export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'event.action') => ({ diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts similarity index 97% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts index 17167b4ed88b82..fdcb620f4da38b 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiHostArea: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts similarity index 95% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts index 3cc50c9ac6a18a..dbfdd5a9d6f7ee 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_host_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiHostMetric: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts similarity index 95% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts index 0de00f856f3816..37a27cf7266a64 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts @@ -5,11 +5,8 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; -import { - DESTINATION_CHART_LABEL, - SOURCE_CHART_LABEL, -} from '../components/kpi_hosts/unique_ips/translations'; +import { DESTINATION_CHART_LABEL, SOURCE_CHART_LABEL } from '../../translations'; +import { LensAttributes } from '../../types'; export const kpiUniqueIpsArea: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts similarity index 95% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_bar.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts index a9ce0c5788063a..f9403e2d574094 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts @@ -5,11 +5,8 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; -import { - SOURCE_CHART_LABEL, - DESTINATION_CHART_LABEL, -} from '../components/kpi_hosts/unique_ips/translations'; +import { LensAttributes } from '../../types'; +import { SOURCE_CHART_LABEL, DESTINATION_CHART_LABEL } from '../../translations'; export const kpiUniqueIpsBar: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts similarity index 95% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_destination_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts index 543d21c6ae8caf..0ca6eb2e1c9ab9 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiUniqueIpsDestinationMetric: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts similarity index 95% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_source_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts index 07af9ef38091d3..dcf30e7662df02 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_unique_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiUniqueIpsSourceMetric: LensAttributes = { description: '', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts similarity index 96% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts index 622a78515eb13c..6e95e19faa933c 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentication_metric_failure.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiUserAuthenticationsMetricFailure: LensAttributes = { title: '[Host] KPI User authentications - metric failure ', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts similarity index 98% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts index 481dd75cb69cd8..94382cb2029af0 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiUserAuthenticationsArea: LensAttributes = { title: '[Host] KPI User authentications - area ', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts similarity index 96% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts index c8c1a466ce07d0..aa2255fe813a46 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts @@ -5,11 +5,8 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; -import { - FAIL_CHART_LABEL, - SUCCESS_CHART_LABEL, -} from '../components/kpi_hosts/authentications/translations'; +import { LensAttributes } from '../../types'; +import { FAIL_CHART_LABEL, SUCCESS_CHART_LABEL } from '../../translations'; export const kpiUserAuthenticationsBar: LensAttributes = { title: '[Host] KPI User authentications - bar ', diff --git a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_metric_success.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts similarity index 96% rename from x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_metric_success.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts index 997d63d8834e42..34e469a2f00919 100644 --- a/x-pack/plugins/security_solution/public/hosts/configs/kpi_user_authentications_metric_success.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiUserAuthenticationsMetricSuccess: LensAttributes = { title: '[Host] KPI User authentications - metric success ', diff --git a/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts similarity index 98% rename from x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts index 452fe7cf32f29e..8c7d85626a16e9 100644 --- a/x-pack/plugins/security_solution/public/network/configs/dns_top_domains.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; /* Exported from Kibana Saved Object */ export const dnsTopDomainsAttrs: LensAttributes = { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts new file mode 100644 index 00000000000000..db0ac37ce7f8a5 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts @@ -0,0 +1,105 @@ +/* + * 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 { LensAttributes } from '../../types'; + +export const kpiDnsQueries: LensAttributes = { + title: '[Network] KPI DNS metric', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + layerId: 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + accessor: '0374e520-eae0-4ac1-bcfe-37565e7fc9e3', + layerType: 'data', + colorMode: 'None', + }, + query: { + query: '', + language: 'kuery', + }, + filters: [ + { + meta: { + index: '196d783b-3779-4c39-898e-6606fe633d05', + type: 'custom', + disabled: false, + negate: false, + alias: null, + key: 'query', + value: + '{"bool":{"should":[{"exists":{"field":"dns.question.name"}},{"term":{"suricata.eve.dns.type":{"value":"query"}}},{"exists":{"field":"zeek.dns.query"}}],"minimum_should_match":1}}', + }, + $state: { + store: 'appState', + }, + query: { + bool: { + should: [ + { + exists: { + field: 'dns.question.name', + }, + }, + { + term: { + 'suricata.eve.dns.type': { + value: 'query', + }, + }, + }, + { + exists: { + field: 'zeek.dns.query', + }, + }, + ], + minimum_should_match: 1, + }, + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3': { + columns: { + '0374e520-eae0-4ac1-bcfe-37565e7fc9e3': { + label: 'DNS', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + customLabel: true, + }, + }, + columnOrder: ['0374e520-eae0-4ac1-bcfe-37565e7fc9e3'], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', + }, + { + type: 'index-pattern', + name: '196d783b-3779-4c39-898e-6606fe633d05', + id: 'security-solution-default', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts similarity index 96% rename from x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts index a79fd529a03ad7..8b1e054140304e 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_network_events.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiNetworkEvents: LensAttributes = { title: '[Network] KPI Network events', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts new file mode 100644 index 00000000000000..b0a9ae7cf0a1b9 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts @@ -0,0 +1,129 @@ +/* + * 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 { LensAttributes } from '../../types'; + +export const kpiTlsHandshakes: LensAttributes = { + title: '[Network] KPI TLS handshakes', + description: '', + visualizationType: 'lnsMetric', + state: { + visualization: { + layerId: '1f48a633-8eee-45ae-9471-861227e9ca03', + accessor: '21052b6b-5504-4084-a2e2-c17f772345cf', + layerType: 'data', + }, + query: { + query: + '(source.ip: * or destination.ip: *) and (tls.version: * or suricata.eve.tls.version: * or zeek.ssl.version: * )', + language: 'kuery', + }, + filters: [ + { + meta: { + index: '32ee22d9-2e77-4aee-8073-87750e92c3ee', + type: 'custom', + disabled: false, + negate: false, + alias: null, + key: 'query', + value: + '{"bool":{"should":[{"exists":{"field":"source.ip"}},{"exists":{"field":"destination.ip"}}],"minimum_should_match":1}}', + }, + $state: { + store: 'appState', + }, + query: { + bool: { + should: [ + { + exists: { + field: 'source.ip', + }, + }, + { + exists: { + field: 'destination.ip', + }, + }, + ], + minimum_should_match: 1, + }, + }, + }, + { + meta: { + index: '1e93f984-9374-4755-a198-de57751533c6', + type: 'custom', + disabled: false, + negate: false, + alias: null, + key: 'query', + value: + '{"bool":{"should":[{"exists":{"field":"tls.version"}},{"exists":{"field":"suricata.eve.tls.version"}},{"exists":{"field":"zeek.ssl.version"}}],"minimum_should_match":1}}', + }, + $state: { + store: 'appState', + }, + query: { + bool: { + should: [ + { + exists: { + field: 'tls.version', + }, + }, + { + exists: { + field: 'suricata.eve.tls.version', + }, + }, + { + exists: { + field: 'zeek.ssl.version', + }, + }, + ], + minimum_should_match: 1, + }, + }, + }, + ], + datasourceStates: { + indexpattern: { + layers: { + '1f48a633-8eee-45ae-9471-861227e9ca03': { + columns: { + '21052b6b-5504-4084-a2e2-c17f772345cf': { + label: ' ', + dataType: 'number', + operationType: 'count', + isBucketed: false, + scale: 'ratio', + sourceField: '___records___', + customLabel: true, + }, + }, + columnOrder: ['21052b6b-5504-4084-a2e2-c17f772345cf'], + incompleteColumns: {}, + }, + }, + }, + }, + }, + references: [ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-1f48a633-8eee-45ae-9471-861227e9ca03', + }, + ], +} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts similarity index 65% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts index 8db0e884f05824..136a44a86df047 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_flow_ids.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiUniqueFlowIds: LensAttributes = { title: '[Network] KPI Unique flow IDs', @@ -21,7 +21,40 @@ export const kpiUniqueFlowIds: LensAttributes = { query: 'source.ip: * or destination.ip: * ', language: 'kuery', }, - filters: [], + filters: [ + { + meta: { + index: 'c01edc8a-90ce-4d49-95f0-76954a034eb2', + type: 'custom', + disabled: false, + negate: false, + alias: null, + key: 'query', + value: + '{"bool":{"should":[{"exists":{"field":"source.ip"}},{"exists":{"field":"destination.ip"}}],"minimum_should_match":1}}', + }, + $state: { + store: 'appState', + }, + query: { + bool: { + should: [ + { + exists: { + field: 'source.ip', + }, + }, + { + exists: { + field: 'destination.ip', + }, + }, + ], + minimum_should_match: 1, + }, + }, + }, + ], datasourceStates: { indexpattern: { layers: { diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts similarity index 98% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts index 4e76ea3facb1e6..5a90246f3f47ad 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { LensAttributes } from '../../types'; export const kpiUniquePrivateIpsArea: LensAttributes = { title: '[Network] KPI Unique private IPs - area chart', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts similarity index 50% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_bar.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts index 290aa2344935d9..24d36efd50cbd1 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts @@ -5,13 +5,10 @@ * 2.0. */ -import { - SOURCE_CHART_LABEL, - DESTINATION_CHART_LABEL, -} from '../components/kpi_network/unique_private_ips/translations'; -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { SOURCE_CHART_LABEL, DESTINATION_CHART_LABEL } from '../../translations'; +import { LensAttributes } from '../../types'; -export const kpiUniquePrivateIpsBar = { +export const kpiUniquePrivateIpsBar: LensAttributes = { title: '[Network] KPI Unique private IPs - bar chart', description: '', visualizationType: 'lnsXY', @@ -95,14 +92,13 @@ export const kpiUniquePrivateIpsBar = { '5acd4c9d-dc3b-4b21-9632-e4407944c36d': { label: SOURCE_CHART_LABEL, dataType: 'number', + isBucketed: false, operationType: 'unique_count', scale: 'ratio', sourceField: 'source.ip', - isBucketed: false, - customLabel: true, filter: { query: - '"source.ip": "10.0.0.0/8" or "source.ip": "192.168.0.0/16" or "source.ip": "172.16.0.0/12" or "source.ip": "fd00::/8"', + 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', language: 'kuery', }, }, @@ -136,11 +132,10 @@ export const kpiUniquePrivateIpsBar = { 'd27e0966-daf9-41f4-9033-230cf1e76dc9': { label: DESTINATION_CHART_LABEL, dataType: 'number', + isBucketed: false, operationType: 'unique_count', scale: 'ratio', sourceField: 'destination.ip', - isBucketed: false, - customLabel: true, filter: { query: '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', @@ -193,4 +188,129 @@ export const kpiUniquePrivateIpsBar = { name: 'indexpattern-datasource-layer-38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7', }, ], + + // description: '', + // state: { + // datasourceStates: { + // indexpattern: { + // layers: { + // '8be0156b-d423-4a39-adf1-f54d4c9f2e69': { + // columnOrder: [ + // 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e', + // '32f66676-f4e1-48fd-b7f8-d4de38318601', + // ], + // columns: { + // '32f66676-f4e1-48fd-b7f8-d4de38318601': { + // dataType: 'number', + // filter: { + // language: 'kuery', + // query: + // 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', + // }, + // isBucketed: false, + // label: 'Unique count of source.ip', + // operationType: 'unique_count', + // scale: 'ratio', + // sourceField: 'source.ip', + // }, + // 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e': { + // dataType: 'string', + // isBucketed: true, + // label: 'Filters', + // operationType: 'filters', + // params: { filters: [{ input: { language: 'kuery', query: '' }, label: 'Src.' }] }, + // scale: 'ordinal', + // }, + // }, + // incompleteColumns: {}, + // }, + // 'ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e': { + // columnOrder: [ + // 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff', + // 'b7e59b08-96e6-40d1-84fd-e97b977d1c47', + // ], + // columns: { + // 'b7e59b08-96e6-40d1-84fd-e97b977d1c47': { + // dataType: 'number', + // filter: { + // language: 'kuery', + // query: + // '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', + // }, + // isBucketed: false, + // label: 'Unique count of destination.ip', + // operationType: 'unique_count', + // scale: 'ratio', + // sourceField: 'destination.ip', + // }, + // 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff': { + // customLabel: true, + // dataType: 'string', + // isBucketed: true, + // label: 'Dest.', + // operationType: 'filters', + // params: { + // filters: [{ input: { language: 'kuery', query: '' }, label: 'Dest.' }], + // }, + // scale: 'ordinal', + // }, + // }, + // incompleteColumns: {}, + // }, + // }, + // }, + // }, + // filters: [], + // query: { language: 'kuery', query: '' }, + // visualization: { + // axisTitlesVisibilitySettings: { x: false, yLeft: false, yRight: true }, + // fittingFunction: 'None', + // gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true }, + // labelsOrientation: { x: 0, yLeft: 0, yRight: 0 }, + // layers: [ + // { + // accessors: ['32f66676-f4e1-48fd-b7f8-d4de38318601'], + // layerId: '8be0156b-d423-4a39-adf1-f54d4c9f2e69', + // layerType: 'data', + // seriesType: 'bar_horizontal_stacked', + // xAccessor: 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e', + // yConfig: [{ color: '#d36186', forAccessor: '32f66676-f4e1-48fd-b7f8-d4de38318601' }], + // }, + // { + // accessors: ['b7e59b08-96e6-40d1-84fd-e97b977d1c47'], + // layerId: 'ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e', + // layerType: 'data', + // seriesType: 'bar_horizontal_stacked', + // xAccessor: 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff', + // yConfig: [{ color: '#9170b8', forAccessor: 'b7e59b08-96e6-40d1-84fd-e97b977d1c47' }], + // }, + // ], + // legend: { isVisible: false, position: 'right', showSingleSeries: false }, + // preferredSeriesType: 'bar_horizontal_stacked', + // tickLabelsVisibilitySettings: { x: true, yLeft: true, yRight: true }, + // valueLabels: 'hide', + // yLeftExtent: { mode: 'full' }, + // yRightExtent: { mode: 'full' }, + // }, + // }, + // title: '[Host] KPI Unique IPs - bar', + // visualizationType: 'lnsXY', + // references: [ + // { + // id: 'security-solution-default', + // name: 'indexpattern-datasource-current-indexpattern', + // type: 'index-pattern', + // }, + // { + // id: 'security-solution-default', + // name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', + // type: 'index-pattern', + // }, + // { + // id: 'security-solution-default', + // name: 'indexpattern-datasource-layer-ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e', + // type: 'index-pattern', + // }, + // { id: 'security-solution-default', name: 'tag-ref-security-solution-default', type: 'tag' }, + // ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts similarity index 78% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts index b5e02bc875c714..66a035f36cd186 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { DESTINATION_CHART_LABEL } from '../../translations'; +import { LensAttributes } from '../../types'; export const kpiUniquePrivateIpsDestinationMetric: LensAttributes = { description: '', @@ -20,10 +21,15 @@ export const kpiUniquePrivateIpsDestinationMetric: LensAttributes = { customLabel: true, dataType: 'number', isBucketed: false, - label: ' ', + label: DESTINATION_CHART_LABEL, operationType: 'unique_count', scale: 'ratio', sourceField: 'destination.ip', + filter: { + language: 'kuery', + query: + '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', + }, }, }, incompleteColumns: {}, @@ -34,8 +40,7 @@ export const kpiUniquePrivateIpsDestinationMetric: LensAttributes = { filters: [], query: { language: 'kuery', - query: - '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', + query: '', }, visualization: { accessor: 'bd17c23e-4f83-4108-8005-2669170d064b', diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts similarity index 80% rename from x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_source_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts index 751dee806789bc..bf252cba37a7e9 100644 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_unique_private_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts @@ -4,7 +4,8 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LensAttributes } from '../../common/components/visualization_actions/types'; +import { SOURCE_CHART_LABEL } from '../../translations'; +import { LensAttributes } from '../../types'; export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { description: '', @@ -19,10 +20,15 @@ export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { customLabel: true, dataType: 'number', isBucketed: false, - label: ' ', + label: SOURCE_CHART_LABEL, operationType: 'unique_count', scale: 'ratio', sourceField: 'source.ip', + filter: { + query: + 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', + language: 'kuery', + }, }, }, incompleteColumns: {}, @@ -33,8 +39,7 @@ export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { filters: [], query: { language: 'kuery', - query: - 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', + query: '', }, visualization: { accessor: 'bd17c23e-4f83-4108-8005-2669170d064b', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts index 9239f38d709974..3abf4d5e41f5ca 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts @@ -61,3 +61,45 @@ export const ADD_TO_EXISTING_CASE = i18n.translate( defaultMessage: 'Add to Existing Case', } ); + +export const SOURCE_CHART_LABEL = i18n.translate( + 'xpack.securitySolution.visualizationActions.uniqueIps.sourceChartLabel', + { + defaultMessage: 'Src.', + } +); + +export const DESTINATION_CHART_LABEL = i18n.translate( + 'xpack.securitySolution.visualizationActions.uniqueIps.destinationChartLabel', + { + defaultMessage: 'Dest.', + } +); + +export const SUCCESS_CHART_LABEL = i18n.translate( + 'xpack.securitySolution.visualizationActions.userAuthentications.successChartLabel', + { + defaultMessage: 'Succ.', + } +); + +export const FAIL_CHART_LABEL = i18n.translate( + 'xpack.securitySolution.visualizationActions.userAuthentications.failChartLabel', + { + defaultMessage: 'Fail', + } +); + +export const SUCCESS_UNIT_LABEL = i18n.translate( + 'xpack.securitySolution.visualizationActions.userAuthentications.successUnitLabel', + { + defaultMessage: 'success', + } +); + +export const FAIL_UNIT_LABEL = i18n.translate( + 'xpack.securitySolution.visualizationActions.userAuthentications.failUnitLabel', + { + defaultMessage: 'fail', + } +); diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx index de906a85f1e00a..8d16a686d7ac6d 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx @@ -8,10 +8,10 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUserAuthenticationsMetricSuccess } from '../../../configs/kpi_user_authentications_metric_success'; -import { kpiUserAuthenticationsArea } from '../../../configs/kpi_user_authentications_area'; -import { kpiUserAuthenticationsBar } from '../../../configs/kpi_user_authentications_bar'; -import { kpiUserAuthenticationsMetricFailure } from '../../../configs/kpi_user_authentication_metric_failure'; +import { kpiUserAuthenticationsArea } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentications_area'; +import { kpiUserAuthenticationsBar } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar'; +import { kpiUserAuthenticationsMetricSuccess } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success'; +import { kpiUserAuthenticationsMetricFailure } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure'; import { useHostsKpiAuthentications } from '../../../containers/kpi_hosts/authentications'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx index e46133e71e5efc..25f09d7a504bd8 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx @@ -8,8 +8,8 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiHostArea } from '../../../configs/kpi_host_area'; -import { kpiHostMetric } from '../../../configs/kpi_host_metric'; +import { kpiHostArea } from '../../../../common/components/visualization_actions/configs/hosts/kpi_host_area'; +import { kpiHostMetric } from '../../../../common/components/visualization_actions/configs/hosts/kpi_host_metric'; import { useHostsKpiHosts } from '../../../containers/kpi_hosts/hosts'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx index e1a0676edcd314..52587a12d8c49d 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx @@ -8,10 +8,10 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUniqueIpsArea } from '../../../configs/kpi_unique_ips_area'; -import { kpiUniqueIpsBar } from '../../../configs/kpi_unique_ips_bar'; -import { kpiUniqueIpsDestinationMetric } from '../../../configs/kpi_unique_ips_destination_metric'; -import { kpiUniqueIpsSourceMetric } from '../../../configs/kpi_unique_ips_source_metric'; +import { kpiUniqueIpsArea } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_area'; +import { kpiUniqueIpsBar } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar'; +import { kpiUniqueIpsDestinationMetric } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric'; +import { kpiUniqueIpsSourceMetric } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric'; import { useHostsKpiUniqueIps } from '../../../containers/kpi_hosts/unique_ips'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx index 4dc7dad70245b9..1b270804a82375 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx @@ -20,8 +20,8 @@ import { MatrixHistogram } from '../../../common/components/matrix_histogram'; import { HostsKpiChartColors } from '../../components/kpi_hosts/types'; import * as i18n from '../translations'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; -import { authentication } from '../../configs/authentication'; -import { TypedLensByValueInput } from '../../../../../lens/public'; +import { authentication } from '../../../common/components/visualization_actions/configs/hosts/authentication'; +import { LensAttributes } from '../../../common/components/visualization_actions/types'; const AuthenticationTableManage = manageQuery(AuthenticationTable); @@ -62,7 +62,7 @@ const histogramConfigs: MatrixHistogramConfigs = { mapping: authenticationsMatrixDataMappingFields, stackByOptions: authenticationsStackByOptions, title: i18n.NAVIGATION_AUTHENTICATIONS_TITLE, - lensAttributes: authentication as TypedLensByValueInput['attributes'], + lensAttributes: authentication as LensAttributes, }; const AuthenticationsQueryTabBodyComponent: React.FC = ({ diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx index 9e0b227550dd42..8b4391032e5a5d 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx @@ -28,7 +28,7 @@ import { SourcererScopeName } from '../../../common/store/sourcerer/model'; import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features'; import { DEFAULT_COLUMN_MIN_WIDTH } from '../../../timelines/components/timeline/body/constants'; import { defaultCellActions } from '../../../common/lib/cell_actions/default_cell_actions'; -import { getEventsHistogramCongifs } from '../../configs/events'; +import { getEventsHistogramCongifs } from '../../../common/components/visualization_actions/configs/hosts/events'; const EVENTS_HISTOGRAM_ID = 'eventsHistogramQuery'; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx index da78e33dfd95db..c478025fd2e93b 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiDnsQueries } from '../../../configs/kpi_dns_queries'; +import { kpiDnsQueries } from '../../../../common/components/visualization_actions/configs/network/kpi_dns_queries'; import { useNetworkKpiDns } from '../../../containers/kpi_network/dns'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts b/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts index b741f8c3ffcabe..faed630b4d29c1 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts @@ -7,10 +7,10 @@ import { NetworkKpiStrategyResponse } from '../../../../common/search_strategy'; import { StatItems } from '../../../common/components/stat_items'; -import { kpiUniquePrivateIpsArea } from '../../configs/kpi_unique_private_ips_area'; -import { kpiUniquePrivateIpsBar } from '../../configs/kpi_unique_private_ips_bar'; -import { kpiUniquePrivateIpsDestinationMetric } from '../../configs/kpi_unique_private_ips_destination_metric'; -import { kpiUniquePrivateIpsSourceMetric } from '../../configs/kpi_unique_private_ips_source_metric'; +import { kpiUniquePrivateIpsArea } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_area'; +import { kpiUniquePrivateIpsBar } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar'; +import { kpiUniquePrivateIpsDestinationMetric } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric'; +import { kpiUniquePrivateIpsSourceMetric } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric'; export const mockNarrowDateRange = jest.fn(); diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx index eee292359389d2..0e267673c4891f 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx @@ -13,7 +13,7 @@ import { useNetworkKpiNetworkEvents } from '../../../containers/kpi_network/netw import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; import * as i18n from './translations'; -import { kpiNetworkEvents } from '../../../configs/kpi_network_events'; +import { kpiNetworkEvents } from '../../../../common/components/visualization_actions/configs/network/kpi_network_events'; const euiVisColorPalette = euiPaletteColorBlind(); const euiColorVis1 = euiVisColorPalette[1]; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx index 8061dc368af310..dc5f55b1271421 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiTlsHandshakes } from '../../../configs/kpi_tls_handshakes'; +import { kpiTlsHandshakes } from '../../../../common/components/visualization_actions/configs/network/kpi_tls_handshakes'; import { useNetworkKpiTlsHandshakes } from '../../../containers/kpi_network/tls_handshakes'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx index a9aeacfd3a7038..8f7d96197c6340 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUniqueFlowIds } from '../../../configs/kpi_unique_flow_ids'; +import { kpiUniqueFlowIds } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_flow_ids'; import { useNetworkKpiUniqueFlows } from '../../../containers/kpi_network/unique_flows'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx index 7b256177313da6..1370a1079a1815 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx @@ -13,10 +13,10 @@ import { useNetworkKpiUniquePrivateIps } from '../../../containers/kpi_network/u import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; import * as i18n from './translations'; -import { kpiUniquePrivateIpsSourceMetric } from '../../../configs/kpi_unique_private_ips_source_metric'; -import { kpiUniquePrivateIpsDestinationMetric } from '../../../configs/kpi_unique_private_ips_destination_metric'; -import { kpiUniquePrivateIpsArea } from '../../../configs/kpi_unique_private_ips_area'; -import { kpiUniquePrivateIpsBar } from '../../../configs/kpi_unique_private_ips_bar'; +import { kpiUniquePrivateIpsSourceMetric } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric'; +import { kpiUniquePrivateIpsDestinationMetric } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric'; +import { kpiUniquePrivateIpsArea } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_area'; +import { kpiUniquePrivateIpsBar } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar'; const euiVisColorPalette = euiPaletteColorBlind(); const euiColorVis2 = euiVisColorPalette[2]; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts deleted file mode 100644 index 012ba2c2015284..00000000000000 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_dns_queries.ts +++ /dev/null @@ -1,60 +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 { LensAttributes } from '../../common/components/visualization_actions/types'; - -export const kpiDnsQueries: LensAttributes = { - title: '[Network] KPI Unique private IPs - source metric', - description: '', - visualizationType: 'lnsMetric', - state: { - visualization: { - layerId: 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3', - accessor: 'bd17c23e-4f83-4108-8005-2669170d064b', - layerType: 'data', - }, - query: { - query: - 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', - language: 'kuery', - }, - filters: [], - datasourceStates: { - indexpattern: { - layers: { - 'cea37c70-8f91-43bf-b9fe-72d8c049f6a3': { - columns: { - 'bd17c23e-4f83-4108-8005-2669170d064b': { - label: ' ', - dataType: 'number', - operationType: 'unique_count', - scale: 'ratio', - sourceField: 'source.ip', - isBucketed: false, - customLabel: true, - }, - }, - columnOrder: ['bd17c23e-4f83-4108-8005-2669170d064b'], - incompleteColumns: {}, - }, - }, - }, - }, - }, - references: [ - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-current-indexpattern', - }, - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', - }, - ], -} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts b/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts deleted file mode 100644 index d5f2929941a1df..00000000000000 --- a/x-pack/plugins/security_solution/public/network/configs/kpi_tls_handshakes.ts +++ /dev/null @@ -1,59 +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 { LensAttributes } from '../../common/components/visualization_actions/types'; - -export const kpiTlsHandshakes: LensAttributes = { - title: '[Network] KPI TLS handshakes', - description: '', - visualizationType: 'lnsMetric', - state: { - visualization: { - layerId: '1f48a633-8eee-45ae-9471-861227e9ca03', - accessor: '21052b6b-5504-4084-a2e2-c17f772345cf', - layerType: 'data', - }, - query: { - query: - '(source.ip: * or destination.ip: *) and (tls.version: * or suricata.eve.tls.version: * or zeek.ssl.version: * )', - language: 'kuery', - }, - filters: [], - datasourceStates: { - indexpattern: { - layers: { - '1f48a633-8eee-45ae-9471-861227e9ca03': { - columns: { - '21052b6b-5504-4084-a2e2-c17f772345cf': { - label: ' ', - dataType: 'number', - operationType: 'count', - isBucketed: false, - scale: 'ratio', - sourceField: '___records___', - customLabel: true, - }, - }, - columnOrder: ['21052b6b-5504-4084-a2e2-c17f772345cf'], - incompleteColumns: {}, - }, - }, - }, - }, - }, - references: [ - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-current-indexpattern', - }, - { - type: 'index-pattern', - id: 'security-solution-default', - name: 'indexpattern-datasource-layer-1f48a633-8eee-45ae-9471-861227e9ca03', - }, - ], -} as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx index e241f3c5ed2faa..6ac11295a42a0c 100644 --- a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx @@ -23,7 +23,7 @@ import { MatrixHistogram } from '../../../common/components/matrix_histogram'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; import { networkSelectors } from '../../store'; import { useShallowEqualSelector } from '../../../common/hooks/use_selector'; -import { dnsTopDomainsAttrs } from '../../configs/dns_top_domains'; +import { dnsTopDomainsAttrs } from '../../../common/components/visualization_actions/configs/network/dns_top_domains'; const HISTOGRAM_ID = 'networkDnsHistogramQuery'; From 6daf421b83ab481a0347cafcc88bc19da2979359 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Sat, 5 Mar 2022 02:40:54 +0800 Subject: [PATCH 25/59] unit tests --- .../components/side_panel/__snapshots__/index.test.tsx.snap | 1 + .../security_solution/public/users/pages/users_tabs.test.tsx | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap index 8c88efbbad8a36..9fa91a82896095 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap @@ -282,6 +282,7 @@ exports[`Details Panel Component DetailsPanel:EventDetails: rendering it should Object { "id": "", "inspect": null, + "inspectedVizType": null, "isInspected": false, "loading": false, "refetch": null, diff --git a/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx b/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx index bd4ce3cbae1e3c..83b9285fcd462e 100644 --- a/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx @@ -22,6 +22,11 @@ jest.mock('../../common/components/search_bar', () => ({ jest.mock('../../common/components/query_bar', () => ({ QueryBar: () => null, })); +jest.mock('../../common/components/visualization_actions', () => ({ + VisualizationActions: jest.fn(() => ( +
{'mockVizAction'}
+ )), +})); type Action = 'PUSH' | 'POP' | 'REPLACE'; const pop: Action = 'POP'; From 3eb1c782fb38368c754166847be6c557f713f202 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 8 Mar 2022 17:55:33 +0800 Subject: [PATCH 26/59] fix typo --- .../common/components/visualization_actions/toast_text.tsx | 6 +++--- .../visualization_actions/use_add_to_existing_case.tsx | 4 ++-- .../visualization_actions/use_add_to_new_case.tsx | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx index 9bb0875664aabf..bf227d2880b050 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx @@ -14,7 +14,7 @@ interface ToaseTextProps { href: string; } -const ToaseTextComponent: React.FC = ({ caseId, href }) => { +const ToastTextComponent: React.FC = ({ caseId, href }) => { return ( @@ -25,5 +25,5 @@ const ToaseTextComponent: React.FC = ({ caseId, href }) => { ); }; -ToaseTextComponent.displayName = 'ToaseTextComponent'; -export const ToaseText = React.memo(ToaseTextComponent); +ToastTextComponent.displayName = 'ToastTextComponent'; +export const ToastText = React.memo(ToastTextComponent); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx index 3696188dc4ec07..ccbbbc8095e7f7 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx @@ -18,7 +18,7 @@ import { ADD_TO_CASE_FAILURE, ADD_TO_CASE_SUCCESS } from './translations'; import { LensAttributes } from './types'; import { addToCase } from './utils'; -import { ToaseText } from './toast_text'; +import { ToastText } from './toast_text'; const appId = 'securitySolutionUI'; const owner = APP_ID; @@ -57,7 +57,7 @@ export const useAddToExistingCase = ({ const getToastText = useCallback( (theCase: Case) => toMountPoint( - void; @@ -50,7 +50,7 @@ export const useAddToNewCase = ({ const getToastText = useCallback( (theCase) => toMountPoint( - Date: Tue, 8 Mar 2022 17:56:29 +0800 Subject: [PATCH 27/59] rm unused props --- .../common/components/visualization_actions/toast_text.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx index bf227d2880b050..753e2d2fa1cb11 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx @@ -10,11 +10,10 @@ import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; import { VIEW_CASE } from './translations'; interface ToaseTextProps { - caseId: string; href: string; } -const ToastTextComponent: React.FC = ({ caseId, href }) => { +const ToastTextComponent: React.FC = ({ href }) => { return ( From 16af7f16d9af95e34ef2cb2a0e7d6e7139bc3b17 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 8 Mar 2022 21:50:18 +0800 Subject: [PATCH 28/59] apply cases flyout and modal --- .../components/header_section/index.tsx | 136 +++++++------- .../common/components/stat_items/index.tsx | 176 +++++++++--------- .../visualization_actions/index.tsx | 57 +----- .../use_add_to_existing_case.tsx | 112 +++-------- .../use_add_to_new_case.tsx | 77 ++------ 5 files changed, 215 insertions(+), 343 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx index 7fd5bb504561e5..41bc81dd0cb6b1 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx @@ -13,6 +13,8 @@ import { InspectButton } from '../inspect'; import { VisualizationActions } from '../visualization_actions'; import { LensAttributes, GetLensAttributes } from '../visualization_actions/types'; import { Subtitle } from '../subtitle'; +import { APP_ID } from '../../../../common/constants'; +import { useGetUserCasesPermissions, useKibana } from '../../lib/kibana'; interface HeaderProps { border?: boolean; @@ -82,73 +84,81 @@ const HeaderSectionComponent: React.FC = ({ title, titleSize = 'm', tooltip, -}) => ( -
- - - - - -

- {title} - {tooltip && ( - <> - {' '} - - - )} -

-
+}) => { + const { cases } = useKibana().services; + const CasesContext = cases.getCasesContext(); + const userPermissions = useGetUserCasesPermissions(); + const userCanCrud = userPermissions?.crud ?? false; + return ( +
+ + + + + +

+ {title} + {tooltip && ( + <> + {' '} + + + )} +

+
- {!hideSubtitle && ( - - )} -
- - {id && ( - <> - {showInspectButton && ( - - - - )} - {(getLensAttributes || lensAttributes) && timerange && ( - - - + {!hideSubtitle && ( + )} - - )} +
- {headerFilters && {headerFilters}} -
- + {id && ( + <> + {showInspectButton && ( + + + + )} + {(getLensAttributes || lensAttributes) && timerange && ( + + + + + + )} + + )} - {children && ( - - {children} + {headerFilters && {headerFilters}} + - )} - -
-); + + {children && ( + + {children} + + )} +
+
+ ); +}; export const HeaderSection = React.memo(HeaderSectionComponent); diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index cb977a0dd5001b..25f2a10ec92f18 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -34,6 +34,8 @@ import { InspectButton } from '../inspect'; import { VisualizationActions, HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; import { HoverVisibilityContainer } from '../hover_visibility_container'; import { LensAttributes } from '../visualization_actions/types'; +import { useGetUserCasesPermissions, useKibana } from '../../lib/kibana'; +import { APP_ID } from '../../../../common/constants'; const FlexItem = styled(EuiFlexItem)` min-width: 0; @@ -221,6 +223,10 @@ export const StatItemsComponent = React.memo( barChartLensAttributes, areaChartLensAttributes, }) => { + const { cases } = useKibana().services; + const CasesContext = cases.getCasesContext(); + const userPermissions = useGetUserCasesPermissions(); + const userCanCrud = userPermissions?.crud ?? false; const isBarChartDataAvailable = barChart && barChart.length && @@ -240,103 +246,107 @@ export const StatItemsComponent = React.memo( return ( - - - - -
{description}
-
-
- {showInspectButton && ( - - + + + + + +
{description}
+
- )} -
+ {showInspectButton && ( + + + + )} +
- - {fields.map((field) => ( - - - {(isAreaChartDataAvailable || isBarChartDataAvailable) && field.icon && ( - - - - )} - - - - -

- {field.value != null ? field.value.toLocaleString() : getEmptyTagValue()}{' '} - {field.description} -

-
- {field.lensAttributes && timerange && ( - + {fields.map((field) => ( + + + {(isAreaChartDataAvailable || isBarChartDataAvailable) && field.icon && ( + + - )} -
-
-
-
- ))} -
+
+ )} - {(enableAreaChart || enableBarChart) && } - - {enableBarChart && ( - - - - )} + + + +

+ {field.value != null + ? field.value.toLocaleString() + : getEmptyTagValue()}{' '} + {field.description} +

+
+ {field.lensAttributes && timerange && ( + + )} +
+
+
+ + ))} +
- {enableAreaChart && from != null && to != null && ( - <> + {(enableAreaChart || enableBarChart) && } + + {enableBarChart && ( - - - )} - - + )} + + {enableAreaChart && from != null && to != null && ( + <> + + + + + )} + + + ); }, diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 530db00fb75c8e..32df932fc84583 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -7,12 +7,8 @@ import { EuiButtonIcon, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui'; import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; -import { - GetAllCasesSelectorModalProps, - GetCreateCaseFlyoutProps, -} from '../../../../../cases/public'; + import { LensEmbeddableInput } from '../../../../../lens/public'; -import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; import { ModalInspectQuery } from '../inspect/modal'; @@ -40,8 +36,6 @@ const Wrapper = styled.div` export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; -const owner = APP_ID; - const VisualizationActionsComponent: React.FC = ({ className, getLensAttributes, @@ -57,7 +51,7 @@ const VisualizationActionsComponent: React.FC = ({ title, stackByField, }) => { - const { lens, cases } = useKibana().services; + const { lens } = useKibana().services; const userPermissions = useGetUserCasesPermissions(); const userCanCrud = userPermissions?.crud ?? false; @@ -85,50 +79,21 @@ const VisualizationActionsComponent: React.FC = ({ const dataTestSubj = ['stat', queryId, vizType].filter((i) => i != null).join('-'); - const { - disabled: isAddToExistingCaseDisabled, - closeAllCaseModal, - isAllCaseModalOpen, - onCaseClicked, - onAddToExistingCaseClicked, - } = useAddToExistingCase({ - onAddToCaseClicked: closePopover, - lensAttributes: attributes, - timeRange: timerange, - userCanCrud, - }); + const { disabled: isAddToExistingCaseDisabled, onAddToExistingCaseClicked } = + useAddToExistingCase({ + onAddToCaseClicked: closePopover, + lensAttributes: attributes, + timeRange: timerange, + userCanCrud, + }); - const { - onClose: closeCreateCaseFlyout, - onSuccess: onCreateCaseSuccess, - attachments: chartAddedToCase, - onAddToNewCaseClicked, - isCreateCaseFlyoutOpen, - disabled: isAddToNewCaseDisabled, - } = useAddToNewCase({ + const { onAddToNewCaseClicked, disabled: isAddToNewCaseDisabled } = useAddToNewCase({ onClick: closePopover, timeRange: timerange, lensAttributes: attributes, userCanCrud, }); - const allCasesSelectorModalProps: GetAllCasesSelectorModalProps = { - onRowClick: onCaseClicked, - userCanCrud, - owner: [owner], - onClose: closeAllCaseModal, - }; - - const createCaseFlyoutProps: GetCreateCaseFlyoutProps = useMemo(() => { - return { - onClose: closeCreateCaseFlyout, - onSuccess: onCreateCaseSuccess, - owner: [owner], - userCanCrud, - attachments: chartAddedToCase, - }; - }, [closeCreateCaseFlyout, onCreateCaseSuccess, userCanCrud, chartAddedToCase]); - const onOpenInLens = useCallback(() => { closePopover(); if (!timerange || !attributes) { @@ -282,8 +247,6 @@ const VisualizationActionsComponent: React.FC = ({ title={title} /> )} - {isCreateCaseFlyoutOpen && cases.getCreateCaseFlyout(createCaseFlyoutProps)} - {isAllCaseModalOpen && cases.getAllCasesSelectorModal(allCasesSelectorModalProps)} ); }; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx index ccbbbc8095e7f7..08ecb22ec8da8d 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx @@ -4,23 +4,14 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import React, { useCallback, useState } from 'react'; -import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; -import { Case } from '../../../../../cases/common'; -import { - CasesDeepLinkId, - DRAFT_COMMENT_STORAGE_ID, - generateCaseViewPath, -} from '../../../../../cases/public'; +import { useCallback, useMemo } from 'react'; +import { CommentType } from '../../../../../cases/common'; + import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; -import { ADD_TO_CASE_FAILURE, ADD_TO_CASE_SUCCESS } from './translations'; import { LensAttributes } from './types'; -import { addToCase } from './utils'; -import { ToastText } from './toast_text'; -const appId = 'securitySolutionUI'; const owner = APP_ID; export const useAddToExistingCase = ({ @@ -34,90 +25,33 @@ export const useAddToExistingCase = ({ timeRange: { from: string; to: string }; userCanCrud: boolean; }) => { - const { - application: { getUrlForApp, navigateToApp }, - http, - notifications: { toasts }, - storage, - theme, - } = useKibana().services; - const [isAllCaseModalOpen, setIsAllCaseModalOpen] = useState(false); - - const closeAllCaseModal = useCallback(() => { - setIsAllCaseModalOpen(false); - }, []); + const { cases } = useKibana().services; + const attachments = useMemo(() => { + return [ + { + comment: `!{lens${JSON.stringify({ + timeRange, + attributes: lensAttributes, + })}}`, + owner, + type: CommentType.user as const, + }, + ]; + }, [lensAttributes, timeRange]); + + const selectCaseModal = cases.hooks.getUseCasesAddToExistingCaseModal({ + attachments, + onClose: onAddToCaseClicked, + }); const onAddToExistingCaseClicked = useCallback(() => { if (onAddToCaseClicked) { onAddToCaseClicked(); } - setIsAllCaseModalOpen(true); - }, [onAddToCaseClicked]); - - const getToastText = useCallback( - (theCase: Case) => - toMountPoint( - , - { theme$: theme?.theme$ } - ), - [getUrlForApp, theme?.theme$] - ); - - const onCaseClicked = useCallback( - (theCase?: Case) => { - if (theCase && lensAttributes) { - setIsAllCaseModalOpen(false); - addToCase(http, theCase, lensAttributes, timeRange, owner).then( - () => { - toasts.addSuccess( - { - title: ADD_TO_CASE_SUCCESS(theCase.title), - text: getToastText(theCase), - }, - { - toastLifeTimeMs: 10000, - } - ); - }, - (error) => { - toasts.addError(error, { - title: ADD_TO_CASE_FAILURE, - }); - } - ); - } else { - /* save lens attributes and timerange to local storage, - ** so the description field will be automatically filled on case creation page. - */ - storage?.set(DRAFT_COMMENT_STORAGE_ID, { - commentId: 'description', - comment: `!{lens${JSON.stringify({ - timeRange, - attributes: lensAttributes, - })}}`, - position: '', - caseTitle: '', - caseTags: '', - }); - navigateToApp(appId, { - deepLinkId: CasesDeepLinkId.casesCreate, - openInNewTab: true, - }); - } - }, - [getToastText, http, lensAttributes, navigateToApp, storage, timeRange, toasts] - ); + selectCaseModal.open(); + }, [onAddToCaseClicked, selectCaseModal]); return { - closeAllCaseModal, - isAllCaseModalOpen, - onCaseClicked, onAddToExistingCaseClicked, disabled: lensAttributes == null || !userCanCrud, }; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx index 1f2a47fd0f5924..17eeaec6cfa61a 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx @@ -4,16 +4,14 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import React, { useCallback, useMemo, useState } from 'react'; -import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public'; -import { Case, CommentType } from '../../../../../cases/common'; +import { useCallback, useMemo } from 'react'; + +import { CommentType } from '../../../../../cases/common'; + import { APP_ID } from '../../../../common/constants'; import { useKibana } from '../../lib/kibana/kibana_react'; import { LensAttributes } from './types'; -import { ADD_TO_CASE_SUCCESS } from './translations'; -import { CasesDeepLinkId, generateCaseViewPath } from '../../../../../cases/public'; -import { ToastText } from './toast_text'; export interface UseAddToNewCaseProps { onClick?: () => void; @@ -23,7 +21,6 @@ export interface UseAddToNewCaseProps { } const owner = APP_ID; -const appId = 'securitySolutionUI'; export const useAddToNewCase = ({ onClick, @@ -31,53 +28,7 @@ export const useAddToNewCase = ({ lensAttributes, userCanCrud, }: UseAddToNewCaseProps) => { - const { - theme, - notifications: { toasts }, - application: { getUrlForApp }, - } = useKibana().services; - - const [isCreateCaseFlyoutOpen, setIsCreateCaseFlyoutOpen] = useState(false); - - const onAddToNewCaseClicked = useCallback(() => { - if (onClick) { - onClick(); - } - - setIsCreateCaseFlyoutOpen(true); - }, [onClick]); - - const getToastText = useCallback( - (theCase) => - toMountPoint( - , - { theme$: theme?.theme$ } - ), - [getUrlForApp, theme?.theme$] - ); - - const onCreateCaseSuccess = useCallback( - async (theCase: Case) => { - setIsCreateCaseFlyoutOpen(false); - toasts.addSuccess( - { - title: ADD_TO_CASE_SUCCESS(theCase.title), - text: getToastText(theCase), - }, - { - toastLifeTimeMs: 10000, - } - ); - }, - [getToastText, toasts] - ); - + const { cases } = useKibana().services; const attachments = useMemo(() => { return [ { @@ -91,16 +42,20 @@ export const useAddToNewCase = ({ ]; }, [lensAttributes, timeRange]); - const closeCreateCaseFlyout = useCallback(() => { - setIsCreateCaseFlyoutOpen(false); - }, []); + const createCaseFlyout = cases.hooks.getUseCasesAddToNewCaseFlyout({ + attachments, + }); + + const onAddToNewCaseClicked = useCallback(() => { + if (onClick) { + onClick(); + } + + createCaseFlyout.open(); + }, [createCaseFlyout, onClick]); return { - onClose: closeCreateCaseFlyout, - onSuccess: onCreateCaseSuccess, - attachments, onAddToNewCaseClicked, - isCreateCaseFlyoutOpen, disabled: lensAttributes == null || !userCanCrud, }; }; From c6085134e8325e1dbb803971128bab71626225a3 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 8 Mar 2022 21:52:54 +0800 Subject: [PATCH 29/59] rm unused definition --- .../visualization_actions/toast_text.tsx | 28 ------------------- .../visualization_actions/translations.ts | 23 --------------- .../components/visualization_actions/utils.ts | 27 ------------------ 3 files changed, 78 deletions(-) delete mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx deleted file mode 100644 index 753e2d2fa1cb11..00000000000000 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/toast_text.tsx +++ /dev/null @@ -1,28 +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 { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui'; - -import { VIEW_CASE } from './translations'; - -interface ToaseTextProps { - href: string; -} - -const ToastTextComponent: React.FC = ({ href }) => { - return ( - - - - {VIEW_CASE} - - - - ); -}; -ToastTextComponent.displayName = 'ToastTextComponent'; -export const ToastText = React.memo(ToastTextComponent); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts index 3abf4d5e41f5ca..37264cae4af2eb 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts @@ -7,29 +7,6 @@ import { i18n } from '@kbn/i18n'; -export const ADD_TO_CASE_SUCCESS = (caseTitle: string) => - i18n.translate( - 'xpack.securitySolution.components.visualizationActions.addToCase.notificationSuccess', - { - defaultMessage: 'Successfully added visualization to the case: {caseTitle}', - values: { caseTitle }, - } - ); - -export const ADD_TO_CASE_FAILURE = i18n.translate( - 'xpack.securitySolution.components.visualizationActions.addToCase.notificationFailure', - { - defaultMessage: 'Failed to add visualization to the selected case.', - } -); - -export const VIEW_CASE = i18n.translate( - 'xpack.securitySolution.components.visualizationActions.addToCase.notification.viewCase', - { - defaultMessage: 'View case', - } -); - export const INSPECT = i18n.translate('xpack.securitySolution.visualizationActions.inspect', { defaultMessage: 'Inspect', }); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts index 4fc604ac3629fc..6cac0cf8240a5e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts @@ -6,10 +6,6 @@ */ import { Filter } from '@kbn/es-query'; -import { LensAttributes } from './types'; - -import { HttpSetup } from '../../../../../../../src/core/public'; -import { Case } from '../../../../../cases/common'; export const getHostDetailsPageFilter = (hostName?: string): Filter[] => hostName @@ -145,26 +141,3 @@ export const getIndexFilters = (selectedPatterns: string[]) => }, ] : []; - -export const addToCase = async ( - http: HttpSetup, - theCase: Case, - attributes: LensAttributes, - timeRange?: { from: string; to: string }, - owner?: string -) => { - const apiPath = `/api/cases/${theCase?.id}/comments`; - - const vizPayload = { - attributes, - timeRange, - }; - - const payload = { - comment: `!{lens${JSON.stringify(vizPayload)}}`, - type: 'user', - owner: owner ?? 'security_solution', - }; - - return http.post(apiPath, { body: JSON.stringify(payload) }); -}; From f459e16c83a5cb7042595c4796786f247a37a2af Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 8 Mar 2022 21:57:02 +0800 Subject: [PATCH 30/59] fix typo --- .../public/common/components/charts/areachart.tsx | 6 +++--- .../public/common/components/charts/barchart.tsx | 6 +++--- .../common/components/visualization_actions/index.tsx | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx index 12a70e846ed3c5..313b216eb19ea6 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/areachart.tsx @@ -159,12 +159,12 @@ export const AreaChartComponent: React.FC = ({ const chartHeight = getChartHeight(customHeight, height); const chartWidth = getChartWidth(customWidth, width); - const isVlidSeriesExist = useMemo(() => checkIfAnyValidSeriesExist(areaChart), [areaChart]); + const isValidSeriesExist = useMemo(() => checkIfAnyValidSeriesExist(areaChart), [areaChart]); return ( - {isVlidSeriesExist && areaChart && ( + {isValidSeriesExist && areaChart && ( @@ -178,7 +178,7 @@ export const AreaChartComponent: React.FC = ({ )} - {!isVlidSeriesExist && ( + {!isValidSeriesExist && ( )} {visualizationActionsOptions != null && ( diff --git a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx index 2b314bd80050f0..deee4f97331089 100644 --- a/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx +++ b/x-pack/plugins/security_solution/public/common/components/charts/barchart.tsx @@ -182,12 +182,12 @@ export const BarChartComponent: React.FC = ({ const customWidth = get('customWidth', configs); const chartHeight = getChartHeight(customHeight, height); const chartWidth = getChartWidth(customWidth, width); - const isVlidSeriesExist = useMemo(() => checkIfAnyValidSeriesExist(barChart), [barChart]); + const isValidSeriesExist = useMemo(() => checkIfAnyValidSeriesExist(barChart), [barChart]); return ( - {isVlidSeriesExist && barChart && ( + {isValidSeriesExist && barChart && ( @@ -207,7 +207,7 @@ export const BarChartComponent: React.FC = ({ )} - {!isVlidSeriesExist && ( + {!isValidSeriesExist && ( )} {visualizationActionsOptions != null && ( diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 32df932fc84583..ae0d3b862300fd 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -140,7 +140,7 @@ const VisualizationActionsComponent: React.FC = ({ vizType, }); - const disaledOpenInLens = useMemo( + const disabledOpenInLens = useMemo( () => !canUseEditor() || attributes == null, [attributes, canUseEditor] ); @@ -151,7 +151,7 @@ const VisualizationActionsComponent: React.FC = ({ icon="visArea" key="visualizationActionsOpenInLens" data-test-subj="viz-actions-open-in-lens" - disabled={disaledOpenInLens} + disabled={disabledOpenInLens} onClick={onOpenInLens} > {OPEN_IN_LENS} @@ -195,7 +195,7 @@ const VisualizationActionsComponent: React.FC = ({ ], [ disableInspectButton, - disaledOpenInLens, + disabledOpenInLens, handleInspectButtonClick, isAddToExistingCaseDisabled, isAddToNewCaseDisabled, From 13fdc19368530b2383336f591aae80fce5ff8760 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 00:05:34 +0800 Subject: [PATCH 31/59] rm vizType in reducer --- .../common/components/inspect/use_inspect.tsx | 21 ++++++------------- .../visualization_actions/index.tsx | 19 ++++++++++++----- .../public/common/store/inputs/actions.ts | 1 - .../common/store/inputs/helpers.test.ts | 5 ----- .../public/common/store/inputs/helpers.ts | 6 +----- .../public/common/store/inputs/model.ts | 1 - .../public/common/store/inputs/reducer.ts | 6 ++---- .../public/common/store/inputs/selectors.ts | 2 -- .../__snapshots__/index.test.tsx.snap | 7 ++----- 9 files changed, 25 insertions(+), 43 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx index 8d4a67716d30da..d9f633c7d01e3a 100644 --- a/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx +++ b/x-pack/plugins/security_solution/public/common/components/inspect/use_inspect.tsx @@ -20,7 +20,6 @@ interface UseInspectModalProps { onClick?: () => void; onCloseInspect?: () => void; queryId: string; - vizType?: string | null; } export const useInspect = ({ @@ -31,16 +30,14 @@ export const useInspect = ({ onClick, onCloseInspect, queryId, - vizType = null, }: UseInspectModalProps) => { const dispatch = useDispatch(); const getGlobalQuery = inputsSelectors.globalQueryByIdSelector(); const getTimelineQuery = inputsSelectors.timelineQueryByIdSelector(); - const { loading, inspect, selectedInspectIndex, isInspected, inspectedVizType } = - useDeepEqualSelector((state) => - inputId === 'global' ? getGlobalQuery(state, queryId) : getTimelineQuery(state, queryId) - ); + const { loading, inspect, selectedInspectIndex, isInspected } = useDeepEqualSelector((state) => + inputId === 'global' ? getGlobalQuery(state, queryId) : getTimelineQuery(state, queryId) + ); const handleClick = useCallback(() => { if (onClick) { @@ -52,10 +49,9 @@ export const useInspect = ({ inputId, isInspected: true, selectedInspectIndex: inspectIndex, - inspectedVizType: vizType, }) ); - }, [onClick, dispatch, queryId, inputId, inspectIndex, vizType]); + }, [onClick, dispatch, queryId, inputId, inspectIndex]); const handleCloseModal = useCallback(() => { if (onCloseInspect != null) { @@ -67,7 +63,6 @@ export const useInspect = ({ inputId, isInspected: false, selectedInspectIndex: inspectIndex, - inspectedVizType: null, }) ); }, [onCloseInspect, dispatch, queryId, inputId, inspectIndex]); @@ -93,12 +88,8 @@ export const useInspect = ({ } const isShowingModal = useMemo( - () => - !loading && - selectedInspectIndex === inspectIndex && - isInspected && - inspectedVizType === vizType, - [inspectedVizType, vizType, inspectIndex, isInspected, loading, selectedInspectIndex] + () => !loading && selectedInspectIndex === inspectIndex && isInspected, + [inspectIndex, isInspected, loading, selectedInspectIndex] ); const isButtonDisabled = useMemo( diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index ae0d3b862300fd..f9f40a814429b3 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -120,13 +120,23 @@ const VisualizationActionsComponent: React.FC = ({ closePopover(); }, []); + const [isInspectModalOpen, setIsInspectModalOpen] = useState(false); + + const onOpenInspectModal = useCallback(() => { + closePopover(); + setIsInspectModalOpen(true); + }, []); + + const onCloseInspectModal = useCallback(() => { + setIsInspectModalOpen(false); + }, []); + const { additionalRequests, additionalResponses, handleClick: handleInspectButtonClick, handleCloseModal: handleCloseInspectModal, isButtonDisabled: disableInspectButton, - isShowingModal, request, response, } = useInspect({ @@ -134,10 +144,9 @@ const VisualizationActionsComponent: React.FC = ({ inspectIndex, isDisabled: isInspectButtonDisabled, multiple: isMultipleQuery, - onCloseInspect, - onClick: closePopover, + onCloseInspect: onCloseInspectModal, + onClick: onOpenInspectModal, queryId, - vizType, }); const disabledOpenInLens = useMemo( @@ -236,7 +245,7 @@ const VisualizationActionsComponent: React.FC = ({ )} - {isShowingModal && request !== null && response !== null && ( + {isInspectModalOpen && request !== null && response !== null && ( ('SET_INSPECTION_PARAMETER'); export const deleteAllQuery = actionCreator<{ id: InputsModelId }>('DELETE_ALL_QUERY'); diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts index c2db80e87a05a5..c8848e6f7ffc7f 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts @@ -126,7 +126,6 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - inspectedVizType: null, }); }); @@ -153,7 +152,6 @@ describe('Inputs', () => { loading: true, refetch, selectedInspectIndex: 0, - inspectedVizType: null, }); }); }); @@ -189,7 +187,6 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - inspectedVizType: null, }); }); @@ -210,7 +207,6 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - inspectedVizType: null, }); }); }); @@ -276,7 +272,6 @@ describe('Inputs', () => { loading: false, refetch, selectedInspectIndex: 0, - inspectedVizType: null, }, ], timerange: { diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts index 24bc1ff02d0842..d2e350027f9057 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/helpers.ts @@ -103,7 +103,6 @@ export const upsertQuery = ({ isInspected: state[inputId].queries[queryIndex].isInspected, loading, refetch, - inspectedVizType: null, selectedInspectIndex: state[inputId].queries[queryIndex].selectedInspectIndex, }, ...state[inputId].queries.slice(queryIndex + 1), @@ -117,7 +116,6 @@ export const upsertQuery = ({ loading, refetch, selectedInspectIndex: 0, - inspectedVizType: null, }, ], }, @@ -130,7 +128,6 @@ export interface SetIsInspectedParams { isInspected: boolean; selectedInspectIndex: number; state: InputsModel; - inspectedVizType?: string | null; } export const setIsInspected = ({ @@ -139,7 +136,6 @@ export const setIsInspected = ({ isInspected, selectedInspectIndex, state, - inspectedVizType = null, }: SetIsInspectedParams): InputsModel => { const myQueryIndex = state[inputId].queries.findIndex((q) => q.id === id); const myQuery = myQueryIndex > -1 ? state[inputId].queries[myQueryIndex] : null; @@ -152,7 +148,7 @@ export const setIsInspected = ({ myQueryIndex > -1 ? [ ...state[inputId].queries.slice(0, myQueryIndex), - { ...myQuery, isInspected, selectedInspectIndex, inspectedVizType }, + { ...myQuery, isInspected, selectedInspectIndex }, ...state[inputId].queries.slice(myQueryIndex + 1), ] : [...state[inputId].queries], diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts index 9c0e033c37c598..f5e31d42e22eab 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/model.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/model.ts @@ -62,7 +62,6 @@ export interface GlobalGenericQuery { loading: boolean; selectedInspectIndex: number; invalidKqlQuery?: Error; - inspectedVizType?: string | null; } export interface GlobalGraphqlQuery extends GlobalGenericQuery { diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts b/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts index 80a30662395d55..848d5adbffc9af 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/reducer.ts @@ -218,10 +218,8 @@ export const inputsReducer = reducerWithInitialState(initialInputsState) }, })) .case(toggleTimelineLinkTo, (state, { linkToId }) => toggleLockTimeline(linkToId, state)) - .case( - setInspectionParameter, - (state, { id, inputId, isInspected, selectedInspectIndex, inspectedVizType }) => - setIsInspected({ id, inputId, isInspected, selectedInspectIndex, state, inspectedVizType }) + .case(setInspectionParameter, (state, { id, inputId, isInspected, selectedInspectIndex }) => + setIsInspected({ id, inputId, isInspected, selectedInspectIndex, state }) ) .case(removeGlobalLinkTo, (state) => removeGlobalLink(state)) .case(addGlobalLinkTo, (state, { linkToId }) => addGlobalLink(linkToId, state)) diff --git a/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts b/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts index 4aebe1b8bc84e5..864a473a820993 100644 --- a/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts +++ b/x-pack/plugins/security_solution/public/common/store/inputs/selectors.ts @@ -26,7 +26,6 @@ const selectGlobalQuery = (state: State, id: string): GlobalQuery => loading: false, refetch: null, selectedInspectIndex: 0, - inspectedVizType: null, }; const selectTimelineQuery = (state: State, id: string): GlobalQuery => @@ -38,7 +37,6 @@ const selectTimelineQuery = (state: State, id: string): GlobalQuery => loading: false, refetch: null, selectedInspectIndex: 0, - inspectedVizType: null, }; export const inputsSelector = () => createSelector(selectInputs, (inputs) => inputs); diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap index 9fa91a82896095..36c59ec8441a01 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: +exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: Date: Wed, 9 Mar 2022 00:39:12 +0800 Subject: [PATCH 32/59] onCloseInspect callback --- .../public/common/components/visualization_actions/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index f9f40a814429b3..edc469ca09bf31 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -129,7 +129,10 @@ const VisualizationActionsComponent: React.FC = ({ const onCloseInspectModal = useCallback(() => { setIsInspectModalOpen(false); - }, []); + if (onCloseInspect) { + onCloseInspect(); + } + }, [onCloseInspect]); const { additionalRequests, From 86888766de284294770c9bf437c1f2c4ce007a29 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 01:52:44 +0800 Subject: [PATCH 33/59] move viz action component out of header section --- .../components/header_section/index.tsx | 133 +++++-------- .../components/matrix_histogram/index.tsx | 24 ++- .../common/components/stat_items/index.tsx | 176 +++++++++--------- .../components/kpi_hosts/common/index.tsx | 15 +- .../components/kpi_network/common/index.tsx | 15 +- 5 files changed, 176 insertions(+), 187 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx index 41bc81dd0cb6b1..ead5725eac1cfd 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx @@ -10,11 +10,8 @@ import React from 'react'; import styled, { css } from 'styled-components'; import { InspectButton } from '../inspect'; -import { VisualizationActions } from '../visualization_actions'; -import { LensAttributes, GetLensAttributes } from '../visualization_actions/types'; + import { Subtitle } from '../subtitle'; -import { APP_ID } from '../../../../common/constants'; -import { useGetUserCasesPermissions, useKibana } from '../../lib/kibana'; interface HeaderProps { border?: boolean; @@ -43,7 +40,6 @@ Header.displayName = 'Header'; export interface HeaderSectionProps extends HeaderProps { children?: React.ReactNode; - getLensAttributes?: GetLensAttributes; growLeftSplit?: boolean; headerFilters?: string | React.ReactNode; height?: number; @@ -51,13 +47,10 @@ export interface HeaderSectionProps extends HeaderProps { id?: string; inspectMultiple?: boolean; isInspectDisabled?: boolean; - lensAttributes?: LensAttributes | null; showInspectButton?: boolean; split?: boolean; - stackByField?: string; stackHeader?: boolean; subtitle?: string | React.ReactNode; - timerange?: { from: string; to: string }; title: string | React.ReactNode; titleSize?: EuiTitleSize; tooltip?: string; @@ -66,7 +59,6 @@ export interface HeaderSectionProps extends HeaderProps { const HeaderSectionComponent: React.FC = ({ border, children, - getLensAttributes, growLeftSplit = true, headerFilters, height, @@ -74,91 +66,66 @@ const HeaderSectionComponent: React.FC = ({ id, inspectMultiple = false, isInspectDisabled, - lensAttributes, showInspectButton = true, split, - stackByField, stackHeader, subtitle, - timerange, title, titleSize = 'm', tooltip, -}) => { - const { cases } = useKibana().services; - const CasesContext = cases.getCasesContext(); - const userPermissions = useGetUserCasesPermissions(); - const userCanCrud = userPermissions?.crud ?? false; - return ( -
- - - - - -

- {title} - {tooltip && ( - <> - {' '} - - - )} -

-
+}) => ( +
+ + + + + +

+ {title} + {tooltip && ( + <> + {' '} + + + )} +

+
+ + {!hideSubtitle && ( + + )} +
- {!hideSubtitle && ( - + {id && ( + <> + {showInspectButton && ( + + + )} -
+ + )} - {id && ( - <> - {showInspectButton && ( - - - - )} - {(getLensAttributes || lensAttributes) && timerange && ( - - - - - - )} - - )} + {headerFilters && {headerFilters}} +
+ - {headerFilters && {headerFilters}} - + {children && ( + + {children} - - {children && ( - - {children} - - )} - -
- ); -}; + )} +
+
+); export const HeaderSection = React.memo(HeaderSectionComponent); diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 0acdd928579d8b..7fbe2db29e433a 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -29,8 +29,10 @@ import { GlobalTimeArgs } from '../../containers/use_global_time'; import { setAbsoluteRangeDatePicker } from '../../store/inputs/actions'; import { InputsModelId } from '../../store/inputs/constants'; import { HoverVisibilityContainer } from '../hover_visibility_container'; -import { HISTOGRAM_ACTIONS_BUTTON_CLASS } from '../visualization_actions'; +import { HISTOGRAM_ACTIONS_BUTTON_CLASS, VisualizationActions } from '../visualization_actions'; import { GetLensAttributes, LensAttributes } from '../visualization_actions/types'; +import { useKibana, useGetUserCasesPermissions } from '../../lib/kibana'; +import { APP_ID } from '../../../../common/constants'; export type MatrixHistogramComponentProps = MatrixHistogramProps & Omit & { @@ -104,6 +106,11 @@ export const MatrixHistogramComponent: React.FC = skip, }) => { const dispatch = useDispatch(); + const { cases } = useKibana().services; + const CasesContext = cases.getCasesContext(); + const userPermissions = useGetUserCasesPermissions(); + const userCanCrud = userPermissions?.crud ?? false; + const handleBrushEnd = useCallback( ({ x }) => { if (!x) { @@ -237,12 +244,19 @@ export const MatrixHistogramComponent: React.FC = inspectMultiple showInspectButton={showInspectButton} isInspectDisabled={filterQuery === undefined} - lensAttributes={lensAttributes} - stackByField={selectedStackByOption.value} - timerange={timerange} - getLensAttributes={getLensAttributes} > + + + {stackByOptions.length > 1 && ( ( barChartLensAttributes, areaChartLensAttributes, }) => { - const { cases } = useKibana().services; - const CasesContext = cases.getCasesContext(); - const userPermissions = useGetUserCasesPermissions(); - const userCanCrud = userPermissions?.crud ?? false; const isBarChartDataAvailable = barChart && barChart.length && @@ -246,107 +240,103 @@ export const StatItemsComponent = React.memo( return ( - - - - - -
{description}
-
+ + + + +
{description}
+
+
+ {showInspectButton && ( + + - {showInspectButton && ( - - - - )} -
+ )} +
- - {fields.map((field) => ( - - - {(isAreaChartDataAvailable || isBarChartDataAvailable) && field.icon && ( - - + {fields.map((field) => ( + + + {(isAreaChartDataAvailable || isBarChartDataAvailable) && field.icon && ( + + + + )} + + + + +

+ {field.value != null ? field.value.toLocaleString() : getEmptyTagValue()}{' '} + {field.description} +

+
+ {field.lensAttributes && timerange && ( + -
- )} + )} +
+ + + + ))} + - - - -

- {field.value != null - ? field.value.toLocaleString() - : getEmptyTagValue()}{' '} - {field.description} -

-
- {field.lensAttributes && timerange && ( - - )} -
-
- - - ))} - + {(enableAreaChart || enableBarChart) && } + + {enableBarChart && ( + + + + )} - {(enableAreaChart || enableBarChart) && } - - {enableBarChart && ( + {enableAreaChart && from != null && to != null && ( + <> - - )} - - {enableAreaChart && from != null && to != null && ( - <> - - - - - )} - - - + + )} + + ); }, diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx index 7e5d40d8393ed5..88dc67533d63d6 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx @@ -19,6 +19,8 @@ import { StatItems, } from '../../../../common/components/stat_items'; import { UpdateDateRange } from '../../../../common/components/charts/common'; +import { useKibana, useGetUserCasesPermissions } from '../../../../common/lib/kibana'; +import { APP_ID } from '../../../../../common/constants'; const kpiWidgetHeight = 247; @@ -41,6 +43,11 @@ interface HostsKpiBaseComponentProps { export const HostsKpiBaseComponent = React.memo( ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange, showInspectButton }) => { + const { cases } = useKibana().services; + const CasesContext = cases.getCasesContext(); + const userPermissions = useGetUserCasesPermissions(); + const userCanCrud = userPermissions?.crud ?? false; + const statItemsProps: StatItemsProps[] = useKpiMatrixStatus( fieldsMapping, data, @@ -56,9 +63,11 @@ export const HostsKpiBaseComponent = React.memo( return ( - {statItemsProps.map((mappedStatItemProps) => ( - - ))} + + {statItemsProps.map((mappedStatItemProps) => ( + + ))} + ); }, diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx index 7eab8a26a36382..cd2911cf8386b7 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx @@ -19,6 +19,8 @@ import { StatItems, } from '../../../../common/components/stat_items'; import { UpdateDateRange } from '../../../../common/components/charts/common'; +import { useKibana, useGetUserCasesPermissions } from '../../../../common/lib/kibana'; +import { APP_ID } from '../../../../../common/constants'; const kpiWidgetHeight = 228; @@ -48,6 +50,11 @@ export const NetworkKpiBaseComponent = React.memo<{ narrowDateRange, showInspectButton = true, }) => { + const { cases } = useKibana().services; + const CasesContext = cases.getCasesContext(); + const userPermissions = useGetUserCasesPermissions(); + const userCanCrud = userPermissions?.crud ?? false; + const statItemsProps: StatItemsProps[] = useKpiMatrixStatus( fieldsMapping, data, @@ -69,9 +76,11 @@ export const NetworkKpiBaseComponent = React.memo<{ return ( - {statItemsProps.map((mappedStatItemProps) => ( - - ))} + + {statItemsProps.map((mappedStatItemProps) => ( + + ))} + ); }, From 87fae099f3d1eb52f9e7c829b6226213ff53ead7 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 02:31:53 +0800 Subject: [PATCH 34/59] rm hard coded dataViewId in configs --- .../configs/common/external_alert.ts | 8 +- .../configs/hosts/authentication.ts | 8 +- .../configs/hosts/events.ts | 4 +- .../configs/hosts/kpi_host_area.ts | 9 +- .../configs/hosts/kpi_host_metric.ts | 9 +- .../configs/hosts/kpi_unique_ips_area.ts | 11 +- .../configs/hosts/kpi_unique_ips_bar.ts | 11 +- .../kpi_unique_ips_destination_metric.ts | 9 +- .../hosts/kpi_unique_ips_source_metric.ts | 9 +- .../kpi_user_authentication_metric_failure.ts | 9 +- .../hosts/kpi_user_authentications_area.ts | 11 +- .../hosts/kpi_user_authentications_bar.ts | 11 +- ...kpi_user_authentications_metric_success.ts | 9 +- .../configs/network/dns_top_domains.ts | 6 +- .../configs/network/kpi_dns_queries.ts | 6 +- .../configs/network/kpi_network_events.ts | 8 +- .../configs/network/kpi_tls_handshakes.ts | 4 +- .../configs/network/kpi_unique_flow_ids.ts | 4 +- .../network/kpi_unique_private_ips_area.ts | 6 +- .../network/kpi_unique_private_ips_bar.ts | 131 +----------------- ...i_unique_private_ips_destination_metric.ts | 4 +- .../kpi_unique_private_ips_source_metric.ts | 4 +- 22 files changed, 58 insertions(+), 233 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts index 082629372c818a..bd635bb4ad0e8e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts @@ -127,23 +127,23 @@ export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-a3c54471-615f-4ff9-9fda-69b5b2ea3eef', }, { type: 'index-pattern', name: '723c4653-681b-4105-956e-abef287bf025', - id: 'security-solution-default', + id: '{dataViewId}', }, { type: 'index-pattern', name: 'a04472fc-94a3-4b8d-ae05-9d30ea8fbd6a', - id: 'security-solution-default', + id: '{dataViewId}', }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts index 0c75e7a83c09c5..77059599d68b6a 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts @@ -169,23 +169,23 @@ export const authentication: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-3fd0c5d5-f762-4a27-8c56-14eee0223e13', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-bef502be-e5ff-442f-9e3e-229f86ca2afa', }, { type: 'index-pattern', name: '6f4dbdc7-35b6-4e20-ac53-1272167e3919', - id: 'security-solution-default', + id: '{dataViewId}', }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts index 2c5a6d211dff7b..0982b5017552a1 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts @@ -110,12 +110,12 @@ export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'eve references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-0039eb0c-9a1a-4687-ae54-0f4e239bec75', }, ], diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts index fdcb620f4da38b..ce6327c7ecb718 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts @@ -71,19 +71,14 @@ export const kpiHostArea: LensAttributes = { visualizationType: 'lnsXY', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-416b6fad-1923-4f6a-a2df-b223bb287e30', type: 'index-pattern', }, - { - id: '880973d0-89cb-11ec-acbb-112a5cf3323a', - name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', - type: 'tag', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts index dbfdd5a9d6f7ee..923ef2a92feaa4 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts @@ -43,19 +43,14 @@ export const kpiHostMetric: LensAttributes = { visualizationType: 'lnsMetric', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-416b6fad-1923-4f6a-a2df-b223bb287e30', type: 'index-pattern', }, - { - id: '880973d0-89cb-11ec-acbb-112a5cf3323a', - name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', - type: 'tag', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts index 37a27cf7266a64..37e45e3a862019 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts @@ -108,25 +108,20 @@ export const kpiUniqueIpsArea: LensAttributes = { visualizationType: 'lnsXY', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-ca05ecdb-0fa4-49a8-9305-b23d91012a46', type: 'index-pattern', }, - { - id: '880973d0-89cb-11ec-acbb-112a5cf3323a', - name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', - type: 'tag', - }, ], type: 'lens', updated_at: '2022-02-09T17:44:03.359Z', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts index f9403e2d574094..46992b4780504c 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts @@ -109,24 +109,19 @@ export const kpiUniqueIpsBar: LensAttributes = { visualizationType: 'lnsXY', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e', type: 'index-pattern', }, - { - id: '880973d0-89cb-11ec-acbb-112a5cf3323a', - name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', - type: 'tag', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts index 0ca6eb2e1c9ab9..24f79b47a7d0cc 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts @@ -43,19 +43,14 @@ export const kpiUniqueIpsDestinationMetric: LensAttributes = { visualizationType: 'lnsMetric', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', type: 'index-pattern', }, - { - id: '880973d0-89cb-11ec-acbb-112a5cf3323a', - name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', - type: 'tag', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts index dcf30e7662df02..bc08d2f77a13f4 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts @@ -43,19 +43,14 @@ export const kpiUniqueIpsSourceMetric: LensAttributes = { visualizationType: 'lnsMetric', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', type: 'index-pattern', }, - { - id: '880973d0-89cb-11ec-acbb-112a5cf3323a', - name: 'tag-ref-880973d0-89cb-11ec-acbb-112a5cf3323a', - type: 'tag', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts index 6e95e19faa933c..3f46295604fd8e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts @@ -76,18 +76,13 @@ export const kpiUserAuthenticationsMetricFailure: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-4590dafb-4ac7-45aa-8641-47a3ff0b817c', }, - { - type: 'tag', - id: 'security-solution-default', - name: 'tag-ref-security-solution-default', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts index 94382cb2029af0..e7105615f5ed5e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts @@ -182,24 +182,19 @@ export const kpiUserAuthenticationsArea: LensAttributes = { }, references: [ { - type: 'index-pattern', + type: '{dataViewId}', id: 'security-solution-default', name: 'indexpattern-datasource-current-indexpattern', }, { - type: 'index-pattern', + type: '{dataViewId}', id: 'security-solution-default', name: 'indexpattern-datasource-layer-31213ae3-905b-4e88-b987-0cccb1f3209f', }, { - type: 'index-pattern', + type: '{dataViewId}', id: 'security-solution-default', name: 'indexpattern-datasource-layer-4590dafb-4ac7-45aa-8641-47a3ff0b817c', }, - { - type: 'tag', - id: 'security-solution-default', - name: 'tag-ref-security-solution-default', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts index aa2255fe813a46..11314b1bb03044 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts @@ -184,23 +184,18 @@ export const kpiUserAuthenticationsBar: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-31213ae3-905b-4e88-b987-0cccb1f3209f', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-b9acd453-f476-4467-ad38-203e37b73e55', }, - { - type: 'tag', - id: 'security-solution-default', - name: 'tag-ref-security-solution-default', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts index 34e469a2f00919..af670207c54fad 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts @@ -77,18 +77,13 @@ export const kpiUserAuthenticationsMetricSuccess: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-4590dafb-4ac7-45aa-8641-47a3ff0b817c', }, - { - type: 'tag', - id: 'security-solution-default', - name: 'tag-ref-security-solution-default', - }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts index 8c7d85626a16e9..13f3a47163ca72 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts @@ -144,18 +144,18 @@ export const dnsTopDomainsAttrs: LensAttributes = { references: [ { type: 'index-pattern', - id: 'filebeat-*', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'logs-*', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-b1c3efc6-c886-4fba-978f-3b6bb5e7948a', }, { name: 'filter-index-pattern-0', type: 'index-pattern', - id: 'logs-*', + id: '{dataViewId}', }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts index db0ac37ce7f8a5..44b9d919bc47dc 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts @@ -88,18 +88,18 @@ export const kpiDnsQueries: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', }, { type: 'index-pattern', name: '196d783b-3779-4c39-898e-6606fe633d05', - id: 'security-solution-default', + id: '{dataViewId}', }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts index 8b1e054140304e..4904df154305a0 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts @@ -86,23 +86,23 @@ export const kpiNetworkEvents: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-eaadfec7-deaa-4aeb-a403-3b4e516416d2', }, { type: 'index-pattern', name: '861af17d-be25-45a3-a82d-d6e697b76e51', - id: 'security-solution-default', + id: '{dataViewId}', }, { type: 'index-pattern', name: '09617767-f732-410e-af53-bebcbd0bf4b9', - id: 'security-solution-default', + id: '{dataViewId}', }, ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts index b0a9ae7cf0a1b9..7789ec8ed52885 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts @@ -117,12 +117,12 @@ export const kpiTlsHandshakes: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-1f48a633-8eee-45ae-9471-861227e9ca03', }, ], diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts index 136a44a86df047..13d2a86b02955d 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts @@ -80,12 +80,12 @@ export const kpiUniqueFlowIds: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-5d46d48f-6ce8-46be-a797-17ad50642564', }, ], diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts index 5a90246f3f47ad..78a619eee14c2f 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts @@ -157,17 +157,17 @@ export const kpiUniquePrivateIpsArea: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-72dc4b99-b07d-4dc9-958b-081d259e11fa', }, ], diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts index 24d36efd50cbd1..7f5e82bd92fbb3 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts @@ -174,143 +174,18 @@ export const kpiUniquePrivateIpsBar: LensAttributes = { references: [ { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-e406bf4f-942b-41ac-b516-edb5cef06ec8', }, { type: 'index-pattern', - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-38aa6532-6bf9-4c8f-b2a6-da8d32f7d0d7', }, ], - - // description: '', - // state: { - // datasourceStates: { - // indexpattern: { - // layers: { - // '8be0156b-d423-4a39-adf1-f54d4c9f2e69': { - // columnOrder: [ - // 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e', - // '32f66676-f4e1-48fd-b7f8-d4de38318601', - // ], - // columns: { - // '32f66676-f4e1-48fd-b7f8-d4de38318601': { - // dataType: 'number', - // filter: { - // language: 'kuery', - // query: - // 'source.ip: "10.0.0.0/8" or source.ip: "192.168.0.0/16" or source.ip: "172.16.0.0/12" or source.ip: "fd00::/8"', - // }, - // isBucketed: false, - // label: 'Unique count of source.ip', - // operationType: 'unique_count', - // scale: 'ratio', - // sourceField: 'source.ip', - // }, - // 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e': { - // dataType: 'string', - // isBucketed: true, - // label: 'Filters', - // operationType: 'filters', - // params: { filters: [{ input: { language: 'kuery', query: '' }, label: 'Src.' }] }, - // scale: 'ordinal', - // }, - // }, - // incompleteColumns: {}, - // }, - // 'ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e': { - // columnOrder: [ - // 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff', - // 'b7e59b08-96e6-40d1-84fd-e97b977d1c47', - // ], - // columns: { - // 'b7e59b08-96e6-40d1-84fd-e97b977d1c47': { - // dataType: 'number', - // filter: { - // language: 'kuery', - // query: - // '"destination.ip": "10.0.0.0/8" or "destination.ip": "192.168.0.0/16" or "destination.ip": "172.16.0.0/12" or "destination.ip": "fd00::/8"', - // }, - // isBucketed: false, - // label: 'Unique count of destination.ip', - // operationType: 'unique_count', - // scale: 'ratio', - // sourceField: 'destination.ip', - // }, - // 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff': { - // customLabel: true, - // dataType: 'string', - // isBucketed: true, - // label: 'Dest.', - // operationType: 'filters', - // params: { - // filters: [{ input: { language: 'kuery', query: '' }, label: 'Dest.' }], - // }, - // scale: 'ordinal', - // }, - // }, - // incompleteColumns: {}, - // }, - // }, - // }, - // }, - // filters: [], - // query: { language: 'kuery', query: '' }, - // visualization: { - // axisTitlesVisibilitySettings: { x: false, yLeft: false, yRight: true }, - // fittingFunction: 'None', - // gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true }, - // labelsOrientation: { x: 0, yLeft: 0, yRight: 0 }, - // layers: [ - // { - // accessors: ['32f66676-f4e1-48fd-b7f8-d4de38318601'], - // layerId: '8be0156b-d423-4a39-adf1-f54d4c9f2e69', - // layerType: 'data', - // seriesType: 'bar_horizontal_stacked', - // xAccessor: 'f8bfa719-5c1c-4bf2-896e-c318d77fc08e', - // yConfig: [{ color: '#d36186', forAccessor: '32f66676-f4e1-48fd-b7f8-d4de38318601' }], - // }, - // { - // accessors: ['b7e59b08-96e6-40d1-84fd-e97b977d1c47'], - // layerId: 'ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e', - // layerType: 'data', - // seriesType: 'bar_horizontal_stacked', - // xAccessor: 'c72aad6a-fc9c-43dc-9194-e13ca3ee8aff', - // yConfig: [{ color: '#9170b8', forAccessor: 'b7e59b08-96e6-40d1-84fd-e97b977d1c47' }], - // }, - // ], - // legend: { isVisible: false, position: 'right', showSingleSeries: false }, - // preferredSeriesType: 'bar_horizontal_stacked', - // tickLabelsVisibilitySettings: { x: true, yLeft: true, yRight: true }, - // valueLabels: 'hide', - // yLeftExtent: { mode: 'full' }, - // yRightExtent: { mode: 'full' }, - // }, - // }, - // title: '[Host] KPI Unique IPs - bar', - // visualizationType: 'lnsXY', - // references: [ - // { - // id: 'security-solution-default', - // name: 'indexpattern-datasource-current-indexpattern', - // type: 'index-pattern', - // }, - // { - // id: 'security-solution-default', - // name: 'indexpattern-datasource-layer-8be0156b-d423-4a39-adf1-f54d4c9f2e69', - // type: 'index-pattern', - // }, - // { - // id: 'security-solution-default', - // name: 'indexpattern-datasource-layer-ec84ba70-2adb-4647-8ef0-8ad91a0e6d4e', - // type: 'index-pattern', - // }, - // { id: 'security-solution-default', name: 'tag-ref-security-solution-default', type: 'tag' }, - // ], } as LensAttributes; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts index 66a035f36cd186..559ad218f77fa3 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts @@ -52,12 +52,12 @@ export const kpiUniquePrivateIpsDestinationMetric: LensAttributes = { visualizationType: 'lnsMetric', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', type: 'index-pattern', }, diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts index bf252cba37a7e9..43787808ee6488 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts @@ -51,12 +51,12 @@ export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { visualizationType: 'lnsMetric', references: [ { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-current-indexpattern', type: 'index-pattern', }, { - id: 'security-solution-default', + id: '{dataViewId}', name: 'indexpattern-datasource-layer-cea37c70-8f91-43bf-b9fe-72d8c049f6a3', type: 'index-pattern', }, From b1e0ccc162b9e5d465dbddb5ad8f6c6e12cf0124 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 02:36:43 +0800 Subject: [PATCH 35/59] update icon and wording --- .../common/components/visualization_actions/index.tsx | 2 +- .../components/visualization_actions/translations.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index edc469ca09bf31..13aefc0abaa38a 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -178,7 +178,7 @@ const VisualizationActionsComponent: React.FC = ({ {SAVE_VISUALIZATION}
, Date: Wed, 9 Mar 2022 03:38:28 +0800 Subject: [PATCH 36/59] fix unit tests --- .../hover_actions/actions/show_top_n.test.tsx | 17 +++++++++++++++++ .../public/hosts/pages/hosts.test.tsx | 17 +++++++++++++++++ .../public/network/pages/network.test.tsx | 4 ++++ .../alerts_by_category/index.test.tsx | 17 +++++++++++++++++ .../__snapshots__/index.test.tsx.snap | 4 ++-- .../public/users/pages/users_tabs.test.tsx | 15 +++++++++++++++ 6 files changed, 72 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx index 99ffe717cac432..cff955757316e7 100644 --- a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx @@ -7,6 +7,7 @@ import { EuiButtonEmpty, EuiContextMenuItem } from '@elastic/eui'; import { mount } from 'enzyme'; import React from 'react'; +import { mockCasesContext } from '../../../../../../cases/public/mocks/mock_cases_context'; import { TestProviders } from '../../../mock'; import { ShowTopNButton } from './show_top_n'; @@ -16,6 +17,22 @@ jest.mock('../../visualization_actions', () => ({ )), })); +jest.mock('../../../lib/kibana', () => { + const original = jest.requireActual('../../../lib/kibana'); + + return { + ...original, + useKibana: () => ({ + services: { + ...original.useKibana().services, + cases: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, + }, + }), + }; +}); + describe('show topN button', () => { const defaultProps = { field: 'signal.rule.name', diff --git a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx index d176d1c502fe2c..51cfc0758d6f62 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx @@ -24,6 +24,7 @@ import { State, createStore } from '../../common/store'; import { Hosts } from './hosts'; import { HostsTabs } from './hosts_tabs'; import { useSourcererDataView } from '../../common/containers/sourcerer'; +import { mockCasesContext } from '../../../../cases/public/mocks/mock_cases_context'; jest.mock('../../common/containers/sourcerer'); @@ -41,6 +42,22 @@ jest.mock('../../common/components/visualization_actions', () => ({ )), })); +jest.mock('../../common/lib/kibana', () => { + const original = jest.requireActual('../../common/lib/kibana'); + + return { + ...original, + useKibana: () => ({ + services: { + ...original.useKibana().services, + cases: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, + }, + }), + }; +}); + type Action = 'PUSH' | 'POP' | 'REPLACE'; const pop: Action = 'POP'; const location = { diff --git a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx index 7d4cd1c3e6a5b9..27e92133a64e5a 100644 --- a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx @@ -24,6 +24,7 @@ import { inputsActions } from '../../common/store/inputs'; import { Network } from './network'; import { NetworkRoutes } from './navigation'; +import { mockCasesContext } from '../../../../cases/public/mocks/mock_cases_context'; jest.mock('../../common/containers/sourcerer'); @@ -95,6 +96,9 @@ jest.mock('../../common/lib/kibana', () => { storage: { get: () => true, }, + cases: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, }, }), useToasts: jest.fn().mockReturnValue({ diff --git a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx index 98a77a5cad3cc8..89fc1649ecaa96 100644 --- a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx @@ -15,6 +15,7 @@ import { waitFor } from '@testing-library/react'; import { mockIndexPattern, TestProviders } from '../../../common/mock'; import { AlertsByCategory } from '.'; +import { mockCasesContext } from '../../../../../cases/public/mocks/mock_cases_context'; jest.mock('../../../common/components/link_to'); jest.mock('../../../common/components/visualization_actions', () => ({ @@ -27,6 +28,22 @@ jest.mock('../../../common/containers/matrix_histogram', () => ({ useMatrixHistogramCombined: jest.fn(), })); +jest.mock('../../../common/lib/kibana', () => { + const original = jest.requireActual('../../../common/lib/kibana'); + + return { + ...original, + useKibana: () => ({ + services: { + ...original.useKibana().services, + cases: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, + }, + }), + }; +}); + const from = '2020-03-31T06:00:00.000Z'; const to = '2019-03-31T06:00:00.000Z'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap index 36c59ec8441a01..5108fa86b0f56e 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: +exports[`Details Panel Component DetailsPanel: rendering it should not render the DetailsPanel if an expanded detail with a panelView, but not params have been set: ({ @@ -27,7 +28,21 @@ jest.mock('../../common/components/visualization_actions', () => ({
{'mockVizAction'}
)), })); +jest.mock('../../common/lib/kibana', () => { + const original = jest.requireActual('../../common/lib/kibana'); + return { + ...original, + useKibana: () => ({ + services: { + ...original.useKibana().services, + cases: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, + }, + }), + }; +}); type Action = 'PUSH' | 'POP' | 'REPLACE'; const pop: Action = 'POP'; const location = { From 95eb6b62439629ab2e95e1a85fe80ba17141ef65 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 03:45:42 +0800 Subject: [PATCH 37/59] useRouteSpy --- .../use_lens_attributes.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx index 91ef076da7a72d..2a923be7d3d0e1 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx @@ -6,12 +6,12 @@ */ import { useMemo } from 'react'; -import { useParams, useLocation } from 'react-router-dom'; import { SecurityPageName } from '../../../../common/constants'; import { NetworkRouteType } from '../../../network/pages/navigation/types'; import { useSourcererDataView } from '../../containers/sourcerer'; import { useDeepEqualSelector } from '../../hooks/use_selector'; import { inputsSelectors } from '../../store'; +import { useRouteSpy } from '../../utils/route/use_route_spy'; import { LensAttributes, GetLensAttributes } from './types'; import { getHostDetailsPageFilter, @@ -37,29 +37,26 @@ export const useLensAttributes = ({ ); const query = useDeepEqualSelector(getGlobalQuerySelector); const filters = useDeepEqualSelector(getGlobalFiltersQuerySelector); - const { detailName, tabName } = useParams<{ detailName: string | undefined; tabName: string }>(); - const location = useLocation(); + const [{ detailName, pageName, tabName }] = useRouteSpy(); + const tabsFilters = useMemo(() => { - if (location.pathname.includes(SecurityPageName.hosts) && tabName === 'externalAlerts') { + if (pageName === SecurityPageName.hosts && tabName === 'externalAlerts') { return filterHostExternalAlertData; } - if ( - location.pathname.includes(SecurityPageName.network) && - tabName === NetworkRouteType.alerts - ) { + if (pageName === SecurityPageName.network && tabName === NetworkRouteType.alerts) { return filterNetworkExternalAlertData; } return []; - }, [tabName, location.pathname]); + }, [pageName, tabName]); const pageFilters = useMemo(() => { if (location.pathname.includes(SecurityPageName.hosts) && detailName != null) { return getHostDetailsPageFilter(detailName); } return []; - }, [location.pathname, detailName]); + }, [detailName]); const indexFilters = useMemo(() => getIndexFilters(selectedPatterns), [selectedPatterns]); From 0d53394011f6e7f23a1c1917b6e66eacb40f2385 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 04:18:21 +0800 Subject: [PATCH 38/59] showInspectButton --- .../public/common/components/stat_items/index.tsx | 2 +- .../components/kpi_hosts/authentications/index.tsx | 1 - .../hosts/components/kpi_hosts/common/index.tsx | 5 ++--- .../hosts/components/kpi_hosts/hosts/index.tsx | 1 - .../components/kpi_hosts/unique_ips/index.tsx | 1 - .../components/kpi_network/common/index.tsx | 14 ++------------ .../network/components/kpi_network/dns/index.tsx | 1 - .../kpi_network/network_events/index.tsx | 1 - .../kpi_network/tls_handshakes/index.tsx | 1 - .../components/kpi_network/unique_flows/index.tsx | 1 - .../kpi_network/unique_private_ips/index.tsx | 1 - 11 files changed, 5 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index cb977a0dd5001b..975f8180b3e254 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -213,7 +213,7 @@ export const StatItemsComponent = React.memo( from, grow, id, - showInspectButton = true, + showInspectButton, index, narrowDateRange, statKey = 'item', diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx index 8d16a686d7ac6d..cc9a3668781117 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx @@ -77,7 +77,6 @@ const HostsKpiAuthenticationsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx index 88dc67533d63d6..3663fd890836c6 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx @@ -38,11 +38,10 @@ interface HostsKpiBaseComponentProps { from: string; to: string; narrowDateRange: UpdateDateRange; - showInspectButton?: boolean; } export const HostsKpiBaseComponent = React.memo( - ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange, showInspectButton }) => { + ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange }) => { const { cases } = useKibana().services; const CasesContext = cases.getCasesContext(); const userPermissions = useGetUserCasesPermissions(); @@ -65,7 +64,7 @@ export const HostsKpiBaseComponent = React.memo( {statItemsProps.map((mappedStatItemProps) => ( - + ))} diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx index 25f09d7a504bd8..f947c1121773a5 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx @@ -62,7 +62,6 @@ const HostsKpiHostsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx index 52587a12d8c49d..1b1e14d495b2a0 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx @@ -77,7 +77,6 @@ const HostsKpiUniqueIpsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx index cd2911cf8386b7..5d656a1c104f23 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx @@ -38,18 +38,8 @@ export const NetworkKpiBaseComponent = React.memo<{ from: string; to: string; narrowDateRange: UpdateDateRange; - showInspectButton?: boolean; }>( - ({ - fieldsMapping, - data, - id, - loading = false, - from, - to, - narrowDateRange, - showInspectButton = true, - }) => { + ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange }) => { const { cases } = useKibana().services; const CasesContext = cases.getCasesContext(); const userPermissions = useGetUserCasesPermissions(); @@ -78,7 +68,7 @@ export const NetworkKpiBaseComponent = React.memo<{ {statItemsProps.map((mappedStatItemProps) => ( - + ))} diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx index c478025fd2e93b..8a774724fccac2 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx @@ -57,7 +57,6 @@ const NetworkKpiDnsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx index 0e267673c4891f..e97eb8420e6c2c 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx @@ -62,7 +62,6 @@ const NetworkKpiNetworkEventsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx index dc5f55b1271421..e0d7420f5df18d 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx @@ -57,7 +57,6 @@ const NetworkKpiTlsHandshakesComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx index 8f7d96197c6340..0bd83ebcb9b40d 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx @@ -57,7 +57,6 @@ const NetworkKpiUniqueFlowsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx index 1370a1079a1815..1ea058a1745464 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx @@ -82,7 +82,6 @@ const NetworkKpiUniquePrivateIpsComponent: React.FC = ({ narrowDateRange={narrowDateRange} refetch={refetch} setQuery={setQuery} - showInspectButton={false} /> ); }; From 224a8ac1021f02f8f96e03ae794338d76c55c825 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 04:23:00 +0800 Subject: [PATCH 39/59] add aria label --- .../common/components/visualization_actions/index.tsx | 2 ++ .../components/visualization_actions/translations.ts | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 13aefc0abaa38a..d60778a09ce589 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -22,6 +22,7 @@ import { ADD_TO_EXISTING_CASE, ADD_TO_NEW_CASE, INSPECT, + MORE_ACTIONS, OPEN_IN_LENS, SAVE_VISUALIZATION, } from './translations'; @@ -225,6 +226,7 @@ const VisualizationActionsComponent: React.FC = ({ iconType="boxesHorizontal" onClick={onButtonClick} data-test-subj={dataTestSubj} + aria-label={MORE_ACTIONS} /> ); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts index 5ae1b514d038bd..77fa25b8cd8e5e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/translations.ts @@ -7,6 +7,13 @@ import { i18n } from '@kbn/i18n'; +export const MORE_ACTIONS = i18n.translate( + 'xpack.securitySolution.visualizationActions.moreActions', + { + defaultMessage: 'More actions', + } +); + export const INSPECT = i18n.translate('xpack.securitySolution.visualizationActions.inspect', { defaultMessage: 'Inspect visualization', }); From 85cdc6407605e594168866a5284754929e17ec27 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 04:37:18 +0800 Subject: [PATCH 40/59] rm type casting --- .../visualization_actions/index.tsx | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index d60778a09ce589..45f8c4cffba914 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -8,7 +8,6 @@ import { EuiButtonIcon, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } fr import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; -import { LensEmbeddableInput } from '../../../../../lens/public'; import { useKibana } from '../../lib/kibana/kibana_react'; import { ModalInspectQuery } from '../inspect/modal'; @@ -64,9 +63,9 @@ const VisualizationActionsComponent: React.FC = ({ const [isPopoverOpen, setPopover] = useState(false); const [isSaveModalVisible, setIsSaveModalVisible] = useState(false); - const onButtonClick = () => { + const onButtonClick = useCallback(() => { setPopover(!isPopoverOpen); - }; + }, [isPopoverOpen]); const closePopover = () => { setPopover(false); @@ -220,23 +219,34 @@ const VisualizationActionsComponent: React.FC = ({ ] ); - const button = ( - + const button = useMemo( + () => ( + + ), + [dataTestSubj, onButtonClick] + ); + + const initialInput = useMemo( + () => + attributes != null + ? { + id: 'saveVisualizationModal', + attributes, + } + : null, + [attributes] ); return ( - {isSaveModalVisible && ( - + {isSaveModalVisible && initialInput != null && ( + )} {request !== null && response !== null && ( Date: Wed, 9 Mar 2022 05:45:34 +0800 Subject: [PATCH 41/59] unit test --- .../visualization_actions/index.test.tsx | 268 ++++++++++++++++++ .../visualization_actions/index.tsx | 3 +- 2 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx new file mode 100644 index 00000000000000..6c5eecbad7a680 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx @@ -0,0 +1,268 @@ +/* + * 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 { fireEvent, render, screen } from '@testing-library/react'; +import { dnsTopDomainsAttrs } from './configs/network/dns_top_domains'; +import { VisualizationActions } from '.'; +import { + createSecuritySolutionStorageMock, + kibanaObservable, + mockGlobalState, + SUB_PLUGINS_REDUCER, + TestProviders, +} from '../../mock'; +import { createStore, State } from '../../store'; +import { UpdateQueryParams, upsertQuery } from '../../store/inputs/helpers'; +import { cloneDeep } from 'lodash'; +import { useKibana } from '../../lib/kibana/kibana_react'; +import { CASES_FEATURE_ID } from '../../../../common/constants'; +import { mockCasesContext } from '../../../../../cases/public/mocks/mock_cases_context'; +jest.mock('react-router-dom', () => { + const actual = jest.requireActual('react-router-dom'); + return { + ...actual, + useLocation: jest.fn(() => { + return { pathname: 'network' }; + }), + }; +}); +jest.mock('../../lib/kibana/kibana_react'); +jest.mock('../../utils/route/use_route_spy', () => { + return { + useRouteSpy: jest.fn(() => [{ pageName: 'network', detailName: '', tabName: 'dns' }]), + }; +}); +describe('VisualizationActions', () => { + const refetch = jest.fn(); + const state: State = mockGlobalState; + const { storage } = createSecuritySolutionStorageMock(); + const newQuery: UpdateQueryParams = { + inputId: 'global', + id: 'networkDnsHistogramQuery', + inspect: { + dsl: ['mockDsl'], + response: ['mockResponse'], + }, + loading: false, + refetch, + state: state.inputs, + }; + + let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const props = { + lensAttributes: dnsTopDomainsAttrs, + queryId: 'networkDnsHistogramQuery', + timerange: { + from: '2022-03-06T16:00:00.000Z', + to: '2022-03-07T15:59:59.999Z', + }, + title: 'mock networkDnsHistogram', + }; + const mockNavigateToPrefilledEditor = jest.fn(); + const MockLensSaveModalComponent = jest.fn(() => ( +
{'mockLensSaveModal'}
+ )); + const mockGetCreateCaseFlyoutOpen = jest.fn(); + const mockGetAllCasesSelectorModalOpen = jest.fn(); + + beforeEach(() => { + jest.clearAllMocks(); + (useKibana as jest.Mock).mockReturnValue({ + services: { + lens: { + canUseEditor: jest.fn(() => true), + navigateToPrefilledEditor: mockNavigateToPrefilledEditor, + SaveModalComponent: MockLensSaveModalComponent, + }, + cases: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + hooks: { + getUseCasesAddToExistingCaseModal: jest + .fn() + .mockReturnValue({ open: mockGetAllCasesSelectorModalOpen }), + getUseCasesAddToNewCaseFlyout: jest + .fn() + .mockReturnValue({ open: mockGetCreateCaseFlyoutOpen }), + }, + }, + application: { + capabilities: { [CASES_FEATURE_ID]: { crud_cases: true, read_cases: true } }, + getUrlForApp: jest.fn(), + navigateToApp: jest.fn(), + }, + notifications: { + toasts: { + addError: jest.fn(), + addSuccess: jest.fn(), + addWarning: jest.fn(), + }, + }, + http: jest.fn(), + data: { + search: jest.fn(), + }, + storage: { + set: jest.fn(), + }, + theme: {}, + }, + }); + const myState = cloneDeep(state); + myState.inputs = upsertQuery(newQuery); + store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + }); + + test('Should render VisualizationActions button', () => { + const { container } = render( + + + + ); + expect( + container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`) + ).toBeInTheDocument(); + }); + + test('Should render Open in Lens button', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + + expect(screen.getByText('Open in Lens')).toBeInTheDocument(); + expect(screen.getByText('Open in Lens')).not.toBeDisabled(); + }); + + test('Should call NavigateToPrefilledEditor when Open in Lens', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + + fireEvent.click(screen.getByText('Open in Lens')); + expect(mockNavigateToPrefilledEditor.mock.calls[0][0].timeRange).toEqual(props.timerange); + expect(mockNavigateToPrefilledEditor.mock.calls[0][0].attributes.title).toEqual( + props.lensAttributes.title + ); + expect(mockNavigateToPrefilledEditor.mock.calls[0][0].attributes.references).toEqual([ + { + id: 'security-solution', + name: 'indexpattern-datasource-current-indexpattern', + type: 'index-pattern', + }, + { + id: 'security-solution', + name: 'indexpattern-datasource-layer-b1c3efc6-c886-4fba-978f-3b6bb5e7948a', + type: 'index-pattern', + }, + { id: 'security-solution', name: 'filter-index-pattern-0', type: 'index-pattern' }, + ]); + expect(mockNavigateToPrefilledEditor.mock.calls[0][1].openInNewTab).toEqual(true); + }); + + test('Should render Save button', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + + expect(screen.getByText('Save visualization')).toBeInTheDocument(); + }); + + test('Should open LensSaveModal', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + fireEvent.click(screen.getByText('Save visualization')); + + expect(screen.getByText('mockLensSaveModal')).toBeInTheDocument(); + }); + + test('Should render Inspect visualization button', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + + expect(screen.getByText('Inspect visualization')).toBeInTheDocument(); + expect(screen.getByText('Inspect visualization')).not.toBeDisabled(); + }); + + test('Should render Inspect visualization Modal after clicking the inspect button', () => { + const { baseElement, container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + + expect(screen.getByText('Inspect visualization')).toBeInTheDocument(); + fireEvent.click(screen.getByText('Inspect visualization')); + expect( + baseElement.querySelector('[data-test-subj="modal-inspect-euiModal"]') + ).toBeInTheDocument(); + }); + + test('Should render Add to new case button', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + + expect(screen.getByText('Add to new case')).toBeInTheDocument(); + expect(screen.getByText('Add to new case')).not.toBeDisabled(); + }); + + test('Should render Add to new case modal after clicking on Add to new case button', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + fireEvent.click(screen.getByText('Add to new case')); + + expect(mockGetCreateCaseFlyoutOpen).toBeCalled(); + }); + + test('Should render Add to existing case button', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + + expect(screen.getByText('Add to existing case')).toBeInTheDocument(); + expect(screen.getByText('Add to existing case')).not.toBeDisabled(); + }); + + test('Should render Add to existing case modal after clicking on Add to existing case button', () => { + const { container } = render( + + + + ); + fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); + fireEvent.click(screen.getByText('Add to existing case')); + + expect(mockGetAllCasesSelectorModalOpen).toBeCalled(); + }); +}); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 45f8c4cffba914..7e02f51233fd99 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -62,6 +62,7 @@ const VisualizationActionsComponent: React.FC = ({ } = lens; const [isPopoverOpen, setPopover] = useState(false); const [isSaveModalVisible, setIsSaveModalVisible] = useState(false); + const [isInspectModalOpen, setIsInspectModalOpen] = useState(false); const onButtonClick = useCallback(() => { setPopover(!isPopoverOpen); @@ -120,8 +121,6 @@ const VisualizationActionsComponent: React.FC = ({ closePopover(); }, []); - const [isInspectModalOpen, setIsInspectModalOpen] = useState(false); - const onOpenInspectModal = useCallback(() => { closePopover(); setIsInspectModalOpen(true); From a289c86e03de7dd05b2566ab5abbcc1b2b320f91 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 20:06:40 +0800 Subject: [PATCH 42/59] rm id from filters --- .../public/common/components/visualization_actions/utils.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts index 6cac0cf8240a5e..9a6df2ab6ab998 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/utils.ts @@ -12,7 +12,6 @@ export const getHostDetailsPageFilter = (hostName?: string): Filter[] => ? [ { meta: { - index: 'e5bb994d-e8fb-4ddb-a36e-730ad8cc0712', alias: null, negate: false, disabled: false, @@ -119,7 +118,6 @@ export const getIndexFilters = (selectedPatterns: string[]) => ? [ { meta: { - index: '62d8e968-7ce3-4062-98b8-64b0e0bbff59', type: 'phrases', key: '_index', params: selectedPatterns, @@ -135,9 +133,6 @@ export const getIndexFilters = (selectedPatterns: string[]) => minimum_should_match: 1, }, }, - $state: { - store: 'appState', - }, }, ] : []; From c849a0aa36082084932e8b3391d918d45ad4a6a9 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 9 Mar 2022 21:03:50 +0800 Subject: [PATCH 43/59] use mockCasesContract --- .../common/components/visualization_actions/index.test.tsx | 4 ++-- .../security_solution/public/hosts/pages/hosts.test.tsx | 4 ++-- .../security_solution/public/network/pages/network.test.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx index 6c5eecbad7a680..4fd4111c265696 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx @@ -20,7 +20,7 @@ import { UpdateQueryParams, upsertQuery } from '../../store/inputs/helpers'; import { cloneDeep } from 'lodash'; import { useKibana } from '../../lib/kibana/kibana_react'; import { CASES_FEATURE_ID } from '../../../../common/constants'; -import { mockCasesContext } from '../../../../../cases/public/mocks/mock_cases_context'; +import { mockCasesContract } from '../../../../../cases/public/mocks'; jest.mock('react-router-dom', () => { const actual = jest.requireActual('react-router-dom'); return { @@ -79,7 +79,7 @@ describe('VisualizationActions', () => { SaveModalComponent: MockLensSaveModalComponent, }, cases: { - getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + ...mockCasesContract(), hooks: { getUseCasesAddToExistingCaseModal: jest .fn() diff --git a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx index 51cfc0758d6f62..a1a0542b84e027 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx @@ -24,7 +24,7 @@ import { State, createStore } from '../../common/store'; import { Hosts } from './hosts'; import { HostsTabs } from './hosts_tabs'; import { useSourcererDataView } from '../../common/containers/sourcerer'; -import { mockCasesContext } from '../../../../cases/public/mocks/mock_cases_context'; +import { mockCasesContract } from '../../../../cases/public/mocks'; jest.mock('../../common/containers/sourcerer'); @@ -51,7 +51,7 @@ jest.mock('../../common/lib/kibana', () => { services: { ...original.useKibana().services, cases: { - getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + ...mockCasesContract(), }, }, }), diff --git a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx index 27e92133a64e5a..d8a1dc6ff0c0df 100644 --- a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx @@ -24,7 +24,7 @@ import { inputsActions } from '../../common/store/inputs'; import { Network } from './network'; import { NetworkRoutes } from './navigation'; -import { mockCasesContext } from '../../../../cases/public/mocks/mock_cases_context'; +import { mockCasesContract } from '../../../../cases/public/mocks'; jest.mock('../../common/containers/sourcerer'); @@ -97,7 +97,7 @@ jest.mock('../../common/lib/kibana', () => { get: () => true, }, cases: { - getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + ...mockCasesContract(), }, }, }), From 7f9da304f9785ebd75fb2264e678e5fe9beb8363 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 10 Mar 2022 00:16:25 +0800 Subject: [PATCH 44/59] add unit tests --- .../use_add_to_existing_case.test.tsx | 92 ++++++++++ .../use_add_to_existing_case.tsx | 4 +- .../use_add_to_new_case.test.tsx | 86 ++++++++++ .../use_add_to_new_case.tsx | 4 +- .../use_lens_attributes.test.tsx | 157 ++++++++++++++++++ .../use_lens_attributes.tsx | 4 +- 6 files changed, 341 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx new file mode 100644 index 00000000000000..e2070cad9bd38d --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx @@ -0,0 +1,92 @@ +/* + * 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 { mockCasesContract } from '../../../../../cases/public/mocks'; +import { useKibana } from '../../lib/kibana'; +import { kpiHostMetric } from './configs/hosts/kpi_host_metric'; +import { useAddToExistingCase } from './use_add_to_existing_case'; + +jest.mock('../../lib/kibana/kibana_react'); + +describe('', () => { + const mockCases = mockCasesContract(); + const mockOnAddToCaseClicked = jest.fn(); + const timeRange = { + from: '2022-03-06T16:00:00.000Z', + to: '2022-03-07T15:59:59.999Z', + }; + const owner = 'securitySolution'; + const type = 'user'; + beforeEach(() => { + (useKibana as jest.Mock).mockReturnValue({ + services: { + cases: mockCases, + }, + }); + }); + + it('getUseCasesAddToExistingCaseModal with attachments', () => { + const { result } = renderHook(() => + useAddToExistingCase({ + lensAttributes: kpiHostMetric, + timeRange, + userCanCrud: true, + onAddToCaseClicked: mockOnAddToCaseClicked, + }) + ); + expect(mockCases.hooks.getUseCasesAddToExistingCaseModal).toHaveBeenCalledWith({ + attachments: [ + { + comment: `!{lens${JSON.stringify({ + timeRange, + attributes: kpiHostMetric, + })}}`, + owner, + type, + }, + ], + onClose: mockOnAddToCaseClicked, + }); + expect(result.current.disabled).toEqual(false); + }); + + it("button disalbled if user Can't Crud", () => { + const { result } = renderHook(() => + useAddToExistingCase({ + lensAttributes: kpiHostMetric, + timeRange, + userCanCrud: false, + onAddToCaseClicked: mockOnAddToCaseClicked, + }) + ); + expect(result.current.disabled).toEqual(true); + }); + + it('button disalbled if no lensAttributes', () => { + const { result } = renderHook(() => + useAddToExistingCase({ + lensAttributes: null, + timeRange, + userCanCrud: true, + onAddToCaseClicked: mockOnAddToCaseClicked, + }) + ); + expect(result.current.disabled).toEqual(true); + }); + + it('button disalbled if no timeRange', () => { + const { result } = renderHook(() => + useAddToExistingCase({ + lensAttributes: kpiHostMetric, + timeRange: null, + userCanCrud: true, + onAddToCaseClicked: mockOnAddToCaseClicked, + }) + ); + expect(result.current.disabled).toEqual(true); + }); +}); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx index 08ecb22ec8da8d..5a4ac6dd934e99 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx @@ -22,7 +22,7 @@ export const useAddToExistingCase = ({ }: { onAddToCaseClicked?: () => void; lensAttributes: LensAttributes | null; - timeRange: { from: string; to: string }; + timeRange: { from: string; to: string } | null; userCanCrud: boolean; }) => { const { cases } = useKibana().services; @@ -53,6 +53,6 @@ export const useAddToExistingCase = ({ return { onAddToExistingCaseClicked, - disabled: lensAttributes == null || !userCanCrud, + disabled: lensAttributes == null || timeRange == null || !userCanCrud, }; }; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx new file mode 100644 index 00000000000000..e48d9aedca4011 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx @@ -0,0 +1,86 @@ +/* + * 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 { mockCasesContract } from '../../../../../cases/public/mocks'; +import { useKibana } from '../../lib/kibana'; +import { kpiHostMetric } from './configs/hosts/kpi_host_metric'; +import { useAddToNewCase } from './use_add_to_new_case'; + +jest.mock('../../lib/kibana/kibana_react'); + +describe('', () => { + const mockCases = mockCasesContract(); + const timeRange = { + from: '2022-03-06T16:00:00.000Z', + to: '2022-03-07T15:59:59.999Z', + }; + const owner = 'securitySolution'; + const type = 'user'; + beforeEach(() => { + (useKibana as jest.Mock).mockReturnValue({ + services: { + cases: mockCases, + }, + }); + }); + + it('getUseCasesAddToNewCaseFlyout with attachments', () => { + const { result } = renderHook(() => + useAddToNewCase({ + lensAttributes: kpiHostMetric, + timeRange, + userCanCrud: true, + }) + ); + expect(mockCases.hooks.getUseCasesAddToNewCaseFlyout).toHaveBeenCalledWith({ + attachments: [ + { + comment: `!{lens${JSON.stringify({ + timeRange, + attributes: kpiHostMetric, + })}}`, + owner, + type, + }, + ], + }); + expect(result.current.disabled).toEqual(false); + }); + + it("button disalbled if user Can't Crud", () => { + const { result } = renderHook(() => + useAddToNewCase({ + lensAttributes: kpiHostMetric, + timeRange, + userCanCrud: false, + }) + ); + expect(result.current.disabled).toEqual(true); + }); + + it('button disalbled if no lensAttributes', () => { + const { result } = renderHook(() => + useAddToNewCase({ + lensAttributes: null, + timeRange, + userCanCrud: true, + }) + ); + expect(result.current.disabled).toEqual(true); + }); + + it('button disalbled if no timeRange', () => { + const { result } = renderHook(() => + useAddToNewCase({ + lensAttributes: kpiHostMetric, + timeRange: null, + userCanCrud: true, + }) + ); + expect(result.current.disabled).toEqual(true); + }); +}); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx index 17eeaec6cfa61a..854894e81c48c7 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx @@ -15,7 +15,7 @@ import { LensAttributes } from './types'; export interface UseAddToNewCaseProps { onClick?: () => void; - timeRange: { from: string; to: string }; + timeRange: { from: string; to: string } | null; lensAttributes: LensAttributes | null; userCanCrud: boolean; } @@ -56,6 +56,6 @@ export const useAddToNewCase = ({ return { onAddToNewCaseClicked, - disabled: lensAttributes == null || !userCanCrud, + disabled: lensAttributes == null || timeRange == null || !userCanCrud, }; }; diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx new file mode 100644 index 00000000000000..c377f06d70d039 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx @@ -0,0 +1,157 @@ +/* + * 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 React from 'react'; +import { cloneDeep } from 'lodash/fp'; + +import { + TestProviders, + mockGlobalState, + SUB_PLUGINS_REDUCER, + kibanaObservable, + createSecuritySolutionStorageMock, +} from '../../mock'; +import { getExternalAlertConfigs } from './configs/common/external_alert'; +import { useLensAttributes } from './use_lens_attributes'; +import { filterHostExternalAlertData, getHostDetailsPageFilter, getIndexFilters } from './utils'; +import { createStore, State } from '../../store'; + +jest.mock('../../containers/sourcerer', () => ({ + useSourcererDataView: jest.fn().mockReturnValue({ + selectedPatterns: ['auditbeat-*'], + dataViewId: 'security-solution-default', + }), +})); + +jest.mock('../../utils/route/use_route_spy', () => ({ + useRouteSpy: jest.fn().mockReturnValue([ + { + detailName: 'mockHost', + pageName: 'hosts', + tabName: 'externalAlerts', + }, + ]), +})); + +describe('useLensAttributes', () => { + const state: State = mockGlobalState; + const { storage } = createSecuritySolutionStorageMock(); + const queryFromSearchBar = { + query: 'host.name: *', + language: 'kql', + }; + + const filterFromSearchBar = [ + { + meta: { + alias: null, + negate: false, + disabled: false, + type: 'phrase', + key: 'host.id', + params: { + query: '123', + }, + }, + query: { + match_phrase: { + 'host.id': '123', + }, + }, + }, + ]; + let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + + beforeEach(() => { + const myState = cloneDeep(state); + myState.inputs = { + ...myState.inputs, + global: { + ...myState.inputs.global, + query: queryFromSearchBar, + filters: filterFromSearchBar, + }, + }; + store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + }); + + it('should should add query', () => { + const wrapper = ({ children }: { children: React.ReactElement }) => ( + {children} + ); + const { result } = renderHook( + () => + useLensAttributes({ + getLensAttributes: getExternalAlertConfigs, + stackByField: 'event.dataset', + }), + { wrapper } + ); + + expect(result?.current?.state.query).toEqual({ query: 'host.name: *', language: 'kql' }); + }); + + it('should should add filters', () => { + const wrapper = ({ children }: { children: React.ReactElement }) => ( + {children} + ); + const { result } = renderHook( + () => + useLensAttributes({ + getLensAttributes: getExternalAlertConfigs, + stackByField: 'event.dataset', + }), + { wrapper } + ); + + expect(result?.current?.state.filters).toEqual([ + ...getExternalAlertConfigs().state.filters, + ...filterFromSearchBar, + ...getHostDetailsPageFilter('mockHost'), + ...filterHostExternalAlertData, + ...getIndexFilters(['auditbeat-*']), + ]); + }); + + it('should should add data view id to references', () => { + const wrapper = ({ children }: { children: React.ReactElement }) => ( + {children} + ); + const { result } = renderHook( + () => + useLensAttributes({ + getLensAttributes: getExternalAlertConfigs, + stackByField: 'event.dataset', + }), + { wrapper } + ); + + expect(result?.current?.references).toEqual([ + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-current-indexpattern', + }, + { + type: 'index-pattern', + id: 'security-solution-default', + name: 'indexpattern-datasource-layer-a3c54471-615f-4ff9-9fda-69b5b2ea3eef', + }, + { + type: 'index-pattern', + name: '723c4653-681b-4105-956e-abef287bf025', + id: 'security-solution-default', + }, + { + type: 'index-pattern', + name: 'a04472fc-94a3-4b8d-ae05-9d30ea8fbd6a', + id: 'security-solution-default', + }, + ]); + }); +}); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx index 2a923be7d3d0e1..123cff112456cd 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.tsx @@ -52,11 +52,11 @@ export const useLensAttributes = ({ }, [pageName, tabName]); const pageFilters = useMemo(() => { - if (location.pathname.includes(SecurityPageName.hosts) && detailName != null) { + if (pageName === SecurityPageName.hosts && detailName != null) { return getHostDetailsPageFilter(detailName); } return []; - }, [detailName]); + }, [detailName, pageName]); const indexFilters = useMemo(() => getIndexFilters(selectedPatterns), [selectedPatterns]); From 86ac400f707ebf107dbcc0b26829cd5df3ef91d0 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 10 Mar 2022 04:09:52 +0800 Subject: [PATCH 45/59] styling --- .../matrix_histogram/index.test.tsx | 27 ++++++++++++++++++- .../visualization_actions/index.tsx | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx index bcd855fb731871..bc228b230f0b4a 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx @@ -13,6 +13,7 @@ import { useMatrixHistogramCombined } from '../../containers/matrix_histogram'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; import { TestProviders } from '../../mock'; import { mockRuntimeMappings } from '../../containers/source/mock'; +import { dnsTopDomainsAttrs } from '../visualization_actions/configs/network/dns_top_domains'; jest.mock('../../lib/kibana'); @@ -21,7 +22,9 @@ jest.mock('./matrix_loader', () => ({ })); jest.mock('../header_section', () => ({ - HeaderSection: () =>
, + HeaderSection: ({ children }: { children: React.ReactElement }) => ( +
{children}
+ ), })); jest.mock('../charts/barchart', () => ({ @@ -32,6 +35,12 @@ jest.mock('../../containers/matrix_histogram', () => ({ useMatrixHistogramCombined: jest.fn(), })); +jest.mock('../visualization_actions', () => ({ + VisualizationActions: jest.fn(({ className }: { className: string }) => ( +
+ )), +})); + jest.mock('../../components/matrix_histogram/utils', () => ({ getBarchartConfigs: jest.fn(), getCustomChartData: jest.fn().mockReturnValue(true), @@ -145,4 +154,20 @@ describe('Matrix Histogram Component', () => { expect(wrapper.find('EuiSelect').exists()).toBe(false); }); }); + + describe('VisualizationActions', () => { + test('it renders a VisualizationActions if lensAttributes is provided', () => { + const testProps = { + ...mockMatrixOverTimeHistogramProps, + lensAttributes: dnsTopDomainsAttrs, + }; + wrapper = mount(, { + wrappingComponent: TestProviders, + }); + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true); + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').prop('className')).toEqual( + 'histogram-viz-actions' + ); + }); + }); }); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index 7e02f51233fd99..d2882d65bcd14e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -32,6 +32,9 @@ const Wrapper = styled.div` top: 0; right: 0; } + &.histogram-viz-actions { + padding: ${({ theme }) => theme.eui.paddingSizes.s}; + } `; export const HISTOGRAM_ACTIONS_BUTTON_CLASS = 'histogram-actions-trigger'; From 98df408388c65c8ea3895a47ff9c2ea050a85619 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 10 Mar 2022 04:10:01 +0800 Subject: [PATCH 46/59] update mock --- .../hover_actions/actions/show_top_n.test.tsx | 4 +-- .../components/matrix_histogram/index.tsx | 27 +++++++++++-------- .../common/components/top_n/index.test.tsx | 4 +-- .../common/components/top_n/top_n.test.tsx | 4 +-- .../hosts/pages/details/details_tabs.test.tsx | 4 +-- .../public/hosts/pages/hosts.test.tsx | 4 +-- .../public/network/pages/network.test.tsx | 4 +-- .../alerts_by_category/index.test.tsx | 4 +-- .../public/overview/pages/overview.test.tsx | 4 +-- .../public/users/pages/users_tabs.test.tsx | 4 +-- 10 files changed, 25 insertions(+), 38 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx index cff955757316e7..6c5f2f4535269b 100644 --- a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx @@ -12,9 +12,7 @@ import { TestProviders } from '../../../mock'; import { ShowTopNButton } from './show_top_n'; jest.mock('../../visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); jest.mock('../../../lib/kibana', () => { diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 7fbe2db29e433a..1c57e45d4f76fe 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -246,17 +246,22 @@ export const MatrixHistogramComponent: React.FC = isInspectDisabled={filterQuery === undefined} > - - - + {(getLensAttributes || lensAttributes) && timerange && ( + + + + + + )} {stackByOptions.length > 1 && ( ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); const field = 'process.name'; const value = 'nice'; diff --git a/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx b/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx index c5ad4c297084d4..f100966185e33f 100644 --- a/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/top_n/top_n.test.tsx @@ -30,9 +30,7 @@ jest.mock('react-router-dom', () => { jest.mock('../../lib/kibana'); jest.mock('../link_to'); jest.mock('../visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); jest.mock('uuid', () => { diff --git a/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx b/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx index 3b0f3ffea3c204..24910e5e313177 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx @@ -55,9 +55,7 @@ const mockUseResizeObserver: jest.Mock = useResizeObserver as jest.Mock; jest.mock('use-resize-observer/polyfilled'); mockUseResizeObserver.mockImplementation(() => ({})); jest.mock('../../../common/components/visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); describe('body', () => { diff --git a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx index a1a0542b84e027..86dae3780e1aed 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/hosts.test.tsx @@ -37,9 +37,7 @@ jest.mock('../../common/components/query_bar', () => ({ QueryBar: () => null, })); jest.mock('../../common/components/visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); jest.mock('../../common/lib/kibana', () => { diff --git a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx index d8a1dc6ff0c0df..1407bf960843e6 100644 --- a/x-pack/plugins/security_solution/public/network/pages/network.test.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/network.test.tsx @@ -37,9 +37,7 @@ jest.mock('../../common/components/query_bar', () => ({ QueryBar: () => null, })); jest.mock('../../common/components/visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); type Action = 'PUSH' | 'POP' | 'REPLACE'; diff --git a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx index 89fc1649ecaa96..6a06cf3efb3021 100644 --- a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx @@ -19,9 +19,7 @@ import { mockCasesContext } from '../../../../../cases/public/mocks/mock_cases_c jest.mock('../../../common/components/link_to'); jest.mock('../../../common/components/visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); jest.mock('../../../common/containers/matrix_histogram', () => ({ diff --git a/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx b/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx index 254efe734a9a3c..73a67ec97fad85 100644 --- a/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/pages/overview.test.tsx @@ -70,9 +70,7 @@ jest.mock('../../common/containers/local_storage/use_messages_storage'); jest.mock('../containers/overview_cti_links'); jest.mock('../../common/components/visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); const useCtiDashboardLinksMock = useCtiDashboardLinks as jest.Mock; diff --git a/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx b/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx index a9d6eb0b47becf..496c868d617b4f 100644 --- a/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx @@ -24,9 +24,7 @@ jest.mock('../../common/components/query_bar', () => ({ QueryBar: () => null, })); jest.mock('../../common/components/visualization_actions', () => ({ - VisualizationActions: jest.fn(() => ( -
{'mockVizAction'}
- )), + VisualizationActions: jest.fn(() =>
), })); jest.mock('../../common/lib/kibana', () => { const original = jest.requireActual('../../common/lib/kibana'); From 1ab5b9d829f316b94ec6eaf47f4be8081b80e0c8 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 10 Mar 2022 19:41:59 +0800 Subject: [PATCH 47/59] rm visualization actions cypress tests --- .../hosts/visualization_actions.spec.ts | 151 ---------------- .../network/visualization_actions.spec.ts | 93 ---------- .../cypress/screens/visualization_actions.ts | 171 ------------------ .../cypress/tasks/visualization_actions.ts | 64 ------- 4 files changed, 479 deletions(-) delete mode 100644 x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts delete mode 100644 x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts delete mode 100644 x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts delete mode 100644 x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts diff --git a/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts deleted file mode 100644 index a3c5b14e83ed6b..00000000000000 --- a/x-pack/plugins/security_solution/cypress/integration/hosts/visualization_actions.spec.ts +++ /dev/null @@ -1,151 +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 { INSPECT_MODAL } from '../../screens/inspect'; -import { cleanKibana } from '../../tasks/common'; - -import { closesModal } from '../../tasks/inspect'; -import { loginAndWaitForHostDetailsPage, loginAndWaitForPage } from '../../tasks/login'; - -import { HOSTS_URL } from '../../urls/navigation'; -import { - clickVizActionsAddToExistingCase, - clickVizActionsAddToNewCase, - clickVizActionsButton, - clickVizActionsInspect, - clickVizActionsOpenInLens, - clickVizActionsSave, - closeAllCasesModal, - closeCreateCaseFlyout, - closeSaveObjectModal, - vizActionsMenuShouldBeClosed, -} from '../../tasks/visualization_actions'; -import { - CREATE_CASE_FLYOUT, - SAVE_LENS_MODAL, - SELECT_CASE_MODAL, - VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY, - VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY, -} from '../../screens/visualization_actions'; - -describe('Visualization actions', () => { - before(() => { - cleanKibana(); - }); - context('Hosts', () => { - before(() => { - loginAndWaitForPage(HOSTS_URL); - }); - - VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY.forEach((button) => { - it(`inspects the ${button.title}`, () => { - clickVizActionsButton(button.id, button.tabId); - clickVizActionsInspect(); - vizActionsMenuShouldBeClosed(); - cy.get(INSPECT_MODAL).should('be.visible'); - closesModal(); - }); - - it(`save the ${button.title}`, () => { - clickVizActionsButton(button.id, button.tabId); - clickVizActionsSave(); - vizActionsMenuShouldBeClosed(); - cy.get(SAVE_LENS_MODAL).should('be.visible'); - - closeSaveObjectModal(); - }); - - it(`open the ${button.title} chart in Lens`, () => { - clickVizActionsButton(button.id, button.tabId); - - cy.window().then((win) => { - cy.stub(win, 'open').as('openInLens'); - }); - clickVizActionsOpenInLens(); - vizActionsMenuShouldBeClosed(); - - cy.get('@openInLens').should('be.called'); - }); - - it(`add the ${button.title} chart to a new case`, () => { - clickVizActionsButton(button.id, button.tabId); - - clickVizActionsAddToNewCase(); - vizActionsMenuShouldBeClosed(); - cy.get(CREATE_CASE_FLYOUT).should('exist'); - closeCreateCaseFlyout(); - }); - - it(`add the ${button.title} chart to an existing case`, () => { - clickVizActionsButton(button.id, button.tabId); - - clickVizActionsAddToExistingCase(); - vizActionsMenuShouldBeClosed(); - cy.get(SELECT_CASE_MODAL).should('exist'); - closeAllCasesModal(); - }); - }); - }); - - context('Host details', () => { - before(() => { - loginAndWaitForHostDetailsPage(); - }); - - VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY.forEach((button) => { - it(`inspects the ${button.title}`, () => { - clickVizActionsButton(button.id, button.tabId); - clickVizActionsInspect(); - vizActionsMenuShouldBeClosed(); - cy.get(INSPECT_MODAL).should('be.visible'); - closesModal(); - }); - - it(`save the ${button.title}`, () => { - clickVizActionsButton(button.id, button.tabId); - clickVizActionsSave(); - vizActionsMenuShouldBeClosed(); - cy.get(SAVE_LENS_MODAL).should('be.visible'); - - closeSaveObjectModal(); - }); - - it(`open the ${button.title} chart in Lens`, () => { - clickVizActionsButton(button.id, button.tabId); - - cy.window().then((win) => { - cy.stub(win, 'open').as('openInLens'); - }); - clickVizActionsOpenInLens(); - vizActionsMenuShouldBeClosed(); - - cy.get('@openInLens').should('be.called'); - }); - - it(`add the ${button.title} chart to a new case`, () => { - clickVizActionsButton(button.id, button.tabId); - - clickVizActionsAddToNewCase(); - vizActionsMenuShouldBeClosed(); - cy.get(CREATE_CASE_FLYOUT).should('exist'); - closeCreateCaseFlyout(); - }); - - it(`add the ${button.title} chart to a new case`, () => { - if (button.tabId) { - cy.get(button.tabId).click(); - } - cy.get(button.id).click({ force: true }); - - clickVizActionsAddToExistingCase(); - vizActionsMenuShouldBeClosed(); - cy.get(SELECT_CASE_MODAL).should('exist'); - closeAllCasesModal(); - }); - }); - }); -}); diff --git a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts b/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts deleted file mode 100644 index c5992c9034596d..00000000000000 --- a/x-pack/plugins/security_solution/cypress/integration/network/visualization_actions.spec.ts +++ /dev/null @@ -1,93 +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 { INSPECT_MODAL } from '../../screens/inspect'; -import { - CREATE_CASE_FLYOUT, - SAVE_LENS_MODAL, - SELECT_CASE_MODAL, - VIZ_ACTIONS_BUTTONS_IN_SECURITY, -} from '../../screens/visualization_actions'; -import { cleanKibana } from '../../tasks/common'; - -import { closesModal } from '../../tasks/inspect'; -import { loginAndWaitForPage } from '../../tasks/login'; -import { - clickVizActionsAddToExistingCase, - clickVizActionsAddToNewCase, - clickVizActionsButton, - clickVizActionsInspect, - clickVizActionsOpenInLens, - clickVizActionsSave, - closeAllCasesModal, - closeCreateCaseFlyout, - closeSaveObjectModal, - vizActionsMenuShouldBeClosed, -} from '../../tasks/visualization_actions'; - -import { NETWORK_URL } from '../../urls/navigation'; - -describe('Visualization actions', () => { - context('inspect', () => { - before(() => { - cleanKibana(); - loginAndWaitForPage(NETWORK_URL); - }); - - VIZ_ACTIONS_BUTTONS_IN_SECURITY.forEach((button) => { - it(`inspects the ${button.title}`, () => { - clickVizActionsButton(button.id, button.tabId); - clickVizActionsInspect(); - vizActionsMenuShouldBeClosed(); - cy.get(INSPECT_MODAL).should('be.visible'); - closesModal(); - }); - - it(`save the ${button.title}`, () => { - clickVizActionsButton(button.id, button.tabId); - clickVizActionsSave(); - vizActionsMenuShouldBeClosed(); - cy.get(SAVE_LENS_MODAL).should('be.visible'); - - closeSaveObjectModal(); - }); - - it(`open the ${button.title} chart in Lens`, () => { - clickVizActionsButton(button.id, button.tabId); - - cy.window().then((win) => { - cy.stub(win, 'open').as('openInLens'); - }); - clickVizActionsOpenInLens(); - vizActionsMenuShouldBeClosed(); - - cy.get('@openInLens').should('be.called'); - }); - - it(`add the ${button.title} chart to a new case`, () => { - clickVizActionsButton(button.id, button.tabId); - - clickVizActionsAddToNewCase(); - vizActionsMenuShouldBeClosed(); - cy.get(CREATE_CASE_FLYOUT).should('exist'); - closeCreateCaseFlyout(); - }); - - it(`add the ${button.title} chart to a new case`, () => { - if (button.tabId) { - cy.get(button.tabId).click(); - } - cy.get(button.id).click({ force: true }); - - clickVizActionsAddToExistingCase(); - vizActionsMenuShouldBeClosed(); - cy.get(SELECT_CASE_MODAL).should('exist'); - closeAllCasesModal(); - }); - }); - }); -}); diff --git a/x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts b/x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts deleted file mode 100644 index 2e252e8f9e2b32..00000000000000 --- a/x-pack/plugins/security_solution/cypress/screens/visualization_actions.ts +++ /dev/null @@ -1,171 +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. - */ - -export const VIZ_INSPECT_BUTTON = '[data-test-subj="viz-actions-inspect"]'; -export const VIZ_SAVE_BUTTON = `[data-test-subj="viz-actions-save"]`; -export const VIZ_OPEN_IN_LENS_BUTTON = '[data-test-subj="viz-actions-open-in-lens"]'; -export const VIZ_ADD_TO_NEW_CASE_BUTTON = '[data-test-subj="viz-actions-add-to-new-case"]'; -export const VIZ_ADD_TO_EXISTING_CASE_BUTTON = - '[data-test-subj="viz-actions-add-to-existing-case"]'; - -export const SELECT_CASE_MODAL = '[data-test-subj="all-cases-modal"]'; -export const SELECT_CASE_MODAL_CLOSE_BUTTON = `${SELECT_CASE_MODAL} .euiModal__closeIcon`; - -export const SAVE_LENS_MODAL = '[data-test-subj="savedObjectSaveModal"]'; -export const SAVE_LENS_MODAL_CLOSE_BUTTON = `${SAVE_LENS_MODAL} .euiModal__closeIcon`; -export const CREATE_CASE_FLYOUT = '[data-test-subj="create-case-flyout"]'; -export const CREATE_CASE_FLYOUT_CLOSE_BUTTON = `${CREATE_CASE_FLYOUT} [data-test-subj="euiFlyoutCloseButton"]`; - -export interface VizActionsButtonMetadata { - altInspectId?: string; - id: string; - title: string; - tabId?: string; -} - -export const VIZ_ACTIONS_HOSTS_DETAILS_BUTTONS_IN_SECURITY: VizActionsButtonMetadata[] = [ - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', - title: 'Unique IPs Stat - Success', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', - title: 'Unique IPs Stat - Failure', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', - title: 'User authentication - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', - title: 'User authentication - area', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', - title: 'Unique IPs - source', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', - title: 'Unique IPs - destination', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', - title: 'Unique IPs - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', - title: 'Unique IPs - area', - }, - { - id: '[data-test-subj="stat-authenticationsHistogramQuery"]', - title: 'Authentications histogram', - tabId: '[data-test-subj="navigation-authentications"]', - }, - { - id: '[data-test-subj="stat-eventsHistogramQuery"]', - title: 'Events histogram', - tabId: '[data-test-subj="navigation-events"]', - }, - { - id: '[data-test-subj="stat-alertsHistogramQuery"]', - title: 'External alert trend histogram', - tabId: '[data-test-subj="navigation-externalAlerts"]', - }, -]; - -export const VIZ_ACTIONS_HOSTS_BUTTONS_IN_SECURITY: VizActionsButtonMetadata[] = [ - { - id: '[data-test-subj="stat-hostsKpiHostsQuery-hosts-metric"]', - title: 'Hosts Stat', - }, - { - id: '[data-test-subj="stat-hostsKpiHostsQuery-area"]', - title: 'Hosts Stat - area', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsSuccess-metric"]', - title: 'Unique IPs Stat - Success', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-authenticationsFailure-metric"]', - title: 'Unique IPs Stat - Failure', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-bar_horizontal_stacked"]', - title: 'User authentication - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiAuthenticationsQuery-area"]', - title: 'User authentication - area', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueSourceIps-metric"]', - title: 'Unique IPs - source', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-uniqueDestinationIps-metric"]', - title: 'Unique IPs - destination', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-bar_horizontal_stacked"]', - title: 'Unique IPs - bar', - }, - { - id: '[data-test-subj="stat-hostsKpiUniqueIpsQuery-area"]', - title: 'Unique IPs - area', - }, - { - id: '[data-test-subj="stat-authenticationsHistogramQuery"]', - title: 'Authentications histogram', - tabId: '[data-test-subj="navigation-authentications"]', - }, - { - id: '[data-test-subj="stat-eventsHistogramQuery"]', - title: 'Events histogram', - tabId: '[data-test-subj="navigation-events"]', - }, - { - id: '[data-test-subj="stat-alertsHistogramQuery"]', - title: 'External alert trend histogram', - tabId: '[data-test-subj="navigation-externalAlerts"]', - }, -]; - -export const VIZ_ACTIONS_BUTTONS_IN_SECURITY: VizActionsButtonMetadata[] = [ - { - id: '[data-test-subj="stat-networkKpiNetworkEventsQuery-networkEvents-metric"]', - title: 'Inspect KPI Network events', - }, - { - id: '[data-test-subj="stat-networkKpiDnsQuery-dnsQueries-metric"]', - title: 'Inspect KPI DNS queries', - }, - { - id: '[data-test-subj="stat-networkKpiUniqueFlowsQuery-uniqueFlowId-metric"]', - title: 'Inspect KPI Unique flow IDs', - }, - { - id: '[data-test-subj="stat-networkKpiTlsHandshakesQuery-tlsHandshakes-metric"]', - title: 'Inspect KPI TLS handshakes', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueSourcePrivateIps-metric"]', - title: 'Inspect KPI Unique private IPs - source', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-uniqueDestinationPrivateIps-metric"]', - title: 'Inspect KPI Unique private IPs - dest.', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-bar_horizontal_stacked"]', - title: 'Inspect KPI Unique private IPs - bar chart', - }, - { - id: '[data-test-subj="stat-networkKpiUniquePrivateIpsQuery-area"]', - title: 'Inspect KPI Unique private IPs - area chart', - }, -]; diff --git a/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts b/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts deleted file mode 100644 index 077e763acf08cc..00000000000000 --- a/x-pack/plugins/security_solution/cypress/tasks/visualization_actions.ts +++ /dev/null @@ -1,64 +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 { - CREATE_CASE_FLYOUT_CLOSE_BUTTON, - SAVE_LENS_MODAL_CLOSE_BUTTON, - SELECT_CASE_MODAL_CLOSE_BUTTON, - VIZ_ADD_TO_EXISTING_CASE_BUTTON, - VIZ_ADD_TO_NEW_CASE_BUTTON, - VIZ_INSPECT_BUTTON, - VIZ_OPEN_IN_LENS_BUTTON, - VIZ_SAVE_BUTTON, -} from '../screens/visualization_actions'; - -export const clickVizActionsButton = (button: string, tab?: string) => { - if (tab) { - cy.get(tab).click(); - } - cy.get(button).click({ force: true }); -}; - -export const clickVizActionsInspect = () => { - cy.get(VIZ_INSPECT_BUTTON).click({ force: true }); -}; - -export const clickVizActionsSave = () => { - cy.get(VIZ_SAVE_BUTTON).click({ force: true }); -}; - -export const clickVizActionsOpenInLens = () => { - cy.get(VIZ_OPEN_IN_LENS_BUTTON).click({ force: true }); -}; - -export const clickVizActionsAddToNewCase = () => { - cy.get(VIZ_ADD_TO_NEW_CASE_BUTTON).click({ force: true }); -}; - -export const clickVizActionsAddToExistingCase = () => { - cy.get(VIZ_ADD_TO_EXISTING_CASE_BUTTON).click({ force: true }); -}; - -export const vizActionsMenuShouldBeClosed = () => { - cy.get(VIZ_INSPECT_BUTTON).should('not.exist'); - cy.get(VIZ_SAVE_BUTTON).should('not.exist'); - cy.get(VIZ_OPEN_IN_LENS_BUTTON).should('not.exist'); - cy.get(VIZ_ADD_TO_NEW_CASE_BUTTON).should('not.exist'); - cy.get(VIZ_ADD_TO_EXISTING_CASE_BUTTON).should('not.exist'); -}; - -export const closeSaveObjectModal = () => { - cy.get(SAVE_LENS_MODAL_CLOSE_BUTTON).click(); -}; - -export const closeCreateCaseFlyout = () => { - cy.get(CREATE_CASE_FLYOUT_CLOSE_BUTTON).click(); -}; - -export const closeAllCasesModal = () => { - cy.get(SELECT_CASE_MODAL_CLOSE_BUTTON).click(); -}; From 3476ae71370d242def74d0f736b7743db2293554 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 10 Mar 2022 19:53:59 +0800 Subject: [PATCH 48/59] clean up data-test-subj --- .../public/common/components/stat_items/index.tsx | 3 --- .../common/components/visualization_actions/index.tsx | 9 ++++----- .../common/components/visualization_actions/types.ts | 1 - 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 975f8180b3e254..979bb6f8d9e4bb 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -279,7 +279,6 @@ export const StatItemsComponent = React.memo( {field.lensAttributes && timerange && ( ( inspectIndex: index, timerange, title: `KPI ${description}`, - vizType: 'bar_horizontal_stacked', }} /> @@ -329,7 +327,6 @@ export const StatItemsComponent = React.memo( inspectIndex: index, timerange, title: `KPI ${description}`, - vizType: 'area', }} /> diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx index d2882d65bcd14e..8a4e630e0f189e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.tsx @@ -46,7 +46,6 @@ const VisualizationActionsComponent: React.FC = ({ inspectIndex = 0, isInspectButtonDisabled, isMultipleQuery, - vizType, lensAttributes, onCloseInspect, queryId, @@ -81,7 +80,7 @@ const VisualizationActionsComponent: React.FC = ({ stackByField, }); - const dataTestSubj = ['stat', queryId, vizType].filter((i) => i != null).join('-'); + const dataTestSubj = `stat-${queryId}`; const { disabled: isAddToExistingCaseDisabled, onAddToExistingCaseClicked } = useAddToExistingCase({ @@ -224,11 +223,11 @@ const VisualizationActionsComponent: React.FC = ({ const button = useMemo( () => ( ), [dataTestSubj, onButtonClick] @@ -246,7 +245,7 @@ const VisualizationActionsComponent: React.FC = ({ ); return ( - + {isSaveModalVisible && initialInput != null && ( )} diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts index f893adbe4bc698..9fc193e71b40d4 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/types.ts @@ -24,5 +24,4 @@ export interface VisualizationActionsProps { stackByField?: string; timerange: { from: string; to: string }; title: React.ReactNode; - vizType?: string | null; } From 92f090b60a00711f80a494209af15cf28c3b0be1 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 10 Mar 2022 21:14:24 +0800 Subject: [PATCH 49/59] disabled inspect button in matrix histogram by default --- .../common/components/alerts_viewer/index.tsx | 1 - .../components/header_section/index.tsx | 22 ++++++++----------- .../matrix_histogram/index.test.tsx | 15 ++++++++++++- .../components/matrix_histogram/index.tsx | 2 +- .../authentications_query_tab_body.tsx | 1 - .../navigation/events_query_tab_body.tsx | 1 - .../pages/navigation/dns_query_tab_body.tsx | 1 - .../components/alerts_by_category/index.tsx | 1 - .../components/events_by_dataset/index.tsx | 1 - 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx index be83e7df1c0bad..b0471a72c6ee6b 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/index.tsx @@ -69,7 +69,6 @@ const AlertsViewComponent: React.FC = ({ indexNames={indexNames} setQuery={setQuery} startDate={startDate} - showInspectButton={false} {...alertsHistogramConfigs} /> )} diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx index ead5725eac1cfd..ae07a03ba6407f 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.tsx @@ -100,19 +100,15 @@ const HeaderSectionComponent: React.FC = ({ )} - {id && ( - <> - {showInspectButton && ( - - - - )} - + {id && showInspectButton && ( + + + )} {headerFilters && {headerFilters}} diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx index bc228b230f0b4a..68c5800c8b1ed8 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx @@ -155,8 +155,21 @@ describe('Matrix Histogram Component', () => { }); }); + describe('Inspect button', () => { + test("it doesn't render Inspect button by default", () => { + const testProps = { + ...mockMatrixOverTimeHistogramProps, + lensAttributes: dnsTopDomainsAttrs, + }; + wrapper = mount(, { + wrappingComponent: TestProviders, + }); + expect(wrapper.find('[data-test-subj="inspect-icon-button"]').exists()).toBe(false); + }); + }); + describe('VisualizationActions', () => { - test('it renders a VisualizationActions if lensAttributes is provided', () => { + test('it renders VisualizationActions if lensAttributes is provided', () => { const testProps = { ...mockMatrixOverTimeHistogramProps, lensAttributes: dnsTopDomainsAttrs, diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 1c57e45d4f76fe..9117bf936767ea 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -93,7 +93,7 @@ export const MatrixHistogramComponent: React.FC = panelHeight = DEFAULT_PANEL_HEIGHT, setAbsoluteRangeDatePickerTarget = 'global', setQuery, - showInspectButton = true, + showInspectButton = false, showLegend, showSpacer = true, stackByOptions, diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx index 1b270804a82375..147863fa3da59c 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx @@ -106,7 +106,6 @@ const AuthenticationsQueryTabBodyComponent: React.FC indexNames={indexNames} setQuery={setQuery} startDate={startDate} - showInspectButton={false} {...histogramConfigs} /> diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx index 8b4391032e5a5d..803019bdb47bfb 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx @@ -111,7 +111,6 @@ const EventsQueryTabBodyComponent: React.FC = ({ startDate={startDate} id={EVENTS_HISTOGRAM_ID} indexNames={indexNames} - showInspectButton={false} {...histogramConfigs} /> )} diff --git a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx index 6ac11295a42a0c..e9c6d84fd5459d 100644 --- a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx @@ -110,7 +110,6 @@ const DnsQueryTabBodyComponent: React.FC = ({ setQuery={setQuery} showLegend={true} startDate={startDate} - showInspectButton={false} {...dnsHistogramConfigs} /> = ({ indexNames={indexNames} setQuery={setQuery} startDate={from} - showInspectButton={false} {...alertsByCategoryHistogramConfigs} /> ); diff --git a/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx b/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx index 4c0d90811517fb..fc62a3cb8060b7 100644 --- a/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx @@ -185,7 +185,6 @@ const EventsByDatasetComponent: React.FC = ({ setAbsoluteRangeDatePickerTarget={setAbsoluteRangeDatePickerTarget} setQuery={setQuery} showSpacer={showSpacer} - showInspectButton={false} showLegend={showLegend} skip={filterQuery === undefined} startDate={from} From 286706b3b124ec76a04b0ac0682da47f6213db63 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Thu, 10 Mar 2022 23:30:19 +0800 Subject: [PATCH 50/59] styling --- .../common/components/matrix_histogram/index.tsx | 6 +----- .../overview/components/alerts_by_category/index.tsx | 10 +++++++--- .../overview/components/events_by_dataset/index.tsx | 11 ++++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 9117bf936767ea..9c748c2c1c26f3 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -60,10 +60,6 @@ export type MatrixHistogramComponentProps = MatrixHistogramProps & const DEFAULT_PANEL_HEIGHT = 300; -const HeaderChildrenFlexItem = styled(EuiFlexItem)` - margin-left: 24px; -`; - const HistogramPanel = styled(Panel)<{ height?: number }>` display: flex; flex-direction: column; @@ -272,7 +268,7 @@ export const MatrixHistogramComponent: React.FC = /> )} - {headerChildren} + {headerChildren} diff --git a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx index acf85dcf55d181..da01092ed1409a 100644 --- a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.tsx @@ -8,8 +8,10 @@ import numeral from '@elastic/numeral'; import React, { useEffect, useMemo, useCallback } from 'react'; import { Position } from '@elastic/charts'; +import styled from 'styled-components'; import type { DataViewBase, Filter, Query } from '@kbn/es-query'; +import { EuiButton } from '@elastic/eui'; import { DEFAULT_NUMBER_FORMAT, APP_UI_ID } from '../../../../common/constants'; import { SHOWING, UNIT } from '../../../common/components/alerts_viewer/translations'; import { MatrixHistogram } from '../../../common/components/matrix_histogram'; @@ -28,13 +30,15 @@ import { getTabsOnHostsUrl } from '../../../common/components/link_to/redirect_t import { GlobalTimeArgs } from '../../../common/containers/use_global_time'; import { SecurityPageName } from '../../../app/types'; import { useFormatUrl } from '../../../common/components/link_to'; -import { LinkButton } from '../../../common/components/links'; import { useInvalidFilterQuery } from '../../../common/hooks/use_invalid_filter_query'; const ID = 'alertsByCategoryOverview'; const DEFAULT_STACK_BY = 'event.module'; +const StyledLinkButton = styled(EuiButton)` + margin-left: ${({ theme }) => theme.eui.paddingSizes.l}; +`; interface Props extends Pick { filters: Filter[]; hideHeaderChildren?: boolean; @@ -74,13 +78,13 @@ const AlertsByCategoryComponent: React.FC = ({ const alertsCountViewAlertsButton = useMemo( () => ( - {i18n.VIEW_ALERTS} - + ), [goToHostAlerts, formatUrl] ); diff --git a/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx b/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx index fc62a3cb8060b7..55903a8b47665d 100644 --- a/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/events_by_dataset/index.tsx @@ -12,6 +12,8 @@ import React, { useEffect, useMemo, useCallback } from 'react'; import uuid from 'uuid'; import type { DataViewBase, Filter, Query } from '@kbn/es-query'; +import styled from 'styled-components'; +import { EuiButton } from '@elastic/eui'; import { DEFAULT_NUMBER_FORMAT, APP_UI_ID } from '../../../../common/constants'; import { SHOWING, UNIT } from '../../../common/components/events_viewer/translations'; import { getTabsOnHostsUrl } from '../../../common/components/link_to/redirect_to_hosts'; @@ -32,7 +34,6 @@ import { GlobalTimeArgs } from '../../../common/containers/use_global_time'; import * as i18n from '../../pages/translations'; import { SecurityPageName } from '../../../app/types'; import { useFormatUrl } from '../../../common/components/link_to'; -import { LinkButton } from '../../../common/components/links'; import { useInvalidFilterQuery } from '../../../common/hooks/use_invalid_filter_query'; const DEFAULT_STACK_BY = 'event.dataset'; @@ -61,6 +62,10 @@ const getHistogramOption = (fieldName: string): MatrixHistogramOption => ({ value: fieldName, }); +const StyledLinkButton = styled(EuiButton)` + margin-left: ${({ theme }) => theme.eui.paddingSizes.l}; +`; + const EventsByDatasetComponent: React.FC = ({ combinedQueries, deleteQuery, @@ -110,12 +115,12 @@ const EventsByDatasetComponent: React.FC = ({ const eventsCountViewEventsButton = useMemo( () => ( - {i18n.VIEW_EVENTS} - + ), [goToHostEvents, formatUrl] ); From f6066bb0cc3eb0a5e04568a1649ad8def1ca93d9 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Mon, 14 Mar 2022 18:32:54 +0800 Subject: [PATCH 51/59] viz actions only available on hosts / network page --- .../matrix_histogram/index.test.tsx | 124 ++++++++++++++++-- .../components/matrix_histogram/index.tsx | 11 +- .../visualization_actions/index.tsx | 60 ++------- .../visualization_actions/translations.ts | 9 +- 4 files changed, 133 insertions(+), 71 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx index 68c5800c8b1ed8..e6edf34c7cf976 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx @@ -14,19 +14,13 @@ import { MatrixHistogramType } from '../../../../common/search_strategy/security import { TestProviders } from '../../mock'; import { mockRuntimeMappings } from '../../containers/source/mock'; import { dnsTopDomainsAttrs } from '../visualization_actions/configs/network/dns_top_domains'; - +import { useRouteSpy } from '../../utils/route/use_route_spy'; jest.mock('../../lib/kibana'); jest.mock('./matrix_loader', () => ({ MatrixLoader: () =>
, })); -jest.mock('../header_section', () => ({ - HeaderSection: ({ children }: { children: React.ReactElement }) => ( -
{children}
- ), -})); - jest.mock('../charts/barchart', () => ({ BarChart: () =>
, })); @@ -41,11 +35,25 @@ jest.mock('../visualization_actions', () => ({ )), })); +jest.mock('../inspect', () => ({ + InspectButton: jest.fn(() =>
), +})); + jest.mock('../../components/matrix_histogram/utils', () => ({ getBarchartConfigs: jest.fn(), getCustomChartData: jest.fn().mockReturnValue(true), })); +jest.mock('../../utils/route/use_route_spy', () => ({ + useRouteSpy: jest.fn().mockReturnValue([ + { + detailName: 'mockHost', + pageName: 'hosts', + tabName: 'externalAlerts', + }, + ]), +})); + describe('Matrix Histogram Component', () => { let wrapper: ReactWrapper; @@ -156,7 +164,53 @@ describe('Matrix Histogram Component', () => { }); describe('Inspect button', () => { - test("it doesn't render Inspect button by default", () => { + test("it doesn't render Inspect button by default on Host page", () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: 'mockHost', + pageName: 'hosts', + tabName: 'externalAlerts', + }, + ]); + + const testProps = { + ...mockMatrixOverTimeHistogramProps, + lensAttributes: dnsTopDomainsAttrs, + }; + wrapper = mount(, { + wrappingComponent: TestProviders, + }); + expect(wrapper.find('[data-test-subj="mock-inspect"]').exists()).toBe(false); + }); + + test("it doesn't render Inspect button by default on Network page", () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'network', + tabName: 'external-alerts', + }, + ]); + + const testProps = { + ...mockMatrixOverTimeHistogramProps, + lensAttributes: dnsTopDomainsAttrs, + }; + wrapper = mount(, { + wrappingComponent: TestProviders, + }); + expect(wrapper.find('[data-test-subj="mock-inspect"]').exists()).toBe(false); + }); + + test('it render Inspect button by default on other pages', () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'overview', + tabName: undefined, + }, + ]); + const testProps = { ...mockMatrixOverTimeHistogramProps, lensAttributes: dnsTopDomainsAttrs, @@ -164,12 +218,42 @@ describe('Matrix Histogram Component', () => { wrapper = mount(, { wrappingComponent: TestProviders, }); - expect(wrapper.find('[data-test-subj="inspect-icon-button"]').exists()).toBe(false); + expect(wrapper.find('[data-test-subj="mock-inspect"]').exists()).toBe(true); }); }); describe('VisualizationActions', () => { - test('it renders VisualizationActions if lensAttributes is provided', () => { + test('it renders VisualizationActions on Host page if lensAttributes is provided', () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: 'mockHost', + pageName: 'hosts', + tabName: 'externalAlerts', + }, + ]); + + const testProps = { + ...mockMatrixOverTimeHistogramProps, + lensAttributes: dnsTopDomainsAttrs, + }; + wrapper = mount(, { + wrappingComponent: TestProviders, + }); + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true); + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').prop('className')).toEqual( + 'histogram-viz-actions' + ); + }); + + test('it renders VisualizationActions on Network page if lensAttributes is provided', () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'network', + tabName: 'external-alerts', + }, + ]); + const testProps = { ...mockMatrixOverTimeHistogramProps, lensAttributes: dnsTopDomainsAttrs, @@ -182,5 +266,25 @@ describe('Matrix Histogram Component', () => { 'histogram-viz-actions' ); }); + + test("it doesn't renders VisualizationActions except Host / Network pages", () => { + const testProps = { + ...mockMatrixOverTimeHistogramProps, + lensAttributes: dnsTopDomainsAttrs, + }; + + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'overview', + tabName: undefined, + }, + ]); + + wrapper = mount(, { + wrappingComponent: TestProviders, + }); + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(false); + }); }); }); diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 9c748c2c1c26f3..1a9ae0515088f6 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -32,7 +32,8 @@ import { HoverVisibilityContainer } from '../hover_visibility_container'; import { HISTOGRAM_ACTIONS_BUTTON_CLASS, VisualizationActions } from '../visualization_actions'; import { GetLensAttributes, LensAttributes } from '../visualization_actions/types'; import { useKibana, useGetUserCasesPermissions } from '../../lib/kibana'; -import { APP_ID } from '../../../../common/constants'; +import { APP_ID, SecurityPageName } from '../../../../common/constants'; +import { useRouteSpy } from '../../utils/route/use_route_spy'; export type MatrixHistogramComponentProps = MatrixHistogramProps & Omit & { @@ -165,6 +166,10 @@ export const MatrixHistogramComponent: React.FC = const [loading, { data, inspect, totalCount, refetch }] = useMatrixHistogramCombined(matrixHistogramRequest); + const [{ pageName }] = useRouteSpy(); + + const onHostOrNetworkPage = + pageName === SecurityPageName.hosts || pageName === SecurityPageName.network; const titleWithStackByField = useMemo( () => (title != null && typeof title === 'function' ? title(selectedStackByOption) : title), @@ -238,11 +243,11 @@ export const MatrixHistogramComponent: React.FC = titleSize={titleSize} subtitle={subtitleWithCounts} inspectMultiple - showInspectButton={showInspectButton} + showInspectButton={showInspectButton || !onHostOrNetworkPage} isInspectDisabled={filterQuery === undefined} > - {(getLensAttributes || lensAttributes) && timerange && ( + {onHostOrNetworkPage && (getLensAttributes || lensAttributes) && timerange && ( = ({ const userPermissions = useGetUserCasesPermissions(); const userCanCrud = userPermissions?.crud ?? false; - const { - canUseEditor, - navigateToPrefilledEditor, - SaveModalComponent: LensSaveModalComponent, - } = lens; + const { canUseEditor, navigateToPrefilledEditor } = lens; const [isPopoverOpen, setPopover] = useState(false); - const [isSaveModalVisible, setIsSaveModalVisible] = useState(false); const [isInspectModalOpen, setIsInspectModalOpen] = useState(false); const onButtonClick = useCallback(() => { @@ -114,15 +108,6 @@ const VisualizationActionsComponent: React.FC = ({ ); }, [attributes, navigateToPrefilledEditor, timerange]); - const closeSaveModalVisible = useCallback(() => { - setIsSaveModalVisible(false); - }, []); - - const onSaveVisualization = useCallback(() => { - setIsSaveModalVisible(true); - closePopover(); - }, []); - const onOpenInspectModal = useCallback(() => { closePopover(); setIsInspectModalOpen(true); @@ -160,24 +145,6 @@ const VisualizationActionsComponent: React.FC = ({ const items = useMemo( () => [ - - {OPEN_IN_LENS} - , - - {SAVE_VISUALIZATION} - , = ({ > {INSPECT} , + + {OPEN_IN_LENS} + , = ({ onAddToExistingCaseClicked, onAddToNewCaseClicked, onOpenInLens, - onSaveVisualization, - userCanCrud, ] ); @@ -233,22 +207,8 @@ const VisualizationActionsComponent: React.FC = ({ [dataTestSubj, onButtonClick] ); - const initialInput = useMemo( - () => - attributes != null - ? { - id: 'saveVisualizationModal', - attributes, - } - : null, - [attributes] - ); - return ( - {isSaveModalVisible && initialInput != null && ( - - )} {request !== null && response !== null && ( Date: Mon, 14 Mar 2022 18:43:14 +0800 Subject: [PATCH 52/59] rm kpi --- .../public/common/components/stat_items/index.tsx | 8 ++++---- .../visualization_actions/configs/hosts/kpi_host_area.ts | 2 +- .../configs/hosts/kpi_host_metric.ts | 2 +- .../configs/hosts/kpi_unique_ips_area.ts | 2 +- .../configs/hosts/kpi_unique_ips_bar.ts | 2 +- .../configs/hosts/kpi_unique_ips_destination_metric.ts | 2 +- .../configs/hosts/kpi_unique_ips_source_metric.ts | 2 +- .../hosts/kpi_user_authentication_metric_failure.ts | 2 +- .../configs/hosts/kpi_user_authentications_area.ts | 2 +- .../configs/hosts/kpi_user_authentications_bar.ts | 2 +- .../hosts/kpi_user_authentications_metric_success.ts | 2 +- .../configs/network/kpi_dns_queries.ts | 2 +- .../configs/network/kpi_network_events.ts | 2 +- .../configs/network/kpi_tls_handshakes.ts | 2 +- .../configs/network/kpi_unique_flow_ids.ts | 2 +- .../configs/network/kpi_unique_private_ips_area.ts | 2 +- .../configs/network/kpi_unique_private_ips_bar.ts | 2 +- .../network/kpi_unique_private_ips_destination_metric.ts | 2 +- .../network/kpi_unique_private_ips_source_metric.ts | 2 +- .../components/kpi_hosts/risky_hosts/translations.ts | 2 +- 20 files changed, 23 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx index 979bb6f8d9e4bb..93a13dd5dee8b3 100644 --- a/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/stat_items/index.tsx @@ -249,7 +249,7 @@ export const StatItemsComponent = React.memo( {showInspectButton && ( - + )} @@ -283,7 +283,7 @@ export const StatItemsComponent = React.memo( queryId={id} inspectIndex={index} timerange={timerange} - title={`KPI ${description}`} + title={description} className="viz-actions" /> )} @@ -306,7 +306,7 @@ export const StatItemsComponent = React.memo( queryId: id, inspectIndex: index, timerange, - title: `KPI ${description}`, + title: description, }} /> @@ -326,7 +326,7 @@ export const StatItemsComponent = React.memo( queryId: id, inspectIndex: index, timerange, - title: `KPI ${description}`, + title: description, }} /> diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts index ce6327c7ecb718..4402f50cfe6594 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts @@ -67,7 +67,7 @@ export const kpiHostArea: LensAttributes = { yRightExtent: { mode: 'full' }, }, }, - title: '[Host] KPI Hosts - area', + title: '[Host] Hosts - area', visualizationType: 'lnsXY', references: [ { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts index 923ef2a92feaa4..ef49e63c2f207d 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts @@ -39,7 +39,7 @@ export const kpiHostMetric: LensAttributes = { layerType: 'data', }, }, - title: '[Host] KPI Hosts - metric', + title: '[Host] Hosts - metric', visualizationType: 'lnsMetric', references: [ { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts index 37e45e3a862019..7c169e24ac2e68 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts @@ -104,7 +104,7 @@ export const kpiUniqueIpsArea: LensAttributes = { yRightExtent: { mode: 'full' }, }, }, - title: '[Host] KPI Unique IPs - area', + title: '[Host] Unique IPs - area', visualizationType: 'lnsXY', references: [ { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts index 46992b4780504c..6908a7c53de95a 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts @@ -105,7 +105,7 @@ export const kpiUniqueIpsBar: LensAttributes = { yRightExtent: { mode: 'full' }, }, }, - title: '[Host] KPI Unique IPs - bar', + title: '[Host] Unique IPs - bar', visualizationType: 'lnsXY', references: [ { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts index 24f79b47a7d0cc..39be59c1bd319c 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts @@ -39,7 +39,7 @@ export const kpiUniqueIpsDestinationMetric: LensAttributes = { layerType: 'data', }, }, - title: '[Host] KPI Unique IPs - destination metric', + title: '[Host] Unique IPs - destination metric', visualizationType: 'lnsMetric', references: [ { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts index bc08d2f77a13f4..e67ba7614e8749 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts @@ -39,7 +39,7 @@ export const kpiUniqueIpsSourceMetric: LensAttributes = { layerType: 'data', }, }, - title: '[Host] KPI Unique IPs - source metric', + title: '[Host] Unique IPs - source metric', visualizationType: 'lnsMetric', references: [ { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts index 3f46295604fd8e..4d13264af6d3b1 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; export const kpiUserAuthenticationsMetricFailure: LensAttributes = { - title: '[Host] KPI User authentications - metric failure ', + title: '[Host] User authentications - metric failure ', description: '', visualizationType: 'lnsMetric', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts index e7105615f5ed5e..7a07f6258467e1 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; export const kpiUserAuthenticationsArea: LensAttributes = { - title: '[Host] KPI User authentications - area ', + title: '[Host] User authentications - area ', description: '', visualizationType: 'lnsXY', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts index 11314b1bb03044..328f4026a82a12 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts @@ -9,7 +9,7 @@ import { LensAttributes } from '../../types'; import { FAIL_CHART_LABEL, SUCCESS_CHART_LABEL } from '../../translations'; export const kpiUserAuthenticationsBar: LensAttributes = { - title: '[Host] KPI User authentications - bar ', + title: '[Host] User authentications - bar ', description: '', visualizationType: 'lnsXY', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts index af670207c54fad..e49b9d5dd85c28 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; export const kpiUserAuthenticationsMetricSuccess: LensAttributes = { - title: '[Host] KPI User authentications - metric success ', + title: '[Host] User authentications - metric success ', description: '', visualizationType: 'lnsMetric', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts index 44b9d919bc47dc..4f12cedb6ec39b 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; export const kpiDnsQueries: LensAttributes = { - title: '[Network] KPI DNS metric', + title: '[Network] DNS metric', description: '', visualizationType: 'lnsMetric', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts index 4904df154305a0..91890112661c20 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; export const kpiNetworkEvents: LensAttributes = { - title: '[Network] KPI Network events', + title: '[Network] Network events', description: '', visualizationType: 'lnsMetric', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts index 7789ec8ed52885..a9d298fb6966f5 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; export const kpiTlsHandshakes: LensAttributes = { - title: '[Network] KPI TLS handshakes', + title: '[Network] TLS handshakes', description: '', visualizationType: 'lnsMetric', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts index 13d2a86b02955d..af3598af7d3a59 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; export const kpiUniqueFlowIds: LensAttributes = { - title: '[Network] KPI Unique flow IDs', + title: '[Network] Unique flow IDs', description: '', visualizationType: 'lnsMetric', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts index 78a619eee14c2f..15b454acb38612 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; export const kpiUniquePrivateIpsArea: LensAttributes = { - title: '[Network] KPI Unique private IPs - area chart', + title: '[Network] Unique private IPs - area chart', description: '', visualizationType: 'lnsXY', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts index 7f5e82bd92fbb3..e161a700d302bc 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts @@ -9,7 +9,7 @@ import { SOURCE_CHART_LABEL, DESTINATION_CHART_LABEL } from '../../translations' import { LensAttributes } from '../../types'; export const kpiUniquePrivateIpsBar: LensAttributes = { - title: '[Network] KPI Unique private IPs - bar chart', + title: '[Network] Unique private IPs - bar chart', description: '', visualizationType: 'lnsXY', state: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts index 559ad218f77fa3..dfb7d20cf30324 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts @@ -48,7 +48,7 @@ export const kpiUniquePrivateIpsDestinationMetric: LensAttributes = { layerType: 'data', }, }, - title: '[Network] KPI Unique private IPs - destination metric', + title: '[Network] Unique private IPs - destination metric', visualizationType: 'lnsMetric', references: [ { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts index 43787808ee6488..e1bba75c8db638 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts @@ -47,7 +47,7 @@ export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { layerType: 'data', }, }, - title: '[Network] KPI Unique private IPs - source metric', + title: '[Network] Unique private IPs - source metric', visualizationType: 'lnsMetric', references: [ { diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/risky_hosts/translations.ts b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/risky_hosts/translations.ts index f97dc80fd9679d..ef289a0aa6aab2 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/risky_hosts/translations.ts +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/risky_hosts/translations.ts @@ -34,7 +34,7 @@ export const RISKY_HOSTS_TITLE = i18n.translate( export const INSPECT_RISKY_HOSTS = i18n.translate( 'xpack.securitySolution.kpiHosts.riskyHosts.inspectTitle', { - defaultMessage: 'KPI Risky Hosts', + defaultMessage: 'Risky Hosts', } ); From 3fdc08ed804ef2758b36cdce941bae6e14b8f02c Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Mon, 14 Mar 2022 22:13:23 +0800 Subject: [PATCH 53/59] unit tests --- .../components/matrix_histogram/index.tsx | 2 +- .../components/kpi_hosts/common/index.tsx | 2 +- .../hosts/pages/details/details_tabs.test.tsx | 23 ++- .../components/kpi_network/common/index.tsx | 2 +- .../alerts_by_category/index.test.tsx | 182 +++++++++++++++++- 5 files changed, 200 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx index 1a9ae0515088f6..dbf525f8e14cb1 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.tsx @@ -104,7 +104,7 @@ export const MatrixHistogramComponent: React.FC = }) => { const dispatch = useDispatch(); const { cases } = useKibana().services; - const CasesContext = cases.getCasesContext(); + const CasesContext = cases.ui.getCasesContext(); const userPermissions = useGetUserCasesPermissions(); const userCanCrud = userPermissions?.crud ?? false; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx index 3663fd890836c6..1f120617a36938 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/common/index.tsx @@ -43,7 +43,7 @@ interface HostsKpiBaseComponentProps { export const HostsKpiBaseComponent = React.memo( ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange }) => { const { cases } = useKibana().services; - const CasesContext = cases.getCasesContext(); + const CasesContext = cases.ui.getCasesContext(); const userPermissions = useGetUserCasesPermissions(); const userCanCrud = userPermissions?.crud ?? false; diff --git a/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx b/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx index 24910e5e313177..f0ac78e3950d48 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/details/details_tabs.test.tsx @@ -18,16 +18,25 @@ import { type } from './utils'; import { useMountAppended } from '../../../common/utils/use_mount_appended'; import { getHostDetailsPageFilters } from './helpers'; import { HostsTableType } from '../../store/model'; +import { mockCasesContract } from '../../../../../cases/public/mocks'; -jest.mock('../../../common/lib/kibana'); +jest.mock('../../../common/lib/kibana', () => { + const original = jest.requireActual('../../../common/lib/kibana'); -jest.mock('../../../common/components/url_state/normalize_time_range.ts'); + return { + ...original, + useKibana: () => ({ + ...original.useKibana(), + services: { + ...original.useKibana().services, + cases: mockCasesContract(), + timelines: { getTGrid: jest.fn().mockReturnValue(() => <>) }, + }, + }), + }; +}); -jest.mock('../../../common/lib/kibana/hooks', () => ({ - useNavigateTo: () => ({ - navigateTo: jest.fn(), - }), -})); +jest.mock('../../../common/components/url_state/normalize_time_range.ts'); jest.mock('../../../common/containers/source', () => ({ useFetchIndex: () => [false, { indicesExist: true, indexPatterns: mockIndexPattern }], diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx index 5d656a1c104f23..8fbc75aff4e19c 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/common/index.tsx @@ -41,7 +41,7 @@ export const NetworkKpiBaseComponent = React.memo<{ }>( ({ fieldsMapping, data, id, loading = false, from, to, narrowDateRange }) => { const { cases } = useKibana().services; - const CasesContext = cases.getCasesContext(); + const CasesContext = cases.ui.getCasesContext(); const userPermissions = useGetUserCasesPermissions(); const userCanCrud = userPermissions?.crud ?? false; diff --git a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx index 6a06cf3efb3021..075be8cde58958 100644 --- a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx @@ -16,6 +16,7 @@ import { mockIndexPattern, TestProviders } from '../../../common/mock'; import { AlertsByCategory } from '.'; import { mockCasesContext } from '../../../../../cases/public/mocks/mock_cases_context'; +import { useRouteSpy } from '../../../common/utils/route/use_route_spy'; jest.mock('../../../common/components/link_to'); jest.mock('../../../common/components/visualization_actions', () => ({ @@ -42,6 +43,16 @@ jest.mock('../../../common/lib/kibana', () => { }; }); +jest.mock('../../../common/utils/route/use_route_spy', () => ({ + useRouteSpy: jest.fn().mockReturnValue([ + { + detailName: 'mockHost', + pageName: 'hosts', + tabName: 'externalAlerts', + }, + ]), +})); + const from = '2020-03-31T06:00:00.000Z'; const to = '2019-03-31T06:00:00.000Z'; @@ -160,11 +171,180 @@ describe('Alerts by category', () => { }); }); + test('it shows visualization actions on host page', async () => { + await waitFor(() => { + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true); + }); + }); + + test('it shows visualization actions on network page', async () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'network', + tabName: 'external-alerts', + }, + ]); + + const testWrapper = mount( + + + + ); + + await waitFor(() => { + testWrapper.update(); + }); + await waitFor(() => { + expect(testWrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true); + }); + }); + + test('it does not shows visualization actions on other pages', async () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'overview', + tabName: undefined, + }, + ]); + const testWrapper = mount( + + + + ); + + await waitFor(() => { + testWrapper.update(); + }); + + await waitFor(() => { + expect(testWrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(false); + }); + }); + }); + + describe('Host page', () => { + beforeAll(async () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: 'mockHost', + pageName: 'hosts', + tabName: 'externalAlerts', + }, + ]); + + (useMatrixHistogramCombined as jest.Mock).mockReturnValue([ + false, + { + data: [ + { x: 1, y: 2, g: 'g1' }, + { x: 2, y: 4, g: 'g1' }, + { x: 3, y: 6, g: 'g1' }, + { x: 1, y: 1, g: 'g2' }, + { x: 2, y: 3, g: 'g2' }, + { x: 3, y: 5, g: 'g2' }, + ], + inspect: false, + totalCount: 6, + }, + ]); + + wrapper = mount( + + + + ); + + wrapper.update(); + }); + test('it shows visualization actions', async () => { await waitFor(() => { - expect(wrapper.find('[data-test-subj="inspect-icon-button"]').exists()).not.toBe(true); expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true); }); }); }); + + describe('Network page', () => { + beforeAll(async () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'network', + tabName: 'external-alerts', + }, + ]); + (useMatrixHistogramCombined as jest.Mock).mockReturnValue([ + false, + { + data: [ + { x: 1, y: 2, g: 'g1' }, + { x: 2, y: 4, g: 'g1' }, + { x: 3, y: 6, g: 'g1' }, + { x: 1, y: 1, g: 'g2' }, + { x: 2, y: 3, g: 'g2' }, + { x: 3, y: 5, g: 'g2' }, + ], + inspect: false, + totalCount: 6, + }, + ]); + + wrapper = mount( + + + + ); + + wrapper.update(); + }); + + test('it shows visualization actions', async () => { + await waitFor(() => { + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true); + }); + }); + }); + + describe('Othen than Host or Network page', () => { + beforeAll(async () => { + (useRouteSpy as jest.Mock).mockReturnValue([ + { + detailName: undefined, + pageName: 'overview', + tabName: undefined, + }, + ]); + (useMatrixHistogramCombined as jest.Mock).mockReturnValue([ + false, + { + data: [ + { x: 1, y: 2, g: 'g1' }, + { x: 2, y: 4, g: 'g1' }, + { x: 3, y: 6, g: 'g1' }, + { x: 1, y: 1, g: 'g2' }, + { x: 2, y: 3, g: 'g2' }, + { x: 3, y: 5, g: 'g2' }, + ], + inspect: false, + totalCount: 6, + }, + ]); + + wrapper = mount( + + + + ); + + wrapper.update(); + }); + + test('it does not shows visualization actions', async () => { + await waitFor(() => { + expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(false); + }); + }); + }); }); From cf1ae9d036ce61faa5d4143690a8e79ef7556e0b Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Mon, 14 Mar 2022 23:17:47 +0800 Subject: [PATCH 54/59] unit tests --- .../components/hover_actions/actions/show_top_n.test.tsx | 4 +++- .../overview/components/alerts_by_category/index.test.tsx | 4 +++- .../security_solution/public/users/pages/users_tabs.test.tsx | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx index 6c5f2f4535269b..ab5ad74c0bf150 100644 --- a/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/hover_actions/actions/show_top_n.test.tsx @@ -24,7 +24,9 @@ jest.mock('../../../lib/kibana', () => { services: { ...original.useKibana().services, cases: { - getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + ui: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, }, }, }), diff --git a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx index 075be8cde58958..3402a7bef49052 100644 --- a/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/alerts_by_category/index.test.tsx @@ -36,7 +36,9 @@ jest.mock('../../../common/lib/kibana', () => { services: { ...original.useKibana().services, cases: { - getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + ui: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, }, }, }), diff --git a/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx b/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx index 496c868d617b4f..41cb19e48e94d4 100644 --- a/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/users/pages/users_tabs.test.tsx @@ -35,7 +35,9 @@ jest.mock('../../common/lib/kibana', () => { services: { ...original.useKibana().services, cases: { - getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + ui: { + getCasesContext: jest.fn().mockReturnValue(mockCasesContext), + }, }, }, }), From dc46b4c3e85d21401bf67fbd51532d5d174d42d2 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 15 Mar 2022 00:25:22 +0800 Subject: [PATCH 55/59] unit tests --- .../visualization_actions/index.test.tsx | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx index 4fd4111c265696..cffdf70653e889 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx @@ -63,9 +63,6 @@ describe('VisualizationActions', () => { title: 'mock networkDnsHistogram', }; const mockNavigateToPrefilledEditor = jest.fn(); - const MockLensSaveModalComponent = jest.fn(() => ( -
{'mockLensSaveModal'}
- )); const mockGetCreateCaseFlyoutOpen = jest.fn(); const mockGetAllCasesSelectorModalOpen = jest.fn(); @@ -76,7 +73,6 @@ describe('VisualizationActions', () => { lens: { canUseEditor: jest.fn(() => true), navigateToPrefilledEditor: mockNavigateToPrefilledEditor, - SaveModalComponent: MockLensSaveModalComponent, }, cases: { ...mockCasesContract(), @@ -168,7 +164,7 @@ describe('VisualizationActions', () => { expect(mockNavigateToPrefilledEditor.mock.calls[0][1].openInNewTab).toEqual(true); }); - test('Should render Save button', () => { + test('Should render Inspect button', () => { const { container } = render( @@ -176,34 +172,11 @@ describe('VisualizationActions', () => { ); fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); - expect(screen.getByText('Save visualization')).toBeInTheDocument(); + expect(screen.getByText('Inspect')).toBeInTheDocument(); + expect(screen.getByText('Inspect')).not.toBeDisabled(); }); - test('Should open LensSaveModal', () => { - const { container } = render( - - - - ); - fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); - fireEvent.click(screen.getByText('Save visualization')); - - expect(screen.getByText('mockLensSaveModal')).toBeInTheDocument(); - }); - - test('Should render Inspect visualization button', () => { - const { container } = render( - - - - ); - fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); - - expect(screen.getByText('Inspect visualization')).toBeInTheDocument(); - expect(screen.getByText('Inspect visualization')).not.toBeDisabled(); - }); - - test('Should render Inspect visualization Modal after clicking the inspect button', () => { + test('Should render Inspect Modal after clicking the inspect button', () => { const { baseElement, container } = render( @@ -211,8 +184,8 @@ describe('VisualizationActions', () => { ); fireEvent.click(container.querySelector(`[data-test-subj="stat-networkDnsHistogramQuery"]`)!); - expect(screen.getByText('Inspect visualization')).toBeInTheDocument(); - fireEvent.click(screen.getByText('Inspect visualization')); + expect(screen.getByText('Inspect')).toBeInTheDocument(); + fireEvent.click(screen.getByText('Inspect')); expect( baseElement.querySelector('[data-test-subj="modal-inspect-euiModal"]') ).toBeInTheDocument(); From 96ed710f78494e491557b97ffecd200a833c0aaf Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 15 Mar 2022 17:46:43 +0800 Subject: [PATCH 56/59] unit tests --- .../components/header_section/index.test.tsx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/common/components/header_section/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/header_section/index.test.tsx index 47b6451dd3090c..5ec97ea59bc1de 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_section/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_section/index.test.tsx @@ -145,7 +145,31 @@ describe('HeaderSection', () => { expect(wrapper.find('[data-test-subj="inspect-icon-button"]').first().exists()).toBe(true); }); - test('it does NOT an inspect button when an `id` is NOT provided', () => { + test('it renders an inspect button when an `id` is provided and `showInspectButton` is true', () => { + const wrapper = mount( + + +

{'Test children'}

+
+
+ ); + + expect(wrapper.find('[data-test-subj="inspect-icon-button"]').first().exists()).toBe(true); + }); + + test('it does NOT render an inspect button when `showInspectButton` is false', () => { + const wrapper = mount( + + +

{'Test children'}

+
+
+ ); + + expect(wrapper.find('[data-test-subj="inspect-icon-button"]').first().exists()).toBe(false); + }); + + test('it does NOT render an inspect button when an `id` is NOT provided', () => { const wrapper = mount( From 1ed177e2e57ad636560a59a28cd0dd6a52d22d15 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 15 Mar 2022 17:48:37 +0800 Subject: [PATCH 57/59] kibana dependency --- x-pack/plugins/security_solution/kibana.json | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/security_solution/kibana.json b/x-pack/plugins/security_solution/kibana.json index 0143f28197bb32..ba289e48fd6a20 100644 --- a/x-pack/plugins/security_solution/kibana.json +++ b/x-pack/plugins/security_solution/kibana.json @@ -36,7 +36,6 @@ "security", "spaces", "usageCollection", - "lens", "lists", "home", "telemetry", From 08ffdf927441f8de83219dd937dae07b082d3db1 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 15 Mar 2022 18:59:29 +0800 Subject: [PATCH 58/59] rename --- .../alerts_viewer/histogram_configs.ts | 4 ++-- .../matrix_histogram/index.test.tsx | 14 +++++------ .../visualization_actions/index.test.tsx | 4 ++-- .../common/external_alert.ts | 4 +++- .../hosts/authentication.ts | 2 +- .../hosts/events.ts | 6 +++-- .../hosts/kpi_host_area.ts | 2 +- .../hosts/kpi_host_metric.ts | 2 +- .../hosts/kpi_unique_ips_area.ts | 2 +- .../hosts/kpi_unique_ips_bar.ts | 2 +- .../kpi_unique_ips_destination_metric.ts | 2 +- .../hosts/kpi_unique_ips_source_metric.ts | 2 +- .../kpi_user_authentication_metric_failure.ts | 2 +- .../hosts/kpi_user_authentications_area.ts | 2 +- .../hosts/kpi_user_authentications_bar.ts | 2 +- ...kpi_user_authentications_metric_success.ts | 2 +- .../network/dns_top_domains.ts | 2 +- .../network/kpi_dns_queries.ts | 2 +- .../network/kpi_network_events.ts | 2 +- .../network/kpi_tls_handshakes.ts | 2 +- .../network/kpi_unique_flow_ids.ts | 2 +- .../network/kpi_unique_private_ips_area.ts | 2 +- .../network/kpi_unique_private_ips_bar.ts | 2 +- ...i_unique_private_ips_destination_metric.ts | 2 +- .../kpi_unique_private_ips_source_metric.ts | 2 +- .../use_add_to_existing_case.test.tsx | 10 ++++---- .../use_add_to_new_case.test.tsx | 10 ++++---- .../use_lens_attributes.test.tsx | 10 ++++---- .../kpi_hosts/authentications/index.tsx | 16 ++++++------- .../components/kpi_hosts/hosts/index.tsx | 8 +++---- .../components/kpi_hosts/unique_ips/index.tsx | 16 ++++++------- .../authentications_query_tab_body.tsx | 4 ++-- .../navigation/events_query_tab_body.tsx | 4 ++-- .../components/kpi_network/dns/index.tsx | 4 ++-- .../network/components/kpi_network/mock.ts | 24 +++++++++---------- .../kpi_network/network_events/index.tsx | 4 ++-- .../kpi_network/tls_handshakes/index.tsx | 4 ++-- .../kpi_network/unique_flows/index.tsx | 4 ++-- .../kpi_network/unique_private_ips/index.tsx | 16 ++++++------- .../pages/navigation/dns_query_tab_body.tsx | 4 ++-- 40 files changed, 107 insertions(+), 103 deletions(-) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/common/external_alert.ts (97%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/authentication.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/events.ts (96%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_host_area.ts (97%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_host_metric.ts (96%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_unique_ips_area.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_unique_ips_bar.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_unique_ips_destination_metric.ts (95%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_unique_ips_source_metric.ts (95%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_user_authentication_metric_failure.ts (96%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_user_authentications_area.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_user_authentications_bar.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/hosts/kpi_user_authentications_metric_success.ts (96%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/dns_top_domains.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_dns_queries.ts (97%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_network_events.ts (97%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_tls_handshakes.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_unique_flow_ids.ts (97%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_unique_private_ips_area.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_unique_private_ips_bar.ts (98%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_unique_private_ips_destination_metric.ts (95%) rename x-pack/plugins/security_solution/public/common/components/visualization_actions/{configs => lens_attributes}/network/kpi_unique_private_ips_source_metric.ts (96%) diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts index f350cf6b33049f..f8500651145cb8 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts +++ b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/histogram_configs.ts @@ -8,7 +8,7 @@ import * as i18n from './translations'; import { MatrixHistogramOption, MatrixHistogramConfigs } from '../matrix_histogram/types'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution/matrix_histogram'; -import { getExternalAlertConfigs } from '../visualization_actions/configs/common/external_alert'; +import { getExternalAlertLensAttributes } from '../visualization_actions/lens_attributes/common/external_alert'; export const alertsStackByOptions: MatrixHistogramOption[] = [ { @@ -31,5 +31,5 @@ export const histogramConfigs: MatrixHistogramConfigs = { stackByOptions: alertsStackByOptions, subtitle: undefined, title: i18n.ALERTS_GRAPH_TITLE, - getLensAttributes: getExternalAlertConfigs, + getLensAttributes: getExternalAlertLensAttributes, }; diff --git a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx index e6edf34c7cf976..aee49bd1b00ae9 100644 --- a/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/matrix_histogram/index.test.tsx @@ -13,7 +13,7 @@ import { useMatrixHistogramCombined } from '../../containers/matrix_histogram'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; import { TestProviders } from '../../mock'; import { mockRuntimeMappings } from '../../containers/source/mock'; -import { dnsTopDomainsAttrs } from '../visualization_actions/configs/network/dns_top_domains'; +import { dnsTopDomainsLensAttributes } from '../visualization_actions/lens_attributes/network/dns_top_domains'; import { useRouteSpy } from '../../utils/route/use_route_spy'; jest.mock('../../lib/kibana'); @@ -175,7 +175,7 @@ describe('Matrix Histogram Component', () => { const testProps = { ...mockMatrixOverTimeHistogramProps, - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, }; wrapper = mount(, { wrappingComponent: TestProviders, @@ -194,7 +194,7 @@ describe('Matrix Histogram Component', () => { const testProps = { ...mockMatrixOverTimeHistogramProps, - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, }; wrapper = mount(, { wrappingComponent: TestProviders, @@ -213,7 +213,7 @@ describe('Matrix Histogram Component', () => { const testProps = { ...mockMatrixOverTimeHistogramProps, - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, }; wrapper = mount(, { wrappingComponent: TestProviders, @@ -234,7 +234,7 @@ describe('Matrix Histogram Component', () => { const testProps = { ...mockMatrixOverTimeHistogramProps, - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, }; wrapper = mount(, { wrappingComponent: TestProviders, @@ -256,7 +256,7 @@ describe('Matrix Histogram Component', () => { const testProps = { ...mockMatrixOverTimeHistogramProps, - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, }; wrapper = mount(, { wrappingComponent: TestProviders, @@ -270,7 +270,7 @@ describe('Matrix Histogram Component', () => { test("it doesn't renders VisualizationActions except Host / Network pages", () => { const testProps = { ...mockMatrixOverTimeHistogramProps, - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, }; (useRouteSpy as jest.Mock).mockReturnValue([ diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx index cffdf70653e889..00ae0873472e9f 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/index.test.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; import { fireEvent, render, screen } from '@testing-library/react'; -import { dnsTopDomainsAttrs } from './configs/network/dns_top_domains'; +import { dnsTopDomainsLensAttributes } from './lens_attributes/network/dns_top_domains'; import { VisualizationActions } from '.'; import { createSecuritySolutionStorageMock, @@ -54,7 +54,7 @@ describe('VisualizationActions', () => { let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); const props = { - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, queryId: 'networkDnsHistogramQuery', timerange: { from: '2022-03-06T16:00:00.000Z', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/external_alert.ts similarity index 97% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/external_alert.ts index bd635bb4ad0e8e..551ce37be924e1 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/common/external_alert.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/external_alert.ts @@ -7,7 +7,9 @@ import { GetLensAttributes, LensAttributes } from '../../types'; -export const getExternalAlertConfigs: GetLensAttributes = (stackByField = 'event.module') => { +export const getExternalAlertLensAttributes: GetLensAttributes = ( + stackByField = 'event.module' +) => { return { title: 'External alerts', description: '', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/authentication.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/authentication.ts index 77059599d68b6a..3610dcb4c94ae5 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/authentication.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/authentication.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const authentication: LensAttributes = { +export const authenticationLensAttributes: LensAttributes = { title: 'Authentication', description: '', visualizationType: 'lnsXY', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/events.ts similarity index 96% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/events.ts index 0982b5017552a1..0e5284f84bf1f8 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/events.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/events.ts @@ -7,7 +7,9 @@ import { GetLensAttributes, LensAttributes } from '../../types'; -export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'event.action') => +export const getEventsHistogramLensAttributes: GetLensAttributes = ( + stackByField = 'event.action' +) => ({ title: 'Host - events', description: '', @@ -87,7 +89,7 @@ export const getEventsHistogramCongifs: GetLensAttributes = (stackByField = 'eve type: 'column', columnId: 'e09e0380-0740-4105-becc-0a4ca12e3944', }, - orderDirection: 'desc', + orderDirection: 'asc', otherBucket: true, missingBucket: false, parentFormat: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_host_area.ts similarity index 97% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_host_area.ts index 4402f50cfe6594..369bbf3da2ab10 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_host_area.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiHostArea: LensAttributes = { +export const kpiHostAreaLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_host_metric.ts similarity index 96% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_host_metric.ts index ef49e63c2f207d..9ce303b70df0a8 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_host_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_host_metric.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiHostMetric: LensAttributes = { +export const kpiHostMetricLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_area.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_area.ts index 7c169e24ac2e68..577a20cfdc2459 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_area.ts @@ -8,7 +8,7 @@ import { DESTINATION_CHART_LABEL, SOURCE_CHART_LABEL } from '../../translations'; import { LensAttributes } from '../../types'; -export const kpiUniqueIpsArea: LensAttributes = { +export const kpiUniqueIpsAreaLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_bar.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_bar.ts index 6908a7c53de95a..b55f71abb75443 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_bar.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; import { SOURCE_CHART_LABEL, DESTINATION_CHART_LABEL } from '../../translations'; -export const kpiUniqueIpsBar: LensAttributes = { +export const kpiUniqueIpsBarLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_destination_metric.ts similarity index 95% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_destination_metric.ts index 39be59c1bd319c..c70efd904cfb30 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_destination_metric.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiUniqueIpsDestinationMetric: LensAttributes = { +export const kpiUniqueIpsDestinationMetricLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_source_metric.ts similarity index 95% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_source_metric.ts index e67ba7614e8749..a1325e0d94e0c0 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_source_metric.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiUniqueIpsSourceMetric: LensAttributes = { +export const kpiUniqueIpsSourceMetricLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentication_metric_failure.ts similarity index 96% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentication_metric_failure.ts index 4d13264af6d3b1..459ad6693ae41a 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentication_metric_failure.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiUserAuthenticationsMetricFailure: LensAttributes = { +export const kpiUserAuthenticationsMetricFailureLensAttributes: LensAttributes = { title: '[Host] User authentications - metric failure ', description: '', visualizationType: 'lnsMetric', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_area.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_area.ts index 7a07f6258467e1..ec0770795f5a80 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_area.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiUserAuthenticationsArea: LensAttributes = { +export const kpiUserAuthenticationsAreaLensAttributes: LensAttributes = { title: '[Host] User authentications - area ', description: '', visualizationType: 'lnsXY', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_bar.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_bar.ts index 328f4026a82a12..02468984144bcd 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_bar.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; import { FAIL_CHART_LABEL, SUCCESS_CHART_LABEL } from '../../translations'; -export const kpiUserAuthenticationsBar: LensAttributes = { +export const kpiUserAuthenticationsBarLensAttributes: LensAttributes = { title: '[Host] User authentications - bar ', description: '', visualizationType: 'lnsXY', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_metric_success.ts similarity index 96% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_metric_success.ts index e49b9d5dd85c28..ae0ac6e3e2e4d6 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_metric_success.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiUserAuthenticationsMetricSuccess: LensAttributes = { +export const kpiUserAuthenticationsMetricSuccessLensAttributes: LensAttributes = { title: '[Host] User authentications - metric success ', description: '', visualizationType: 'lnsMetric', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/dns_top_domains.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/dns_top_domains.ts index 13f3a47163ca72..579d6f0b3ab7e0 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/dns_top_domains.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/dns_top_domains.ts @@ -8,7 +8,7 @@ import { LensAttributes } from '../../types'; /* Exported from Kibana Saved Object */ -export const dnsTopDomainsAttrs: LensAttributes = { +export const dnsTopDomainsLensAttributes: LensAttributes = { title: 'Top domains by dns.question.registered_domain', description: 'Security Solution Network DNS', visualizationType: 'lnsXY', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_dns_queries.ts similarity index 97% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_dns_queries.ts index 4f12cedb6ec39b..3b672c03d97f23 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_dns_queries.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_dns_queries.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiDnsQueries: LensAttributes = { +export const kpiDnsQueriesLensAttributes: LensAttributes = { title: '[Network] DNS metric', description: '', visualizationType: 'lnsMetric', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_network_events.ts similarity index 97% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_network_events.ts index 91890112661c20..a51b8ee0ac66de 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_network_events.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_network_events.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiNetworkEvents: LensAttributes = { +export const kpiNetworkEventsLensAttributes: LensAttributes = { title: '[Network] Network events', description: '', visualizationType: 'lnsMetric', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_tls_handshakes.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_tls_handshakes.ts index a9d298fb6966f5..2e250f6fe3e5b8 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_tls_handshakes.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_tls_handshakes.ts @@ -6,7 +6,7 @@ */ import { LensAttributes } from '../../types'; -export const kpiTlsHandshakes: LensAttributes = { +export const kpiTlsHandshakesLensAttributes: LensAttributes = { title: '[Network] TLS handshakes', description: '', visualizationType: 'lnsMetric', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_flow_ids.ts similarity index 97% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_flow_ids.ts index af3598af7d3a59..cb75ddef54baef 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_flow_ids.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_flow_ids.ts @@ -7,7 +7,7 @@ import { LensAttributes } from '../../types'; -export const kpiUniqueFlowIds: LensAttributes = { +export const kpiUniqueFlowIdsLensAttributes: LensAttributes = { title: '[Network] Unique flow IDs', description: '', visualizationType: 'lnsMetric', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_area.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_area.ts index 15b454acb38612..89104df5d72be6 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_area.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_area.ts @@ -6,7 +6,7 @@ */ import { LensAttributes } from '../../types'; -export const kpiUniquePrivateIpsArea: LensAttributes = { +export const kpiUniquePrivateIpsAreaLensAttributes: LensAttributes = { title: '[Network] Unique private IPs - area chart', description: '', visualizationType: 'lnsXY', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_bar.ts similarity index 98% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_bar.ts index e161a700d302bc..4bbc1e1510dbe9 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_bar.ts @@ -8,7 +8,7 @@ import { SOURCE_CHART_LABEL, DESTINATION_CHART_LABEL } from '../../translations'; import { LensAttributes } from '../../types'; -export const kpiUniquePrivateIpsBar: LensAttributes = { +export const kpiUniquePrivateIpsBarLensAttributes: LensAttributes = { title: '[Network] Unique private IPs - bar chart', description: '', visualizationType: 'lnsXY', diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_destination_metric.ts similarity index 95% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_destination_metric.ts index dfb7d20cf30324..b5664d8cb8348d 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_destination_metric.ts @@ -8,7 +8,7 @@ import { DESTINATION_CHART_LABEL } from '../../translations'; import { LensAttributes } from '../../types'; -export const kpiUniquePrivateIpsDestinationMetric: LensAttributes = { +export const kpiUniquePrivateIpsDestinationMetricLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_source_metric.ts similarity index 96% rename from x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts rename to x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_source_metric.ts index e1bba75c8db638..4ddeacbe7fa4c6 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric.ts +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_source_metric.ts @@ -7,7 +7,7 @@ import { SOURCE_CHART_LABEL } from '../../translations'; import { LensAttributes } from '../../types'; -export const kpiUniquePrivateIpsSourceMetric: LensAttributes = { +export const kpiUniquePrivateIpsSourceMetricLensAttributes: LensAttributes = { description: '', state: { datasourceStates: { diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx index e2070cad9bd38d..a1831a7fccde78 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx @@ -7,7 +7,7 @@ import { renderHook } from '@testing-library/react-hooks'; import { mockCasesContract } from '../../../../../cases/public/mocks'; import { useKibana } from '../../lib/kibana'; -import { kpiHostMetric } from './configs/hosts/kpi_host_metric'; +import { kpiHostMetricLensAttributes } from './lens_attributes/hosts/kpi_host_metric'; import { useAddToExistingCase } from './use_add_to_existing_case'; jest.mock('../../lib/kibana/kibana_react'); @@ -32,7 +32,7 @@ describe('', () => { it('getUseCasesAddToExistingCaseModal with attachments', () => { const { result } = renderHook(() => useAddToExistingCase({ - lensAttributes: kpiHostMetric, + lensAttributes: kpiHostMetricLensAttributes, timeRange, userCanCrud: true, onAddToCaseClicked: mockOnAddToCaseClicked, @@ -43,7 +43,7 @@ describe('', () => { { comment: `!{lens${JSON.stringify({ timeRange, - attributes: kpiHostMetric, + attributes: kpiHostMetricLensAttributes, })}}`, owner, type, @@ -57,7 +57,7 @@ describe('', () => { it("button disalbled if user Can't Crud", () => { const { result } = renderHook(() => useAddToExistingCase({ - lensAttributes: kpiHostMetric, + lensAttributes: kpiHostMetricLensAttributes, timeRange, userCanCrud: false, onAddToCaseClicked: mockOnAddToCaseClicked, @@ -81,7 +81,7 @@ describe('', () => { it('button disalbled if no timeRange', () => { const { result } = renderHook(() => useAddToExistingCase({ - lensAttributes: kpiHostMetric, + lensAttributes: kpiHostMetricLensAttributes, timeRange: null, userCanCrud: true, onAddToCaseClicked: mockOnAddToCaseClicked, diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx index e48d9aedca4011..0627262eec438d 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx @@ -7,7 +7,7 @@ import { renderHook } from '@testing-library/react-hooks'; import { mockCasesContract } from '../../../../../cases/public/mocks'; import { useKibana } from '../../lib/kibana'; -import { kpiHostMetric } from './configs/hosts/kpi_host_metric'; +import { kpiHostMetricLensAttributes } from './lens_attributes/hosts/kpi_host_metric'; import { useAddToNewCase } from './use_add_to_new_case'; jest.mock('../../lib/kibana/kibana_react'); @@ -31,7 +31,7 @@ describe('', () => { it('getUseCasesAddToNewCaseFlyout with attachments', () => { const { result } = renderHook(() => useAddToNewCase({ - lensAttributes: kpiHostMetric, + lensAttributes: kpiHostMetricLensAttributes, timeRange, userCanCrud: true, }) @@ -41,7 +41,7 @@ describe('', () => { { comment: `!{lens${JSON.stringify({ timeRange, - attributes: kpiHostMetric, + attributes: kpiHostMetricLensAttributes, })}}`, owner, type, @@ -54,7 +54,7 @@ describe('', () => { it("button disalbled if user Can't Crud", () => { const { result } = renderHook(() => useAddToNewCase({ - lensAttributes: kpiHostMetric, + lensAttributes: kpiHostMetricLensAttributes, timeRange, userCanCrud: false, }) @@ -76,7 +76,7 @@ describe('', () => { it('button disalbled if no timeRange', () => { const { result } = renderHook(() => useAddToNewCase({ - lensAttributes: kpiHostMetric, + lensAttributes: kpiHostMetricLensAttributes, timeRange: null, userCanCrud: true, }) diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx index c377f06d70d039..72257a76d43c83 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_lens_attributes.test.tsx @@ -16,7 +16,7 @@ import { kibanaObservable, createSecuritySolutionStorageMock, } from '../../mock'; -import { getExternalAlertConfigs } from './configs/common/external_alert'; +import { getExternalAlertLensAttributes } from './lens_attributes/common/external_alert'; import { useLensAttributes } from './use_lens_attributes'; import { filterHostExternalAlertData, getHostDetailsPageFilter, getIndexFilters } from './utils'; import { createStore, State } from '../../store'; @@ -87,7 +87,7 @@ describe('useLensAttributes', () => { const { result } = renderHook( () => useLensAttributes({ - getLensAttributes: getExternalAlertConfigs, + getLensAttributes: getExternalAlertLensAttributes, stackByField: 'event.dataset', }), { wrapper } @@ -103,14 +103,14 @@ describe('useLensAttributes', () => { const { result } = renderHook( () => useLensAttributes({ - getLensAttributes: getExternalAlertConfigs, + getLensAttributes: getExternalAlertLensAttributes, stackByField: 'event.dataset', }), { wrapper } ); expect(result?.current?.state.filters).toEqual([ - ...getExternalAlertConfigs().state.filters, + ...getExternalAlertLensAttributes().state.filters, ...filterFromSearchBar, ...getHostDetailsPageFilter('mockHost'), ...filterHostExternalAlertData, @@ -125,7 +125,7 @@ describe('useLensAttributes', () => { const { result } = renderHook( () => useLensAttributes({ - getLensAttributes: getExternalAlertConfigs, + getLensAttributes: getExternalAlertLensAttributes, stackByField: 'event.dataset', }), { wrapper } diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx index cc9a3668781117..ce73b1cd07f61b 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/authentications/index.tsx @@ -8,10 +8,10 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUserAuthenticationsArea } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentications_area'; -import { kpiUserAuthenticationsBar } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentications_bar'; -import { kpiUserAuthenticationsMetricSuccess } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentications_metric_success'; -import { kpiUserAuthenticationsMetricFailure } from '../../../../common/components/visualization_actions/configs/hosts/kpi_user_authentication_metric_failure'; +import { kpiUserAuthenticationsAreaLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_area'; +import { kpiUserAuthenticationsBarLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_bar'; +import { kpiUserAuthenticationsMetricSuccessLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentications_metric_success'; +import { kpiUserAuthenticationsMetricFailureLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_user_authentication_metric_failure'; import { useHostsKpiAuthentications } from '../../../containers/kpi_hosts/authentications'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; @@ -28,7 +28,7 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.authenticationsSuccess, icon: 'check', - lensAttributes: kpiUserAuthenticationsMetricSuccess, + lensAttributes: kpiUserAuthenticationsMetricSuccessLensAttributes, }, { key: 'authenticationsFailure', @@ -37,14 +37,14 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.authenticationsFailure, icon: 'cross', - lensAttributes: kpiUserAuthenticationsMetricFailure, + lensAttributes: kpiUserAuthenticationsMetricFailureLensAttributes, }, ], enableAreaChart: true, enableBarChart: true, description: i18n.USER_AUTHENTICATIONS, - areaChartLensAttributes: kpiUserAuthenticationsArea, - barChartLensAttributes: kpiUserAuthenticationsBar, + areaChartLensAttributes: kpiUserAuthenticationsAreaLensAttributes, + barChartLensAttributes: kpiUserAuthenticationsBarLensAttributes, }, ]; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx index f947c1121773a5..4e73a429fbc1df 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/hosts/index.tsx @@ -8,8 +8,8 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiHostArea } from '../../../../common/components/visualization_actions/configs/hosts/kpi_host_area'; -import { kpiHostMetric } from '../../../../common/components/visualization_actions/configs/hosts/kpi_host_metric'; +import { kpiHostAreaLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_host_area'; +import { kpiHostMetricLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_host_metric'; import { useHostsKpiHosts } from '../../../containers/kpi_hosts/hosts'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; @@ -24,12 +24,12 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.hosts, icon: 'storage', - lensAttributes: kpiHostMetric, + lensAttributes: kpiHostMetricLensAttributes, }, ], enableAreaChart: true, description: i18n.HOSTS, - areaChartLensAttributes: kpiHostArea, + areaChartLensAttributes: kpiHostAreaLensAttributes, }, ]; diff --git a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx index 1b1e14d495b2a0..2d95e3c98f4aeb 100644 --- a/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/components/kpi_hosts/unique_ips/index.tsx @@ -8,10 +8,10 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUniqueIpsArea } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_area'; -import { kpiUniqueIpsBar } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_bar'; -import { kpiUniqueIpsDestinationMetric } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_destination_metric'; -import { kpiUniqueIpsSourceMetric } from '../../../../common/components/visualization_actions/configs/hosts/kpi_unique_ips_source_metric'; +import { kpiUniqueIpsAreaLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_area'; +import { kpiUniqueIpsBarLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_bar'; +import { kpiUniqueIpsDestinationMetricLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_destination_metric'; +import { kpiUniqueIpsSourceMetricLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/hosts/kpi_unique_ips_source_metric'; import { useHostsKpiUniqueIps } from '../../../containers/kpi_hosts/unique_ips'; import { HostsKpiBaseComponentManage } from '../common'; import { HostsKpiProps, HostsKpiChartColors } from '../types'; @@ -28,7 +28,7 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.uniqueSourceIps, icon: 'visMapCoordinate', - lensAttributes: kpiUniqueIpsSourceMetric, + lensAttributes: kpiUniqueIpsSourceMetricLensAttributes, }, { key: 'uniqueDestinationIps', @@ -37,14 +37,14 @@ export const fieldsMapping: Readonly = [ value: null, color: HostsKpiChartColors.uniqueDestinationIps, icon: 'visMapCoordinate', - lensAttributes: kpiUniqueIpsDestinationMetric, + lensAttributes: kpiUniqueIpsDestinationMetricLensAttributes, }, ], enableAreaChart: true, enableBarChart: true, description: i18n.UNIQUE_IPS, - areaChartLensAttributes: kpiUniqueIpsArea, - barChartLensAttributes: kpiUniqueIpsBar, + areaChartLensAttributes: kpiUniqueIpsAreaLensAttributes, + barChartLensAttributes: kpiUniqueIpsBarLensAttributes, }, ]; diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx index 147863fa3da59c..879f0fce02fd5d 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/authentications_query_tab_body.tsx @@ -20,7 +20,7 @@ import { MatrixHistogram } from '../../../common/components/matrix_histogram'; import { HostsKpiChartColors } from '../../components/kpi_hosts/types'; import * as i18n from '../translations'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; -import { authentication } from '../../../common/components/visualization_actions/configs/hosts/authentication'; +import { authenticationLensAttributes } from '../../../common/components/visualization_actions/lens_attributes/hosts/authentication'; import { LensAttributes } from '../../../common/components/visualization_actions/types'; const AuthenticationTableManage = manageQuery(AuthenticationTable); @@ -62,7 +62,7 @@ const histogramConfigs: MatrixHistogramConfigs = { mapping: authenticationsMatrixDataMappingFields, stackByOptions: authenticationsStackByOptions, title: i18n.NAVIGATION_AUTHENTICATIONS_TITLE, - lensAttributes: authentication as LensAttributes, + lensAttributes: authenticationLensAttributes as LensAttributes, }; const AuthenticationsQueryTabBodyComponent: React.FC = ({ diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx index 803019bdb47bfb..59c3322fb02ed7 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx @@ -28,7 +28,7 @@ import { SourcererScopeName } from '../../../common/store/sourcerer/model'; import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features'; import { DEFAULT_COLUMN_MIN_WIDTH } from '../../../timelines/components/timeline/body/constants'; import { defaultCellActions } from '../../../common/lib/cell_actions/default_cell_actions'; -import { getEventsHistogramCongifs } from '../../../common/components/visualization_actions/configs/hosts/events'; +import { getEventsHistogramLensAttributes } from '../../../common/components/visualization_actions/lens_attributes/hosts/events'; const EVENTS_HISTOGRAM_ID = 'eventsHistogramQuery'; @@ -58,7 +58,7 @@ export const histogramConfigs: MatrixHistogramConfigs = { stackByOptions: eventsStackByOptions, subtitle: undefined, title: i18n.NAVIGATION_EVENTS_TITLE, - getLensAttributes: getEventsHistogramCongifs, + getLensAttributes: getEventsHistogramLensAttributes, }; const EventsQueryTabBodyComponent: React.FC = ({ diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx index 8a774724fccac2..2c9db1cde6daf0 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/dns/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiDnsQueries } from '../../../../common/components/visualization_actions/configs/network/kpi_dns_queries'; +import { kpiDnsQueriesLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_dns_queries'; import { useNetworkKpiDns } from '../../../containers/kpi_network/dns'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; @@ -21,7 +21,7 @@ export const fieldsMapping: Readonly = [ { key: 'dnsQueries', value: null, - lensAttributes: kpiDnsQueries, + lensAttributes: kpiDnsQueriesLensAttributes, }, ], description: i18n.DNS_QUERIES, diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts b/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts index faed630b4d29c1..6f35c4dead2507 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/mock.ts @@ -7,10 +7,10 @@ import { NetworkKpiStrategyResponse } from '../../../../common/search_strategy'; import { StatItems } from '../../../common/components/stat_items'; -import { kpiUniquePrivateIpsArea } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_area'; -import { kpiUniquePrivateIpsBar } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar'; -import { kpiUniquePrivateIpsDestinationMetric } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric'; -import { kpiUniquePrivateIpsSourceMetric } from '../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric'; +import { kpiUniquePrivateIpsAreaLensAttributes } from '../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_area'; +import { kpiUniquePrivateIpsBarLensAttributes } from '../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_bar'; +import { kpiUniquePrivateIpsDestinationMetricLensAttributes } from '../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_destination_metric'; +import { kpiUniquePrivateIpsSourceMetricLensAttributes } from '../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_source_metric'; export const mockNarrowDateRange = jest.fn(); @@ -111,7 +111,7 @@ export const mockEnableChartsInitialData = { description: 'source', color: '#D36086', icon: 'visMapCoordinate', - lensAttributes: kpiUniquePrivateIpsSourceMetric, + lensAttributes: kpiUniquePrivateIpsSourceMetricLensAttributes, }, { key: 'uniqueDestinationPrivateIps', @@ -120,14 +120,14 @@ export const mockEnableChartsInitialData = { description: 'destination', color: '#9170B8', icon: 'visMapCoordinate', - lensAttributes: kpiUniquePrivateIpsDestinationMetric, + lensAttributes: kpiUniquePrivateIpsDestinationMetricLensAttributes, }, ], description: 'Unique private IPs', enableAreaChart: true, enableBarChart: true, - areaChartLensAttributes: kpiUniquePrivateIpsArea, - barChartLensAttributes: kpiUniquePrivateIpsBar, + areaChartLensAttributes: kpiUniquePrivateIpsAreaLensAttributes, + barChartLensAttributes: kpiUniquePrivateIpsBarLensAttributes, areaChart: [], barChart: [ { @@ -213,7 +213,7 @@ export const mockEnableChartsData = { description: 'source', color: '#D36086', icon: 'visMapCoordinate', - lensAttributes: kpiUniquePrivateIpsSourceMetric, + lensAttributes: kpiUniquePrivateIpsSourceMetricLensAttributes, }, { key: 'uniqueDestinationPrivateIps', @@ -222,7 +222,7 @@ export const mockEnableChartsData = { description: 'destination', color: '#9170B8', icon: 'visMapCoordinate', - lensAttributes: kpiUniquePrivateIpsDestinationMetric, + lensAttributes: kpiUniquePrivateIpsDestinationMetricLensAttributes, }, ], from: '2019-06-15T06:00:00.000Z', @@ -230,6 +230,6 @@ export const mockEnableChartsData = { statKey: 'UniqueIps', to: '2019-06-18T06:00:00.000Z', narrowDateRange: mockNarrowDateRange, - areaChartLensAttributes: kpiUniquePrivateIpsArea, - barChartLensAttributes: kpiUniquePrivateIpsBar, + areaChartLensAttributes: kpiUniquePrivateIpsAreaLensAttributes, + barChartLensAttributes: kpiUniquePrivateIpsBarLensAttributes, }; diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx index e97eb8420e6c2c..b3630026109263 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/network_events/index.tsx @@ -13,7 +13,7 @@ import { useNetworkKpiNetworkEvents } from '../../../containers/kpi_network/netw import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; import * as i18n from './translations'; -import { kpiNetworkEvents } from '../../../../common/components/visualization_actions/configs/network/kpi_network_events'; +import { kpiNetworkEventsLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_network_events'; const euiVisColorPalette = euiPaletteColorBlind(); const euiColorVis1 = euiVisColorPalette[1]; @@ -26,7 +26,7 @@ export const fieldsMapping: Readonly = [ key: 'networkEvents', value: null, color: euiColorVis1, - lensAttributes: kpiNetworkEvents, + lensAttributes: kpiNetworkEventsLensAttributes, }, ], description: i18n.NETWORK_EVENTS, diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx index e0d7420f5df18d..f05fdb44eba0c7 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/tls_handshakes/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiTlsHandshakes } from '../../../../common/components/visualization_actions/configs/network/kpi_tls_handshakes'; +import { kpiTlsHandshakesLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_tls_handshakes'; import { useNetworkKpiTlsHandshakes } from '../../../containers/kpi_network/tls_handshakes'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; @@ -21,7 +21,7 @@ export const fieldsMapping: Readonly = [ { key: 'tlsHandshakes', value: null, - lensAttributes: kpiTlsHandshakes, + lensAttributes: kpiTlsHandshakesLensAttributes, }, ], description: i18n.TLS_HANDSHAKES, diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx index 0bd83ebcb9b40d..6f5adc5cd40ca7 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_flows/index.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { StatItems } from '../../../../common/components/stat_items'; -import { kpiUniqueFlowIds } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_flow_ids'; +import { kpiUniqueFlowIdsLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_flow_ids'; import { useNetworkKpiUniqueFlows } from '../../../containers/kpi_network/unique_flows'; import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; @@ -21,7 +21,7 @@ export const fieldsMapping: Readonly = [ { key: 'uniqueFlowId', value: null, - lensAttributes: kpiUniqueFlowIds, + lensAttributes: kpiUniqueFlowIdsLensAttributes, }, ], description: i18n.UNIQUE_FLOW_IDS, diff --git a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx index 1ea058a1745464..c3671abe6d2ee6 100644 --- a/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx +++ b/x-pack/plugins/security_solution/public/network/components/kpi_network/unique_private_ips/index.tsx @@ -13,10 +13,10 @@ import { useNetworkKpiUniquePrivateIps } from '../../../containers/kpi_network/u import { NetworkKpiBaseComponentManage } from '../common'; import { NetworkKpiProps } from '../types'; import * as i18n from './translations'; -import { kpiUniquePrivateIpsSourceMetric } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_source_metric'; -import { kpiUniquePrivateIpsDestinationMetric } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_destination_metric'; -import { kpiUniquePrivateIpsArea } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_area'; -import { kpiUniquePrivateIpsBar } from '../../../../common/components/visualization_actions/configs/network/kpi_unique_private_ips_bar'; +import { kpiUniquePrivateIpsSourceMetricLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_source_metric'; +import { kpiUniquePrivateIpsDestinationMetricLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_destination_metric'; +import { kpiUniquePrivateIpsAreaLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_area'; +import { kpiUniquePrivateIpsBarLensAttributes } from '../../../../common/components/visualization_actions/lens_attributes/network/kpi_unique_private_ips_bar'; const euiVisColorPalette = euiPaletteColorBlind(); const euiColorVis2 = euiVisColorPalette[2]; @@ -33,7 +33,7 @@ export const fieldsMapping: Readonly = [ description: i18n.SOURCE_UNIT_LABEL, color: euiColorVis2, icon: 'visMapCoordinate', - lensAttributes: kpiUniquePrivateIpsSourceMetric, + lensAttributes: kpiUniquePrivateIpsSourceMetricLensAttributes, }, { key: 'uniqueDestinationPrivateIps', @@ -42,14 +42,14 @@ export const fieldsMapping: Readonly = [ description: i18n.DESTINATION_UNIT_LABEL, color: euiColorVis3, icon: 'visMapCoordinate', - lensAttributes: kpiUniquePrivateIpsDestinationMetric, + lensAttributes: kpiUniquePrivateIpsDestinationMetricLensAttributes, }, ], description: i18n.UNIQUE_PRIVATE_IPS, enableAreaChart: true, enableBarChart: true, - areaChartLensAttributes: kpiUniquePrivateIpsArea, - barChartLensAttributes: kpiUniquePrivateIpsBar, + areaChartLensAttributes: kpiUniquePrivateIpsAreaLensAttributes, + barChartLensAttributes: kpiUniquePrivateIpsBarLensAttributes, }, ]; diff --git a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx index e9c6d84fd5459d..21404690438a02 100644 --- a/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/network/pages/navigation/dns_query_tab_body.tsx @@ -23,7 +23,7 @@ import { MatrixHistogram } from '../../../common/components/matrix_histogram'; import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution'; import { networkSelectors } from '../../store'; import { useShallowEqualSelector } from '../../../common/hooks/use_selector'; -import { dnsTopDomainsAttrs } from '../../../common/components/visualization_actions/configs/network/dns_top_domains'; +import { dnsTopDomainsLensAttributes } from '../../../common/components/visualization_actions/lens_attributes/network/dns_top_domains'; const HISTOGRAM_ID = 'networkDnsHistogramQuery'; @@ -45,7 +45,7 @@ export const histogramConfigs: Omit = { histogramType: MatrixHistogramType.dns, stackByOptions: dnsStackByOptions, subtitle: undefined, - lensAttributes: dnsTopDomainsAttrs, + lensAttributes: dnsTopDomainsLensAttributes, }; const DnsQueryTabBodyComponent: React.FC = ({ From 5ddb9eb1b5fe6304f24819726042afb48701e34a Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 16 Mar 2022 01:04:54 +0800 Subject: [PATCH 59/59] add readme --- .../lens_attributes/readme.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/readme.md diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/readme.md b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/readme.md new file mode 100644 index 00000000000000..f9620a2a42eeff --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/readme.md @@ -0,0 +1,19 @@ + +# Steps to generate Lens attributes: +All the files in the folder were exported from Lens. These Lens attributes allow the charts implemented by Security Solution (Not with Lens Embeddable) on Host and Network pages to share across the app. + + +Here are the steps of how to generate them: + +1. Launch Kibana, go to `Visualize Library`, `Create visualization`, and select `Lens` to enter the editor. +2. Create the visualization and save it. +3. Go to `Stack Management` > `Saved Objects`, tick the box of the visualization you just created, and click `Export` +4. Create a new file in this folder with the attributes below from the exported file: + - description + - state + - title + - visualizationType + - references + + Note: `id` under `references` will eventually be replaced according to selected data view id on Security Solution's page +