-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
027f843
commit f81ee32
Showing
92 changed files
with
212 additions
and
7,104 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
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/security_solution/public/common/utils/get_mapped_non_ecs_value.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,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']); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/security_solution/public/common/utils/get_mapped_non_ecs_value.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,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]); | ||
}; |
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
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
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
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
Oops, something went wrong.