Skip to content

Commit

Permalink
[8.x] [Security Solution] Deletes Old Timeline Code (#196243) (#199287)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Deletes Old Timeline Code
(#196243)](#196243)

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

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

<!--BACKPORT [{"author":{"name":"Jatin
Kathuria","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-07T10:39:55Z","message":"[Security
Solution] Deletes Old Timeline Code (#196243)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/security-team/issues/9676\r\n\r\nThis is
follow up of the PR :\r\nhttps://github.com//pull/195959
where we had removed\r\nfeature flag
`unifiedComponentsInTimelineDisabled`.\r\n\r\nThis PR completes unified
components migration in Timeline. \r\n\r\n## Changes\r\n\r\nMost changes
in this PR are : \r\n\r\n1. Deletion for the obsolete code.\r\n2.
Refactoring of needed utils ( only 3. have marked in comments below
)\r\n3. Updating import path of above
utils.","sha":"c9d167f1ab584c315f820dc94ba2d51864d508f4","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:skip","v9.0.0","Team:Threat
Hunting:Investigations","v8.17.0"],"title":"[Security Solution] Deletes
Old Timeline
Code","number":196243,"url":"https://github.com/elastic/kibana/pull/196243","mergeCommit":{"message":"[Security
Solution] Deletes Old Timeline Code (#196243)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/security-team/issues/9676\r\n\r\nThis is
follow up of the PR :\r\nhttps://github.com//pull/195959
where we had removed\r\nfeature flag
`unifiedComponentsInTimelineDisabled`.\r\n\r\nThis PR completes unified
components migration in Timeline. \r\n\r\n## Changes\r\n\r\nMost changes
in this PR are : \r\n\r\n1. Deletion for the obsolete code.\r\n2.
Refactoring of needed utils ( only 3. have marked in comments below
)\r\n3. Updating import path of above
utils.","sha":"c9d167f1ab584c315f820dc94ba2d51864d508f4"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196243","number":196243,"mergeCommit":{"message":"[Security
Solution] Deletes Old Timeline Code (#196243)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/security-team/issues/9676\r\n\r\nThis is
follow up of the PR :\r\nhttps://github.com//pull/195959
where we had removed\r\nfeature flag
`unifiedComponentsInTimelineDisabled`.\r\n\r\nThis PR completes unified
components migration in Timeline. \r\n\r\n## Changes\r\n\r\nMost changes
in this PR are : \r\n\r\n1. Deletion for the obsolete code.\r\n2.
Refactoring of needed utils ( only 3. have marked in comments below
)\r\n3. Updating import path of above
utils.","sha":"c9d167f1ab584c315f820dc94ba2d51864d508f4"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jatin Kathuria <[email protected]>
  • Loading branch information
kibanamachine and logeekal authored Nov 7, 2024
1 parent 027f843 commit f81ee32
Show file tree
Hide file tree
Showing 92 changed files with 212 additions and 7,104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import type {
SetEventsLoading,
ControlColumnProps,
} from '../../../../../common/types';
import { getMappedNonEcsValue } from '../../../../timelines/components/timeline/body/data_driven_columns';
import type { TimelineItem, TimelineNonEcsData } from '../../../../../common/search_strategy';
import type { ColumnHeaderOptions, OnRowSelected } from '../../../../../common/types/timeline';
import { useIsExperimentalFeatureEnabled } from '../../../hooks/use_experimental_features';
import { useTourContext } from '../../guided_onboarding_tour';
import { AlertsCasesTourSteps, SecurityStepId } from '../../guided_onboarding_tour/tour_config';
import { getMappedNonEcsValue } from '../../../utils/get_mapped_non_ecs_value';

export type RowActionProps = EuiDataGridCellValueElementProps & {
columnHeaders: ColumnHeaderOptions[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ import type { EuiTheme } from '@kbn/kibana-react-plugin/common';
import type { EuiDataGridRowHeightsOptions } from '@elastic/eui';
import type { RunTimeMappings } from '@kbn/timelines-plugin/common/search_strategy';
import { ALERTS_TABLE_VIEW_SELECTION_KEY } from '../../../../common/constants';
import type { Sort } from '../../../timelines/components/timeline/body/sort';
import type {
ControlColumnProps,
OnRowSelected,
OnSelectAll,
SetEventsDeleted,
SetEventsLoading,
} from '../../../../common/types';
import type { RowRenderer } from '../../../../common/types/timeline';
import type { RowRenderer, SortColumnTimeline as Sort } from '../../../../common/types/timeline';
import { InputsModelId } from '../../store/inputs/constants';
import type { State } from '../../store';
import { inputsActions } from '../../store/actions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { EuiButtonIcon, EuiToolTip, EuiCheckbox } from '@elastic/eui';
import { useDispatch } from 'react-redux';

import styled from 'styled-components';
import { isFullScreen } from '../../../timelines/components/timeline/helpers';
import type { HeaderActionProps } from '../../../../common/types';
import { TimelineId } from '../../../../common/types';
import { isFullScreen } from '../../../timelines/components/timeline/body/column_headers';
import { isActiveTimeline } from '../../../helpers';
import { getColumnHeader } from '../../../timelines/components/timeline/body/column_headers/helpers';
import { timelineActions } from '../../../timelines/store';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 { TimelineNonEcsData } from '@kbn/timelines-plugin/common';
import { getMappedNonEcsValue, useGetMappedNonEcsValue } from './get_mapped_non_ecs_value';
import { renderHook } from '@testing-library/react-hooks';

describe('getMappedNonEcsValue', () => {
it('should return the correct value', () => {
const data: TimelineNonEcsData[] = [{ field: 'field1', value: ['value1'] }];
const fieldName = 'field1';
const result = getMappedNonEcsValue({ data, fieldName });
expect(result).toEqual(['value1']);
});

it('should return undefined if item is null', () => {
const data: TimelineNonEcsData[] = [{ field: 'field1', value: ['value1'] }];
const fieldName = 'field2';
const result = getMappedNonEcsValue({ data, fieldName });
expect(result).toEqual(undefined);
});

it('should return undefined if item.value is null', () => {
const data: TimelineNonEcsData[] = [{ field: 'field1', value: null }];
const fieldName = 'non_existent_field';
const result = getMappedNonEcsValue({ data, fieldName });
expect(result).toEqual(undefined);
});

it('should return undefined if data is undefined', () => {
const data = undefined;
const fieldName = 'field1';
const result = getMappedNonEcsValue({ data, fieldName });
expect(result).toEqual(undefined);
});

it('should return undefined if data is empty', () => {
const data: TimelineNonEcsData[] = [];
const fieldName = 'field1';
const result = getMappedNonEcsValue({ data, fieldName });
expect(result).toEqual(undefined);
});
});

describe('useGetMappedNonEcsValue', () => {
it('should return the correct value', () => {
const data: TimelineNonEcsData[] = [{ field: 'field1', value: ['value1'] }];
const fieldName = 'field1';
const { result } = renderHook(() => useGetMappedNonEcsValue({ data, fieldName }));
expect(result.current).toEqual(['value1']);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { TimelineNonEcsData } from '@kbn/timelines-plugin/common';
import { useMemo } from 'react';

export const getMappedNonEcsValue = ({
data,
fieldName,
}: {
data?: TimelineNonEcsData[];
fieldName: string;
}): string[] | undefined => {
/*
While data _should_ always be defined
There is the potential for race conditions where a component using this function
is still visible in the UI, while the data has since been removed.
To cover all scenarios where this happens we'll check for the presence of data here
*/
if (!data || data.length === 0) return undefined;
const item = data.find((d) => d.field === fieldName);
if (item != null && item.value != null) {
return item.value;
}
return undefined;
};

export const useGetMappedNonEcsValue = ({
data,
fieldName,
}: {
data?: TimelineNonEcsData[];
fieldName: string;
}): string[] | undefined => {
return useMemo(() => getMappedNonEcsValue({ data, fieldName }), [data, fieldName]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
} from '@kbn/lists-plugin/common/constants.mock';
import { of } from 'rxjs';
import { timelineDefaults } from '../../../timelines/store/defaults';
import { defaultUdtHeaders } from '../../../timelines/components/timeline/unified_components/default_headers';
import { defaultUdtHeaders } from '../../../timelines/components/timeline/body/column_headers/default_headers';

jest.mock('../../../timelines/containers/api', () => ({
getTimelineTemplate: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { getField } from '../../../../helpers';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { useStartTransaction } from '../../../../common/lib/apm/use_start_transaction';
import { ALERTS_ACTIONS } from '../../../../common/lib/apm/user_actions';
import { defaultUdtHeaders } from '../../../../timelines/components/timeline/unified_components/default_headers';
import { defaultUdtHeaders } from '../../../../timelines/components/timeline/body/column_headers/default_headers';

interface UseInvestigateInTimelineActionProps {
ecsRowData?: Ecs | Ecs[] | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import type { EuiDataGridCellValueElementProps } from '@elastic/eui';
import { EuiLink } from '@elastic/eui';
import { ALERT_DURATION, ALERT_REASON, ALERT_SEVERITY, ALERT_STATUS } from '@kbn/rule-data-utils';

import { useGetMappedNonEcsValue } from '../../../../common/utils/get_mapped_non_ecs_value';
import { TruncatableText } from '../../../../common/components/truncatable_text';
import { Severity } from '../../../components/severity';
import { useGetMappedNonEcsValue } from '../../../../timelines/components/timeline/body/data_driven_columns';
import type { CellValueElementProps } from '../../../../timelines/components/timeline/cell_rendering';
import { DefaultCellRenderer } from '../../../../timelines/components/timeline/cell_rendering/default_cell_renderer';
import { Status } from '../../../components/status';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type { EuiDataGridCellValueElementProps } from '@elastic/eui';
import { ALERT_SEVERITY, ALERT_REASON } from '@kbn/rule-data-utils';
import React from 'react';

import { useGetMappedNonEcsValue } from '../../../../common/utils/get_mapped_non_ecs_value';
import { DefaultDraggable } from '../../../../common/components/draggables';
import { TruncatableText } from '../../../../common/components/truncatable_text';
import { Severity } from '../../../components/severity';
import { useGetMappedNonEcsValue } from '../../../../timelines/components/timeline/body/data_driven_columns';
import type { CellValueElementProps } from '../../../../timelines/components/timeline/cell_rendering';
import { DefaultCellRenderer } from '../../../../timelines/components/timeline/cell_rendering/default_cell_renderer';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import {
useGlobalFullScreen,
useTimelineFullScreen,
} from '../../../common/containers/use_full_screen';
import { isFullScreen } from '../timeline/body/column_headers';
import { inputsActions } from '../../../common/store/actions';
import { Resolver } from '../../../resolver/view';
import { useTimelineDataFilters } from '../../containers/use_timeline_data_filters';
import { timelineSelectors } from '../../store';
import { timelineDefaults } from '../../store/defaults';
import { isFullScreen } from '../timeline/helpers';

const SESSION_VIEW_FULL_SCREEN = 'sessionViewFullScreen';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TimelineId } from '../../../../../common/types';
import { timelineActions } from '../../../store';
import { TestProviders } from '../../../../common/mock';
import { RowRendererValues } from '../../../../../common/api/timeline';
import { defaultUdtHeaders } from '../../timeline/unified_components/default_headers';
import { defaultUdtHeaders } from '../../timeline/body/column_headers/default_headers';

jest.mock('../../../../common/components/discover_in_timeline/use_discover_in_timeline_context');
jest.mock('../../../../common/hooks/use_selector');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TimelineTypeEnum,
} from '../../../../common/api/timeline';
import { TestProviders } from '../../../common/mock';
import { defaultUdtHeaders } from '../timeline/unified_components/default_headers';
import { defaultUdtHeaders } from '../timeline/body/column_headers/default_headers';

jest.mock('../../../common/components/discover_in_timeline/use_discover_in_timeline_context');
jest.mock('../../../common/hooks/use_selector');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
mockTemplate as mockSelectedTemplate,
} from './__mocks__';
import { resolveTimeline } from '../../containers/api';
import { defaultUdtHeaders } from '../timeline/unified_components/default_headers';
import { defaultUdtHeaders } from '../timeline/body/column_headers/default_headers';

jest.mock('../../../common/hooks/use_experimental_features');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import { useUpdateTimeline } from './use_update_timeline';
import type { TimelineModel } from '../../store/model';
import { timelineDefaults } from '../../store/defaults';

import { defaultColumnHeaderType } from '../timeline/body/column_headers/default_headers';
import {
defaultColumnHeaderType,
defaultUdtHeaders,
} from '../timeline/body/column_headers/default_headers';

import type { OpenTimelineResult, TimelineErrorCallback } from './types';
import { IS_OPERATOR } from '../timeline/data_providers/data_provider';
Expand All @@ -46,7 +49,6 @@ import {
DEFAULT_TO_MOMENT,
} from '../../../common/utils/default_date_settings';
import { resolveTimeline } from '../../containers/api';
import { defaultUdtHeaders } from '../timeline/unified_components/default_headers';
import { timelineActions } from '../../store';

export const OPEN_TIMELINE_CLASS_NAME = 'open-timeline';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { SourcererScopeName } from '../../../sourcerer/store/model';
import { useSourcererDataView } from '../../../sourcerer/containers';
import { useStartTransaction } from '../../../common/lib/apm/use_start_transaction';
import { TIMELINE_ACTIONS } from '../../../common/lib/apm/user_actions';
import { defaultUdtHeaders } from '../timeline/unified_components/default_headers';
import { defaultUdtHeaders } from '../timeline/body/column_headers/default_headers';
import { timelineDefaults } from '../../store/defaults';

interface OwnProps<TCache = object> {
Expand Down
Loading

0 comments on commit f81ee32

Please sign in to comment.