Skip to content

Commit

Permalink
[SIEM] Fix draggables to work with escapeId for the ML severity column (
Browse files Browse the repository at this point in the history
#41621)

## Summary

Blocker bug where you could not drag and drop to the timeline.
![drag-n-drop-issue-with-severity](https://user-images.githubusercontent.com/1151048/61570279-cf12e500-aa48-11e9-967f-8ef0e6c8750b.gif)

Fix for host:
![drag-and-dop-host](https://user-images.githubusercontent.com/1151048/61570380-6aa45580-aa49-11e9-80e6-2a9e7fa7f650.gif)

Fix for network:
![network-drag-and-drop](https://user-images.githubusercontent.com/1151048/61570386-7132cd00-aa49-11e9-8342-1524aeb5093f.gif)


One line fix for it so you can drag and drop to the timeline 

### Checklist

Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR.

~- [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~

~- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~

~- [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~

~- [ ] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios~

~- [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~

### For maintainers

~- [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~

~- [ ] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~
  • Loading branch information
FrankHassanabad committed Jul 20, 2019
1 parent e356de8 commit 5a06491
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface Columns<T, U = T> {
sortable?: boolean | Func<T>;
truncateText?: boolean;
hideForMobile?: boolean;
render?: (item: T, node: U) => void;
render?: (item: T, node: U) => React.ReactNode;
width?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 escape the draggable id', () => {
const columns = getAnomaliesHostTableColumnsCurated(
HostsType.page,
startDate,
endDate,
interval,
narrowDateRange
);
const column = columns.find(col => col.name === i18n.SCORE) as Columns<string, AnomaliesByHost>;
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(<TestProviders>{column.render('', anomaly)}</TestProviders>);
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);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -68,7 +69,9 @@ export const getAnomaliesHostTableColumns = (
sortable: true,
render: (_, anomaliesByHost) => (
<DraggableScore
id={`anomalies-host-table-severity-${createCompoundHostKey(anomaliesByHost)}`}
id={escapeDataProviderId(
`anomalies-host-table-severity-${createCompoundHostKey(anomaliesByHost)}`
)}
score={anomaliesByHost.anomaly}
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -58,4 +63,66 @@ describe('get_anomalies_network_table_columns', () => {
);
expect(columns.some(col => col.name === i18n.NETWORK_NAME)).toEqual(false);
});

test('on network page, we should escape the draggable id', () => {
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(<TestProviders>{column.render('', anomaly)}</TestProviders>);
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);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,7 +67,9 @@ export const getAnomaliesNetworkTableColumns = (
sortable: true,
render: (_, anomaliesByNetwork) => (
<DraggableScore
id={`anomalies-network-table-severity-${createCompoundNetworkKey(anomaliesByNetwork)}`}
id={escapeDataProviderId(
`anomalies-network-table-severity-${createCompoundNetworkKey(anomaliesByNetwork)}`
)}
score={anomaliesByNetwork.anomaly}
/>
),
Expand Down

0 comments on commit 5a06491

Please sign in to comment.