forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ Security Solution ] - Better row indicators with
getRowIndicator
…
…callback (elastic#206736) ## Summary Recently unified table introduced `getRowIndicator` callback to add row highlighting. Today Security solution achieves that by using `border-left` style. This PR replaces that `border-left` with `getRowIndicator` . > [!Note] > One thing to note is that `Event/Row Renderers` will still make use of `border-left` as it is a cell and `getRowIndicator` applies only to a complete `row`. ### Without Row Renderers || Before | After | |---|---|---| |Query Tab | ![image](https://github.com/user-attachments/assets/bb5405f6-9403-40b3-9cec-4dab1aeb4606) | ![image](https://github.com/user-attachments/assets/38fd410f-9d2e-4ed6-a194-e3681ed07c3e)| |Correlation Tab| ![image](https://github.com/user-attachments/assets/f8914ade-5e5f-4d0c-9bfc-dd4667f252e7)|![image](https://github.com/user-attachments/assets/d86fdf46-0fd9-4a28-bec1-381783a3641c)| ### With Row Renderers || Before | After | |---|---|---| |Query Tab | ![image](https://github.com/user-attachments/assets/4f0d2777-9e5e-4685-abaa-5d5eece655b4)|![image](https://github.com/user-attachments/assets/8ce6b8a3-bbc8-4919-941a-fa0b2ab5254e)| |Correlation Tab|![image](https://github.com/user-attachments/assets/560ef16e-abe0-45f9-8c47-f1cde43facc1)|![image](https://github.com/user-attachments/assets/576ee2eb-258b-4d51-90ce-1848944aea2a)| ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] 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/main/src/platform/packages/shared/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
8 changed files
with
197 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...lic/timelines/components/timeline/unified_components/data_table/get_row_indicator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 type { DataTableRecord } from '@kbn/discover-utils'; | ||
import { getTimelineRowTypeIndicator } from './get_row_indicator'; | ||
import type { EuiThemeComputed } from '@elastic/eui'; | ||
|
||
const mockEuiTheme = { | ||
colors: { | ||
primary: 'primary', | ||
accent: 'accent', | ||
warning: 'warning', | ||
lightShade: 'lightShade', | ||
}, | ||
} as EuiThemeComputed; | ||
|
||
describe('getTimelineRowTypeIndicator', () => { | ||
describe('Alert', () => { | ||
it('should return correct label and color for EQL Event', () => { | ||
const row = { | ||
flattened: { | ||
'event.kind': 'signal', | ||
'eql.parentId': '123', | ||
'eql.sequenceNumber': '1-3', | ||
}, | ||
} as unknown as DataTableRecord; | ||
const rowIndicator = getTimelineRowTypeIndicator(row, mockEuiTheme); | ||
expect(rowIndicator).toEqual({ | ||
color: 'accent', | ||
label: 'EQL Sequence', | ||
}); | ||
}); | ||
it('should return correct label and color for non-EQL Event', () => { | ||
const row = { | ||
flattened: { | ||
'event.kind': 'signal', | ||
}, | ||
} as unknown as DataTableRecord; | ||
const rowIndicator = getTimelineRowTypeIndicator(row, mockEuiTheme); | ||
expect(rowIndicator).toEqual({ | ||
color: 'warning', | ||
label: 'Alert', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Event', () => { | ||
it('should return correct label and color for EQL Event', () => { | ||
const row = { | ||
flattened: { | ||
'eql.parentId': '123', | ||
'eql.sequenceNumber': '1-3', | ||
}, | ||
} as unknown as DataTableRecord; | ||
const rowIndicator = getTimelineRowTypeIndicator(row, mockEuiTheme); | ||
expect(rowIndicator).toEqual({ | ||
color: 'accent', | ||
label: 'EQL Sequence', | ||
}); | ||
}); | ||
it('should return correct label and color for non-EQL Event', () => { | ||
const row = { | ||
flattened: {}, | ||
} as unknown as DataTableRecord; | ||
const rowIndicator = getTimelineRowTypeIndicator(row, mockEuiTheme); | ||
expect(rowIndicator).toMatchObject({ | ||
color: 'lightShade', | ||
label: 'Event', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('EQL Event Type', () => { | ||
it('should return correct label and color for Even EQL Sequence', () => { | ||
const row = { | ||
flattened: { | ||
'eql.parentId': '123', | ||
'eql.sequenceNumber': '2-4', | ||
}, | ||
} as unknown as DataTableRecord; | ||
const rowIndicator = getTimelineRowTypeIndicator(row, mockEuiTheme); | ||
expect(rowIndicator).toEqual({ | ||
color: 'primary', | ||
label: 'EQL Sequence', | ||
}); | ||
}); | ||
it('should return correct label and color for Non-Even EQL Sequence', () => { | ||
const row = { | ||
flattened: { | ||
'eql.parentId': '123', | ||
'eql.sequenceNumber': '1-4', | ||
}, | ||
} as unknown as DataTableRecord; | ||
const rowIndicator = getTimelineRowTypeIndicator(row, mockEuiTheme); | ||
expect(rowIndicator).toEqual({ | ||
color: 'accent', | ||
label: 'EQL Sequence', | ||
}); | ||
}); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...n/public/timelines/components/timeline/unified_components/data_table/get_row_indicator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { EuiThemeComputed } from '@elastic/eui'; | ||
import type { DataTableRecord } from '@kbn/discover-utils'; | ||
import { getFieldValue } from '@kbn/discover-utils'; | ||
import type { UnifiedDataTableProps } from '@kbn/unified-data-table'; | ||
import { isEmpty } from 'lodash'; | ||
|
||
export const getTimelineRowTypeIndicator: NonNullable<UnifiedDataTableProps['getRowIndicator']> = ( | ||
row: DataTableRecord, | ||
euiTheme: EuiThemeComputed | ||
) => { | ||
const isAlert = getFieldValue(row, 'event.kind') === 'signal'; | ||
|
||
const isEql = | ||
!isEmpty(getFieldValue(row, 'eql.parentId')) && | ||
!isEmpty(getFieldValue(row, 'eql.sequenceNumber')); | ||
|
||
if (isEql) { | ||
const sequenceNumber = ((getFieldValue(row, 'eql.sequenceNumber') as string) ?? '').split( | ||
'-' | ||
)[0]; | ||
|
||
const isEvenSequence = parseInt(sequenceNumber, 10) % 2 === 0; | ||
|
||
return { | ||
/* alternating colors to differentiate consecutive sequences */ | ||
color: isEvenSequence ? euiTheme.colors.primary : euiTheme.colors.accent, | ||
label: 'EQL Sequence', | ||
}; | ||
} | ||
|
||
if (isAlert) { | ||
return { | ||
color: euiTheme.colors.warning, | ||
label: 'Alert', | ||
}; | ||
} | ||
|
||
return { | ||
color: euiTheme.colors.lightShade, | ||
label: 'Event', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters