Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [Security Solution] Deletes Old Timeline Code (#196243) #199287

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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