From 356a5b4d436fd5819eecd652870345b19f852578 Mon Sep 17 00:00:00 2001 From: Pablo Machado Date: Thu, 7 Dec 2023 14:36:03 +0100 Subject: [PATCH] [SecuritySolutions] Code review improvements for PR 8038 (#172650) ## Summary * Code review typescript improvements * Remove the tooltip that increased bundle size by 2MB --- .../users/managed_details/index.ts | 2 +- .../entity_details/user_right/header.test.tsx | 6 +---- .../new_user_detail/__mocks__/index.ts | 1 - .../side_panel/new_user_detail/columns.tsx | 20 ++++++-------- .../new_user_detail/hooks/use_managed_user.ts | 6 +---- .../new_user_detail/managed_user.test.tsx | 1 - .../new_user_detail/managed_user.tsx | 2 +- .../factory/users/managed_details/index.ts | 27 +++++-------------- 8 files changed, 18 insertions(+), 47 deletions(-) diff --git a/x-pack/plugins/security_solution/common/search_strategy/security_solution/users/managed_details/index.ts b/x-pack/plugins/security_solution/common/search_strategy/security_solution/users/managed_details/index.ts index 3ab346fc7c69..49fd729c3a0d 100644 --- a/x-pack/plugins/security_solution/common/search_strategy/security_solution/users/managed_details/index.ts +++ b/x-pack/plugins/security_solution/common/search_strategy/security_solution/users/managed_details/index.ts @@ -25,6 +25,6 @@ export interface ManagedUserHit { fields?: ManagedUserFields; } -export type ManagedUserHits = Record; +export type ManagedUserHits = Partial>; export type ManagedUserFields = Record; diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/header.test.tsx b/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/header.test.tsx index d502e8e2d06d..2f1ada7447dd 100644 --- a/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/header.test.tsx +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/header.test.tsx @@ -75,7 +75,6 @@ describe('UserDetailsContent', () => { '@timestamp': [futureDay], }, }, - [ManagedUserDatasetKey.OKTA]: undefined, }, }, }} @@ -126,10 +125,7 @@ describe('UserDetailsContent', () => { ...mockProps, managedUser: { ...mockManagedUserData, - data: { - [ManagedUserDatasetKey.ENTRA]: undefined, - [ManagedUserDatasetKey.OKTA]: undefined, - }, + data: {}, }, }} /> diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/__mocks__/index.ts b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/__mocks__/index.ts index 2bd47cd19f9e..65c6bd974b83 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/__mocks__/index.ts +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/__mocks__/index.ts @@ -113,7 +113,6 @@ export const managedUserDetails: ManagedUserHits = { _index: 'test-index', _id: '123-test', }, - [ManagedUserDatasetKey.OKTA]: undefined, }; export const mockManagedUserData: ManagedUserData = { diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/columns.tsx b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/columns.tsx index 6fd22361c55c..8c4f31ea1214 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/columns.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/columns.tsx @@ -10,9 +10,7 @@ import React, { useCallback } from 'react'; import { head } from 'lodash/fp'; import { euiLightVars } from '@kbn/ui-theme'; import type { EuiBasicTableColumn } from '@elastic/eui'; -import { EuiToolTip } from '@elastic/eui'; import { useDispatch } from 'react-redux'; -import { EcsFlat } from '@kbn/ecs'; import { SourcererScopeName } from '../../../../common/store/sourcerer/model'; import { DefaultFieldRenderer } from '../../field_renderers/field_renderers'; import type { @@ -36,16 +34,14 @@ const fieldColumn: EuiBasicTableColumn = { name: i18n.FIELD_COLUMN_TITLE, field: 'label', render: (label: string, { field }) => ( - - - {label ?? field} - - + + {label ?? field} + ), }; diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user.ts b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user.ts index f8bfd378464c..61e8b7e7e961 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user.ts +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user.ts @@ -7,7 +7,6 @@ import { useEffect, useMemo } from 'react'; import { useInstalledIntegrations } from '../../../../../detections/components/rules/related_integrations/use_installed_integrations'; -import { ManagedUserDatasetKey } from '../../../../../../common/search_strategy/security_solution/users/managed_details'; import { UsersQueries } from '../../../../../../common/search_strategy'; import { useSpaceId } from '../../../../../common/hooks/use_space_id'; import { useSearchStrategy } from '../../../../../common/containers/use_search_strategy'; @@ -37,10 +36,7 @@ export const useManagedUser = (userName: string, observedUser: ObserverUser) => } = useSearchStrategy({ factoryQueryType: UsersQueries.managedDetails, initialResult: { - users: { - [ManagedUserDatasetKey.ENTRA]: undefined, - [ManagedUserDatasetKey.OKTA]: undefined, - }, + users: {}, }, errorMessage: i18n.FAIL_MANAGED_USER, }); diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.test.tsx index 02a7721d2224..70363853b910 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.test.tsx @@ -108,7 +108,6 @@ describe('ManagedUser', () => { managedUser: { ...mockManagedUserData, data: { - [ManagedUserDatasetKey.ENTRA]: undefined, [ManagedUserDatasetKey.OKTA]: { fields: mockOktaUserFields, _index: '123', diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.tsx b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.tsx index 42d059356081..35a9a7801198 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/managed_user.tsx @@ -136,7 +136,7 @@ export const ManagedUser = ({ managedUser={oktaManagedUser.fields} indexName={oktaManagedUser._index} eventId={oktaManagedUser._id} - tableType={UserAssetTableType.assetEntra} + tableType={UserAssetTableType.assetOkta} > ; + latest_hit: SearchResponse; } export const managedUserDetails: SecuritySolutionFactory = { @@ -43,24 +42,10 @@ export const managedUserDetails: SecuritySolutionFactory { - acc[bucket.key] = bucket.latest_hit.hits.hits[0] as unknown as ManagedUserHit; - return acc; - }, - {} as ManagedUserHits - ); - - if (buckets.length === 0) { - return { - ...response, - inspect, - users: { - [ManagedUserDatasetKey.ENTRA]: undefined, - [ManagedUserDatasetKey.OKTA]: undefined, - }, - }; - } + const managedUsers = buckets.reduce((acc, bucket) => { + acc[bucket.key] = bucket.latest_hit.hits.hits[0]; + return acc; + }, {}); return { ...response,