-
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.
[Security Solution] Asset criticality UI (#173512)
This PR adds the UI to assign asset criticality in the old host flyout. [#8086](elastic/security-team#8086)
- Loading branch information
1 parent
392d53c
commit 121fb3a
Showing
12 changed files
with
622 additions
and
3 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
207 changes: 207 additions & 0 deletions
207
...ution/public/entity_analytics/components/asset_criticality/asset_criticality_selector.tsx
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,207 @@ | ||
/* | ||
* 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 { EuiSuperSelectOption } from '@elastic/eui'; | ||
|
||
import { | ||
EuiAccordion, | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHealth, | ||
EuiLoadingSpinner, | ||
EuiModal, | ||
EuiModalBody, | ||
EuiModalFooter, | ||
EuiModalHeader, | ||
EuiModalHeaderTitle, | ||
EuiSuperSelect, | ||
EuiText, | ||
EuiHorizontalRule, | ||
} from '@elastic/eui'; | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
import { | ||
CRITICALITY_LEVEL_DESCRIPTION, | ||
CRITICALITY_LEVEL_TITLE, | ||
PICK_ASSET_CRITICALITY, | ||
} from './translations'; | ||
import type { Entity, ModalState, State } from './use_asset_criticality'; | ||
import { useAssetCriticalityData, useCriticalityModal } from './use_asset_criticality'; | ||
import type { CriticalityLevel } from './common'; | ||
import { CRITICALITY_LEVEL_COLOR } from './common'; | ||
|
||
interface Props { | ||
entity: Entity; | ||
} | ||
export const AssetCriticalitySelector: React.FC<Props> = ({ entity }) => { | ||
const modal = useCriticalityModal(); | ||
const criticality = useAssetCriticalityData(entity, modal); | ||
|
||
if (criticality.privileges.isLoading || !criticality.privileges.data?.has_all_required) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiHorizontalRule /> | ||
<EuiAccordion | ||
id="asset-criticality-selector" | ||
buttonContent={ | ||
<FormattedMessage | ||
id="xpack.securitySolution.entityAnalytics.assetCriticality.accordionTitle" | ||
defaultMessage="Asset Criticality" | ||
/> | ||
} | ||
data-test-subj="asset-criticality-selector" | ||
> | ||
{criticality.query.isLoading || criticality.mutation.isLoading ? ( | ||
<EuiLoadingSpinner size="s" /> | ||
) : ( | ||
<EuiFlexGroup | ||
direction="row" | ||
alignItems="center" | ||
justifyContent="spaceBetween" | ||
wrap={false} | ||
> | ||
<EuiFlexItem> | ||
<EuiText size="s"> | ||
{criticality.status === 'update' && criticality.query.data?.criticality_level ? ( | ||
<EuiHealth | ||
data-test-subj="asset-criticality-level" | ||
color={CRITICALITY_LEVEL_COLOR[criticality.query.data.criticality_level]} | ||
> | ||
{CRITICALITY_LEVEL_TITLE[criticality.query.data.criticality_level]} | ||
</EuiHealth> | ||
) : ( | ||
<EuiHealth color="subdued"> | ||
<FormattedMessage | ||
id="xpack.securitySolution.entityAnalytics.assetCriticality.noCriticality" | ||
defaultMessage="No criticality assigned yet" | ||
/> | ||
</EuiHealth> | ||
)} | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem css={{ flexGrow: 'unset' }}> | ||
<EuiButtonEmpty | ||
data-test-subj="asset-criticality-change-btn" | ||
iconType="arrowStart" | ||
iconSide="left" | ||
flush="right" | ||
onClick={() => modal.toggle(true)} | ||
> | ||
{criticality.status === 'update' ? ( | ||
<FormattedMessage | ||
id="xpack.securitySolution.entityAnalytics.assetCriticality.changeButton" | ||
defaultMessage="Change" | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id="xpack.securitySolution.entityAnalytics.assetCriticality.createButton" | ||
defaultMessage="Create" | ||
/> | ||
)} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
)} | ||
</EuiAccordion> | ||
<EuiHorizontalRule /> | ||
{modal.visible ? ( | ||
<AssetCriticalityModal entity={entity} criticality={criticality} modal={modal} /> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
interface ModalProps { | ||
criticality: State; | ||
modal: ModalState; | ||
entity: Entity; | ||
} | ||
const AssetCriticalityModal: React.FC<ModalProps> = ({ criticality, modal, entity }) => { | ||
const [value, setNewValue] = useState<CriticalityLevel>( | ||
criticality.query.data?.criticality_level ?? 'normal' | ||
); | ||
|
||
return ( | ||
<EuiModal onClose={() => modal.toggle(false)}> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle data-test-subj="asset-criticality-modal-title"> | ||
{PICK_ASSET_CRITICALITY} | ||
</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
<EuiModalBody> | ||
<EuiSuperSelect | ||
id={modal.basicSelectId} | ||
options={options} | ||
valueOfSelected={value} | ||
onChange={setNewValue} | ||
aria-label={PICK_ASSET_CRITICALITY} | ||
data-test-subj="asset-criticality-modal-select" | ||
/> | ||
</EuiModalBody> | ||
<EuiModalFooter> | ||
<EuiButtonEmpty onClick={() => modal.toggle(false)}> | ||
<FormattedMessage | ||
id="xpack.securitySolution.entityAnalytics.assetCriticality.cancelButton" | ||
defaultMessage="Cancel" | ||
/> | ||
</EuiButtonEmpty> | ||
|
||
<EuiButton | ||
onClick={() => | ||
criticality.mutation.mutate({ | ||
criticalityLevel: value, | ||
idField: `${entity.type}.name`, | ||
idValue: entity.name, | ||
}) | ||
} | ||
fill | ||
data-test-subj="asset-criticality-modal-save-btn" | ||
> | ||
<FormattedMessage | ||
id="xpack.securitySolution.entityAnalytics.assetCriticality.saveButton" | ||
defaultMessage="Save" | ||
/> | ||
</EuiButton> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
); | ||
}; | ||
|
||
const option = (level: CriticalityLevel): EuiSuperSelectOption<CriticalityLevel> => ({ | ||
value: level, | ||
dropdownDisplay: ( | ||
<EuiHealth | ||
color={CRITICALITY_LEVEL_COLOR[level]} | ||
style={{ lineHeight: 'inherit' }} | ||
data-test-subj="asset-criticality-modal-select-option" | ||
> | ||
<strong>{CRITICALITY_LEVEL_TITLE[level]}</strong> | ||
<EuiText size="s" color="subdued"> | ||
<p>{CRITICALITY_LEVEL_DESCRIPTION[level]}</p> | ||
</EuiText> | ||
</EuiHealth> | ||
), | ||
inputDisplay: ( | ||
<EuiHealth color={CRITICALITY_LEVEL_COLOR[level]} style={{ lineHeight: 'inherit' }}> | ||
{CRITICALITY_LEVEL_TITLE[level]} | ||
</EuiHealth> | ||
), | ||
}); | ||
const options: Array<EuiSuperSelectOption<CriticalityLevel>> = [ | ||
option('normal'), | ||
option('not_important'), | ||
option('important'), | ||
option('very_important'), | ||
]; |
28 changes: 28 additions & 0 deletions
28
.../plugins/security_solution/public/entity_analytics/components/asset_criticality/common.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,28 @@ | ||
/* | ||
* 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 { euiLightVars } from '@kbn/ui-theme'; | ||
import type { AssetCriticalityRecord } from '../../../../common/api/entity_analytics/asset_criticality'; | ||
|
||
export type CriticalityLevel = AssetCriticalityRecord['criticality_level']; | ||
|
||
export const CRITICALITY_LEVEL_COLOR: Record<CriticalityLevel, string> = { | ||
very_important: '#E7664C', | ||
important: '#D6BF57', | ||
normal: '#54B399', | ||
not_important: euiLightVars.euiColorMediumShade, | ||
}; | ||
|
||
// SUGGESTION: @tiansivive Move this to some more general place within Entity Analytics | ||
export const buildCriticalityQueryKeys = (id: string) => { | ||
const ASSET_CRITICALITY = 'ASSET_CRITICALITY'; | ||
const PRIVILEGES = 'PRIVILEGES'; | ||
return { | ||
doc: [ASSET_CRITICALITY, id], | ||
privileges: [ASSET_CRITICALITY, PRIVILEGES, id], | ||
}; | ||
}; |
Oops, something went wrong.