Skip to content

Commit

Permalink
[8.15] [Bug][Investigations][Timeline] - Fix row highlighting & d…
Browse files Browse the repository at this point in the history
…efault enable row renderers (#188388) (#188591)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Bug][Investigations][Timeline] - Fix row highlighting & default
enable row renderers
(#188388)](#188388)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Michael
Olorunnisola","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-07-17T18:55:27Z","message":"[Bug][Investigations][Timeline]
- Fix row highlighting & default enable row renderers (#188388)\n\n##
Summary\r\n\r\nThis PR accomplishes the following 2 things.\r\n\r\n1. It
fixes row highlighting for the default table as the timeline\r\nstyles
were only being applied when `renderCustomGridBody` was
being\r\nused.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/27fdfae2-729f-46d3-b1f3-691e768c871a\r\n\r\n\r\n2.
It default enables the Row Renderers for the
`investigateInTimeline`\r\nand timeline template
workflows.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f074eaf7-3b8e-4f07-9a5d-face2b9f94a2\r\n\r\n---------\r\n\r\nCo-authored-by:
Jatin Kathuria <[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"5efc0f6bab76797036c27d0fb4726e5dc535eed4","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Threat
Hunting:Investigations","v8.15.0","v8.16.0"],"title":"[Bug][Investigations][Timeline]
- Fix row highlighting & default enable row
renderers","number":188388,"url":"https://github.com/elastic/kibana/pull/188388","mergeCommit":{"message":"[Bug][Investigations][Timeline]
- Fix row highlighting & default enable row renderers (#188388)\n\n##
Summary\r\n\r\nThis PR accomplishes the following 2 things.\r\n\r\n1. It
fixes row highlighting for the default table as the timeline\r\nstyles
were only being applied when `renderCustomGridBody` was
being\r\nused.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/27fdfae2-729f-46d3-b1f3-691e768c871a\r\n\r\n\r\n2.
It default enables the Row Renderers for the
`investigateInTimeline`\r\nand timeline template
workflows.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f074eaf7-3b8e-4f07-9a5d-face2b9f94a2\r\n\r\n---------\r\n\r\nCo-authored-by:
Jatin Kathuria <[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"5efc0f6bab76797036c27d0fb4726e5dc535eed4"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/188388","number":188388,"mergeCommit":{"message":"[Bug][Investigations][Timeline]
- Fix row highlighting & default enable row renderers (#188388)\n\n##
Summary\r\n\r\nThis PR accomplishes the following 2 things.\r\n\r\n1. It
fixes row highlighting for the default table as the timeline\r\nstyles
were only being applied when `renderCustomGridBody` was
being\r\nused.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/27fdfae2-729f-46d3-b1f3-691e768c871a\r\n\r\n\r\n2.
It default enables the Row Renderers for the
`investigateInTimeline`\r\nand timeline template
workflows.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f074eaf7-3b8e-4f07-9a5d-face2b9f94a2\r\n\r\n---------\r\n\r\nCo-authored-by:
Jatin Kathuria <[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"5efc0f6bab76797036c27d0fb4726e5dc535eed4"}}]}]
BACKPORT-->

Co-authored-by: Michael Olorunnisola <[email protected]>
  • Loading branch information
kibanamachine and michaelolo24 authored Jul 17, 2024
1 parent e80610f commit 208e83a
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const getExpectedcreateTimelineParam = (
notes: null,
timeline: {
...timelineDefaults,
excludedRowRendererIds: [],
dataProviders,
id: TimelineId.active,
indexNames: [],
Expand Down Expand Up @@ -379,7 +380,7 @@ describe('alert actions', () => {
},
eventIdToNoteIds: {},
eventType: 'all',
excludedRowRendererIds: defaultTimelineProps.timeline.excludedRowRendererIds,
excludedRowRendererIds: [],
expandedDetail: {},
filters: [
{
Expand Down Expand Up @@ -549,10 +550,13 @@ describe('alert actions', () => {
getExceptionFilter: mockGetExceptionFilter,
});

const expectedTimelineProps = structuredClone(defaultTimelineProps);
expectedTimelineProps.timeline.excludedRowRendererIds = [];

expect(updateTimelineIsLoading).not.toHaveBeenCalled();
expect(mockGetExceptionFilter).not.toHaveBeenCalled();
expect(createTimeline).toHaveBeenCalledTimes(1);
expect(createTimeline).toHaveBeenCalledWith(defaultTimelineProps);
expect(createTimeline).toHaveBeenCalledWith(expectedTimelineProps);
});
});

Expand All @@ -576,10 +580,13 @@ describe('alert actions', () => {
getExceptionFilter: mockGetExceptionFilter,
});

const expectedTimelineProps = structuredClone(defaultTimelineProps);
expectedTimelineProps.timeline.excludedRowRendererIds = [];

expect(updateTimelineIsLoading).not.toHaveBeenCalled();
expect(mockGetExceptionFilter).not.toHaveBeenCalled();
expect(createTimeline).toHaveBeenCalledTimes(1);
expect(createTimeline).toHaveBeenCalledWith(defaultTimelineProps);
expect(createTimeline).toHaveBeenCalledWith(expectedTimelineProps);
});
});

Expand Down Expand Up @@ -614,6 +621,7 @@ describe('alert actions', () => {
...defaultTimelineProps,
timeline: {
...defaultTimelineProps.timeline,
excludedRowRendererIds: [],
resolveTimelineConfig: undefined,
dataProviders: [
{
Expand Down Expand Up @@ -642,6 +650,9 @@ describe('alert actions', () => {
},
};

const expectedTimelineProps = structuredClone(defaultTimelineProps);
expectedTimelineProps.timeline.excludedRowRendererIds = [];

await sendAlertToTimelineAction({
createTimeline,
ecsData: ecsDataMock,
Expand All @@ -653,7 +664,7 @@ describe('alert actions', () => {
expect(updateTimelineIsLoading).not.toHaveBeenCalled();
expect(mockGetExceptionFilter).not.toHaveBeenCalled();
expect(createTimeline).toHaveBeenCalledTimes(1);
expect(createTimeline).toHaveBeenCalledWith(defaultTimelineProps);
expect(createTimeline).toHaveBeenCalledWith(expectedTimelineProps);
});
});

Expand Down Expand Up @@ -737,6 +748,7 @@ describe('alert actions', () => {
...defaultTimelineProps,
timeline: {
...defaultTimelineProps.timeline,
excludedRowRendererIds: [],
dataProviders: [
{
and: [],
Expand Down Expand Up @@ -890,6 +902,7 @@ describe('alert actions', () => {
...defaultTimelineProps,
timeline: {
...defaultTimelineProps.timeline,
excludedRowRendererIds: [],
columns: mockGetOneTimelineResult.columns,
defaultColumns: defaultUdtHeaders,
dataProviders: [],
Expand Down Expand Up @@ -1043,6 +1056,7 @@ describe('alert actions', () => {
...defaultTimelineProps,
timeline: {
...defaultTimelineProps.timeline,
excludedRowRendererIds: [],
filters: [
{
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ const createThresholdTimeline = async (
notes: null,
timeline: {
...timelineDefaults,
excludedRowRendererIds: [],
columns: templateValues.columns ?? timelineDefaults.columns,
description: `_id: ${alertDoc._id}`,
filters: allFilters,
Expand Down Expand Up @@ -655,6 +656,7 @@ const createNewTermsTimeline = async (
timeline: {
...timelineDefaults,
columns: templateValues.columns ?? timelineDefaults.columns,
excludedRowRendererIds: [],
description: `_id: ${alertDoc._id}`,
filters: allFilters,
dataProviders: templateValues.dataProviders ?? dataProviders,
Expand Down Expand Up @@ -824,6 +826,7 @@ const createSuppressedTimeline = async (
notes: null,
timeline: {
...timelineDefaults,
excludedRowRendererIds: [],
columns: templateValues.columns ?? timelineDefaults.columns,
description: `_id: ${alertDoc._id}`,
filters: allFilters,
Expand Down Expand Up @@ -906,6 +909,7 @@ export const sendBulkEventsToTimelineAction = async (
notes: null,
timeline: {
...timelineDefaults,
excludedRowRendererIds: [],
dataProviders,
id: TimelineId.active,
indexNames: [],
Expand Down Expand Up @@ -1050,6 +1054,7 @@ export const sendAlertToTimelineAction = async ({
from,
timeline: {
...timeline,
excludedRowRendererIds: [],
title: '',
timelineType: TimelineType.default,
templateTimelineId: null,
Expand Down Expand Up @@ -1126,6 +1131,7 @@ export const sendAlertToTimelineAction = async ({
notes: null,
timeline: {
...timelineDefaults,
excludedRowRendererIds: [],
dataProviders,
id: TimelineId.active,
indexNames: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ export const useInvestigateInTimeline = ({
columns: !unifiedComponentsInTimelineDisabled ? defaultUdtHeaders : defaultHeaders,
indexNames: timeline.indexNames ?? [],
show: true,
excludedRowRendererIds: !unifiedComponentsInTimelineDisabled
? timeline.excludedRowRendererIds
: [],
excludedRowRendererIds:
!unifiedComponentsInTimelineDisabled && timeline.timelineType !== TimelineType.template
? timeline.excludedRowRendererIds
: [],
},
to: toTimeline,
ruleNote,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('NewTimelineButton', () => {
show: true,
timelineType: TimelineType.template,
updated: undefined,
excludedRowRendererIds: [...Object.values(RowRendererId)],
excludedRowRendererIds: [],
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ describe('helpers', () => {
expect(newTimeline).toEqual({
...defaultTimeline,
columns: defaultUdtHeaders,
excludedRowRendererIds: [],
});
});

Expand Down Expand Up @@ -500,6 +501,7 @@ describe('helpers', () => {
timelineType: TimelineType.template,
title: 'Awesome Timeline',
columns: defaultUdtHeaders,
excludedRowRendererIds: [],
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ import type {
PinnedEvent,
Note,
} from '../../../../common/api/timeline';
import {
RowRendererId,
DataProviderType,
TimelineStatus,
TimelineType,
} from '../../../../common/api/timeline';
import { TimelineId, TimelineTabs } from '../../../../common/types/timeline';
import { DataProviderType, TimelineStatus, TimelineType } from '../../../../common/api/timeline';
import { useUpdateTimeline } from './use_update_timeline';

import type { TimelineModel } from '../../store/model';
Expand Down Expand Up @@ -256,6 +261,7 @@ export const defaultTimelineToTimelineModel = (
}
: timeline.dateRange,
dataProviders: getDataProviders(duplicate, timeline.dataProviders, timelineType),
excludedRowRendererIds: isTemplate ? [] : Object.keys(RowRendererId),
eventIdToNoteIds: setEventIdToNoteIds(duplicate, timeline.eventIdToNoteIds),
filters: timeline.filters != null ? timeline.filters.map(setTimelineFilters) : [],
isFavorite: duplicate
Expand Down Expand Up @@ -358,9 +364,10 @@ export const useQueryTimelineById = () => {
show: openTimeline,
initialized: true,
savedSearchId: savedSearchId ?? null,
excludedRowRendererIds: !unifiedComponentsInTimelineDisabled
? timelineDefaults.excludedRowRendererIds
: [],
excludedRowRendererIds:
!unifiedComponentsInTimelineDisabled && timelineType !== TimelineType.template
? timelineDefaults.excludedRowRendererIds
: [],
},
});
resetDiscoverAppState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import styled from 'styled-components';
import type { RowRenderer } from '../../../../../../common/types';
import { TIMELINE_EVENT_DETAIL_ROW_ID } from '../../body/constants';
import { useStatefulRowRenderer } from '../../body/events/stateful_row_renderer/use_stateful_row_renderer';
import { useGetEventTypeRowClassName } from './use_get_event_type_row_classname';
import { getEventTypeRowClassName } from './get_event_type_row_classname';

export type CustomTimelineDataGridBodyProps = EuiDataGridCustomBodyProps & {
rows: Array<DataTableRecord & TimelineItem> | undefined;
Expand Down Expand Up @@ -181,7 +181,7 @@ const CustomDataGridSingleRow = memo(function CustomDataGridSingleRow(
: {},
[canShowRowRenderer]
);
const eventTypeRowClassName = useGetEventTypeRowClassName(rowData.ecs);
const eventTypeRowClassName = useMemo(() => getEventTypeRowClassName(rowData.ecs), [rowData.ecs]);

return (
<CustomGridRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { useGetEventTypeRowClassName } from './use_get_event_type_row_classname';
import { renderHook } from '@testing-library/react-hooks';
import { getEventTypeRowClassName } from './get_event_type_row_classname';

const mockOddEqlEvent = {
_id: 'test-eql-alert',
Expand All @@ -29,29 +28,29 @@ const mockEvent = {
_id: 'basic-event',
};

describe('useGetEventTypeRowClassName', () => {
describe('getEventTypeRowClassName', () => {
it('should return rawEvent', () => {
const { result } = renderHook(() => useGetEventTypeRowClassName(mockEvent));
expect(result.current).toEqual('rawEvent');
const result = getEventTypeRowClassName(mockEvent);
expect(result).toEqual('rawEvent');
});

it('should contain eqlSequence', () => {
const { result } = renderHook(() => useGetEventTypeRowClassName(mockBuildingBlockAlert));
expect(result.current).toContain('eqlSequence');
const result = getEventTypeRowClassName(mockBuildingBlockAlert);
expect(result).toContain('eqlSequence');
});

it('should contain buildingBlockType', () => {
const { result } = renderHook(() => useGetEventTypeRowClassName(mockBuildingBlockAlert));
expect(result.current).toContain('buildingBlockType');
const result = getEventTypeRowClassName(mockBuildingBlockAlert);
expect(result).toContain('buildingBlockType');
});

it('should return eqlNonSequence', () => {
const { result } = renderHook(() => useGetEventTypeRowClassName(mockOddEqlEvent));
expect(result.current).toEqual('eqlNonSequence');
const result = getEventTypeRowClassName(mockOddEqlEvent);
expect(result).toEqual('eqlNonSequence');
});

it('should return nonRawEvent', () => {
const { result } = renderHook(() => useGetEventTypeRowClassName(mockAlert));
expect(result.current).toEqual('nonRawEvent');
const result = getEventTypeRowClassName(mockAlert);
expect(result).toEqual('nonRawEvent');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { TimelineItem } from '@kbn/timelines-plugin/common';
import { getEventType, isEvenEqlSequence, isEventBuildingBlockType } from '../../body/helpers';

export const getEventTypeRowClassName = (ecsData: TimelineItem['ecs']) => {
const eventType = getEventType(ecsData);
const eventTypeClassName =
eventType === 'raw'
? 'rawEvent'
: eventType === 'eql'
? isEvenEqlSequence(ecsData)
? 'eqlSequence'
: 'eqlNonSequence'
: 'nonRawEvent';

const buildingBlockTypeClassName = isEventBuildingBlockType(ecsData) ? 'buildingBlockType' : '';

return `${eventTypeClassName} ${buildingBlockTypeClassName}`.trim();
};
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const TimelineDataTableComponent: React.FC<DataTableProps> = memo(
selectTimelineById(state, timelineId)
);

const tableRows = useMemo(
const { tableRows, tableStylesOverride } = useMemo(
() => transformTimelineItemToUnifiedRows({ events, dataView }),
[events, dataView]
);
Expand Down Expand Up @@ -424,9 +424,10 @@ export const TimelineDataTableComponent: React.FC<DataTableProps> = memo(
<UnifiedTimelineGlobalStyles />
<DataGridMemoized
ariaLabelledBy="timelineDocumentsAriaLabel"
className={'udtTimeline'}
className="udtTimeline"
columns={columnIds}
expandedDoc={expandedDoc}
gridStyleOverride={tableStylesOverride}
dataView={dataView}
showColumnTokens={true}
loadingState={dataLoadingState}
Expand Down

This file was deleted.

Loading

0 comments on commit 208e83a

Please sign in to comment.