From afefc33e27ff6eaf371b051b250b62294e010786 Mon Sep 17 00:00:00 2001 From: FrankHassanabad Date: Fri, 19 Jul 2019 17:11:56 -0600 Subject: [PATCH 1/2] Fix draggables to work with escapeId and ML severity --- .../components/load_more_table/index.tsx | 2 +- .../get_anomalies_host_table_columns.test.tsx | 63 +++++++++++++++++ .../get_anomalies_host_table_columns.tsx | 5 +- ...t_anomalies_network_table_columns.test.tsx | 67 +++++++++++++++++++ .../get_anomalies_network_table_columns.tsx | 5 +- 5 files changed, 139 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/components/load_more_table/index.tsx b/x-pack/legacy/plugins/siem/public/components/load_more_table/index.tsx index 2e129f077edda4..aa1cb9559959d1 100644 --- a/x-pack/legacy/plugins/siem/public/components/load_more_table/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/load_more_table/index.tsx @@ -110,7 +110,7 @@ export interface Columns { sortable?: boolean | Func; truncateText?: boolean; hideForMobile?: boolean; - render?: (item: T, node: U) => void; + render?: (item: T, node: U) => React.ReactNode; width?: string; } diff --git a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx index 66238eaca83969..9c28080ebf425e 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx @@ -7,6 +7,11 @@ import { getAnomaliesHostTableColumnsCurated } from './get_anomalies_host_table_columns'; import { HostsType } from '../../../store/hosts/model'; import * as i18n from './translations'; +import { AnomaliesByHost } from '../types'; +import { Columns } from '../../load_more_table'; +import { TestProviders } from '../../../mock'; +import { mount } from 'enzyme'; +import React from 'react'; const startDate = new Date(2001).valueOf(); const endDate = new Date(3000).valueOf(); @@ -58,4 +63,62 @@ describe('get_anomalies_host_table_columns', () => { ); expect(columns.some(col => col.name === i18n.HOST_NAME)).toEqual(false); }); + + test('on host page, we should not have an escaped id for the severity with underscores for draggables', () => { + const columns = getAnomaliesHostTableColumnsCurated( + HostsType.page, + startDate, + endDate, + interval, + narrowDateRange + ); + const column = columns.find(col => col.name === i18n.SCORE) as Columns; + const anomaly: AnomaliesByHost = { + hostName: 'host.name', + anomaly: { + detectorIndex: 0, + entityName: 'entity-name-1', + entityValue: 'entity-value-1', + influencers: [], + jobId: 'job-1', + rowId: 'row-1', + severity: 100, + time: new Date('01/01/2000').valueOf(), + source: { + job_id: 'job-1', + result_type: 'result-1', + probability: 50, + multi_bucket_impact: 0, + record_score: 0, + initial_record_score: 0, + bucket_span: 0, + detector_index: 0, + is_interim: true, + timestamp: new Date('01/01/2000').valueOf(), + by_field_name: 'some field name', + by_field_value: 'some field valuke', + partition_field_name: 'partition field name', + partition_field_value: 'partition field value', + function: 'function-1', + function_description: 'description-1', + typical: [5, 3], + actual: [7, 4], + influencers: [], + }, + }, + }; + if (column != null && column.render != null) { + const wrapper = mount({column.render('', anomaly)}); + expect( + wrapper + .find( + '[draggableId="draggableId.content.anomalies-host-table-severity-host_name-entity-name-1-entity-value-1-100-job-1"]' + ) + .first() + .exists() + ).toBe(true); + } else { + expect(column).not.toBe(null); + } + }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.tsx b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.tsx index a76677d6732028..ef829cadb9fb63 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.tsx @@ -21,6 +21,7 @@ import { createExplorerLink } from '../links/create_explorer_link'; import { LocalizedDateTooltip } from '../../localized_date_tooltip'; import { PreferenceFormattedDate } from '../../formatted_date'; import { HostsType } from '../../../store/hosts/model'; +import { escapeDataProviderId } from '../../drag_and_drop/helpers'; export const getAnomaliesHostTableColumns = ( startDate: number, @@ -68,7 +69,9 @@ export const getAnomaliesHostTableColumns = ( sortable: true, render: (_, anomaliesByHost) => ( ), diff --git a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx index e974a7ef5f5119..2924011767ff56 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx @@ -7,6 +7,11 @@ import { getAnomaliesNetworkTableColumnsCurated } from './get_anomalies_network_table_columns'; import { NetworkType } from '../../../store/network/model'; import * as i18n from './translations'; +import { AnomaliesByNetwork } from '../types'; +import { Columns } from '../../load_more_table'; +import { mount } from 'enzyme'; +import React from 'react'; +import { TestProviders } from '../../../mock'; const startDate = new Date(2001).valueOf(); const endDate = new Date(3000).valueOf(); @@ -58,4 +63,66 @@ describe('get_anomalies_network_table_columns', () => { ); expect(columns.some(col => col.name === i18n.NETWORK_NAME)).toEqual(false); }); + + test('on the network page, we should not have an escaped id for the severity with underscores for draggables', () => { + const columns = getAnomaliesNetworkTableColumnsCurated( + NetworkType.page, + startDate, + endDate, + interval, + narrowDateRange + ); + const column = columns.find(col => col.name === i18n.SCORE) as Columns< + string, + AnomaliesByNetwork + >; + const anomaly: AnomaliesByNetwork = { + type: 'source.ip', + ip: '127.0.0.1', + anomaly: { + detectorIndex: 0, + entityName: 'entity-name-1', + entityValue: 'entity-value-1', + influencers: [], + jobId: 'job-1', + rowId: 'row-1', + severity: 100, + time: new Date('01/01/2000').valueOf(), + source: { + job_id: 'job-1', + result_type: 'result-1', + probability: 50, + multi_bucket_impact: 0, + record_score: 0, + initial_record_score: 0, + bucket_span: 0, + detector_index: 0, + is_interim: true, + timestamp: new Date('01/01/2000').valueOf(), + by_field_name: 'some field name', + by_field_value: 'some field valuke', + partition_field_name: 'partition field name', + partition_field_value: 'partition field value', + function: 'function-1', + function_description: 'description-1', + typical: [5, 3], + actual: [7, 4], + influencers: [], + }, + }, + }; + if (column != null && column.render != null) { + const wrapper = mount({column.render('', anomaly)}); + expect( + wrapper + .find( + '[draggableId="draggableId.content.anomalies-network-table-severity-127_0_0_1-entity-name-1-entity-value-1-100-job-1"]' + ) + .first() + .exists() + ).toBe(true); + } else { + expect(column).not.toBe(null); + } + }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.tsx b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.tsx index 13648fdae2472c..771f6f50857ae3 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.tsx @@ -21,6 +21,7 @@ import { createExplorerLink } from '../links/create_explorer_link'; import { LocalizedDateTooltip } from '../../localized_date_tooltip'; import { PreferenceFormattedDate } from '../../formatted_date'; import { NetworkType } from '../../../store/network/model'; +import { escapeDataProviderId } from '../../drag_and_drop/helpers'; export const getAnomaliesNetworkTableColumns = ( startDate: number, @@ -66,7 +67,9 @@ export const getAnomaliesNetworkTableColumns = ( sortable: true, render: (_, anomaliesByNetwork) => ( ), From 3209268f01d4d2e814e5421a967272c370e5e2f0 Mon Sep 17 00:00:00 2001 From: FrankHassanabad Date: Fri, 19 Jul 2019 17:23:59 -0600 Subject: [PATCH 2/2] Fix draggables --- .../ml/tables/get_anomalies_host_table_columns.test.tsx | 2 +- .../ml/tables/get_anomalies_network_table_columns.test.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx index 9c28080ebf425e..5aeeee6d583047 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_host_table_columns.test.tsx @@ -64,7 +64,7 @@ describe('get_anomalies_host_table_columns', () => { expect(columns.some(col => col.name === i18n.HOST_NAME)).toEqual(false); }); - test('on host page, we should not have an escaped id for the severity with underscores for draggables', () => { + test('on host page, we should escape the draggable id', () => { const columns = getAnomaliesHostTableColumnsCurated( HostsType.page, startDate, diff --git a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx index 2924011767ff56..706c4feaa0f37f 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/tables/get_anomalies_network_table_columns.test.tsx @@ -64,7 +64,7 @@ describe('get_anomalies_network_table_columns', () => { expect(columns.some(col => col.name === i18n.NETWORK_NAME)).toEqual(false); }); - test('on the network page, we should not have an escaped id for the severity with underscores for draggables', () => { + test('on network page, we should escape the draggable id', () => { const columns = getAnomaliesNetworkTableColumnsCurated( NetworkType.page, startDate,