Skip to content

Commit

Permalink
[SecuritySolutions] Code review improvements for PR 8038 (elastic#172650
Browse files Browse the repository at this point in the history
)

## Summary

* Code review typescript improvements
* Remove the tooltip that increased bundle size by 2MB
  • Loading branch information
machadoum authored Dec 7, 2023
1 parent ec81569 commit 356a5b4
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export interface ManagedUserHit {
fields?: ManagedUserFields;
}

export type ManagedUserHits = Record<ManagedUserDatasetKey, ManagedUserHit | undefined>;
export type ManagedUserHits = Partial<Record<ManagedUserDatasetKey, ManagedUserHit>>;

export type ManagedUserFields = Record<string, SearchTypes[]>;
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('UserDetailsContent', () => {
'@timestamp': [futureDay],
},
},
[ManagedUserDatasetKey.OKTA]: undefined,
},
},
}}
Expand Down Expand Up @@ -126,10 +125,7 @@ describe('UserDetailsContent', () => {
...mockProps,
managedUser: {
...mockManagedUserData,
data: {
[ManagedUserDatasetKey.ENTRA]: undefined,
[ManagedUserDatasetKey.OKTA]: undefined,
},
data: {},
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const managedUserDetails: ManagedUserHits = {
_index: 'test-index',
_id: '123-test',
},
[ManagedUserDatasetKey.OKTA]: undefined,
};

export const mockManagedUserData: ManagedUserData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,16 +34,14 @@ const fieldColumn: EuiBasicTableColumn<ObservedUserTable | ManagedUserTable> = {
name: i18n.FIELD_COLUMN_TITLE,
field: 'label',
render: (label: string, { field }) => (
<EuiToolTip content={EcsFlat[field as keyof typeof EcsFlat]?.short ?? field}>
<span
css={css`
font-weight: ${euiLightVars.euiFontWeightMedium};
color: ${euiLightVars.euiTitleColor};
`}
>
{label ?? field}
</span>
</EuiToolTip>
<span
css={css`
font-weight: ${euiLightVars.euiFontWeightMedium};
color: ${euiLightVars.euiTitleColor};
`}
>
{label ?? field}
</span>
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -37,10 +36,7 @@ export const useManagedUser = (userName: string, observedUser: ObserverUser) =>
} = useSearchStrategy<UsersQueries.managedDetails>({
factoryQueryType: UsersQueries.managedDetails,
initialResult: {
users: {
[ManagedUserDatasetKey.ENTRA]: undefined,
[ManagedUserDatasetKey.OKTA]: undefined,
},
users: {},
},
errorMessage: i18n.FAIL_MANAGED_USER,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ describe('ManagedUser', () => {
managedUser: {
...mockManagedUserData,
data: {
[ManagedUserDatasetKey.ENTRA]: undefined,
[ManagedUserDatasetKey.OKTA]: {
fields: mockOktaUserFields,
_index: '123',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const ManagedUser = ({
managedUser={oktaManagedUser.fields}
indexName={oktaManagedUser._index}
eventId={oktaManagedUser._id}
tableType={UserAssetTableType.assetEntra}
tableType={UserAssetTableType.assetOkta}
>
<ManagedUserTable
isDraggable={isDraggable}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ import { buildManagedUserDetailsQuery } from './query.managed_user_details.dsl';
import type { UsersQueries } from '../../../../../../common/search_strategy/security_solution/users';
import type {
ManagedUserHits,
ManagedUserHit,
ManagedUserDetailsStrategyResponse,
ManagedUserFields,
ManagedUserDatasetKey,
} from '../../../../../../common/search_strategy/security_solution/users/managed_details';
import { ManagedUserDatasetKey } from '../../../../../../common/search_strategy/security_solution/users/managed_details';

interface ManagedUserBucket {
key: ManagedUserDatasetKey;
latest_hit: SearchResponse<ManagedUserFields | ManagedUserFields>;
latest_hit: SearchResponse<ManagedUserFields>;
}

export const managedUserDetails: SecuritySolutionFactory<UsersQueries.managedDetails> = {
Expand All @@ -43,24 +42,10 @@ export const managedUserDetails: SecuritySolutionFactory<UsersQueries.managedDet
response.rawResponse
);

const managedUsers: ManagedUserHits = buckets.reduce(
(acc: ManagedUserHits, bucket: ManagedUserBucket) => {
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<ManagedUserHits>((acc, bucket) => {
acc[bucket.key] = bucket.latest_hit.hits.hits[0];
return acc;
}, {});

return {
...response,
Expand Down

0 comments on commit 356a5b4

Please sign in to comment.