-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Entity Analytics][Entity Store] Refactor enablement UI #199762
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
Merged
tiansivive
merged 12 commits into
elastic:main
from
tiansivive:ea-store-refactor-enablement-ui
Nov 28, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a6f9595
simplifying enablement via new APIs
tiansivive 019392a
finish UI rework
tiansivive 4bd0ecb
add cypress tests
tiansivive 2c8485f
fix cypress
tiansivive fca713a
revert cypress config
tiansivive 9c911b3
review
tiansivive 631726e
review: cypress test fixes
tiansivive b6b43b9
fix config
tiansivive 0119b96
Merge branch 'main' into ea-store-refactor-enablement-ui
tiansivive 155be15
Merge branch 'main' into ea-store-refactor-enablement-ui
tiansivive fdde799
Fix cypress test error
machadoum 3175ed2
Merge branch 'main' into ea-store-refactor-enablement-ui
machadoum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
198 changes: 198 additions & 0 deletions
198
...public/entity_analytics/components/entity_store/components/dashboard_enablement_panel.tsx
This file contains hidden or 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,198 @@ | ||
| /* | ||
| * 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 React, { useCallback, useState } from 'react'; | ||
| import { | ||
| EuiCallOut, | ||
| EuiPanel, | ||
| EuiEmptyPrompt, | ||
| EuiLoadingLogo, | ||
| EuiToolTip, | ||
| EuiButton, | ||
| EuiImage, | ||
| } from '@elastic/eui'; | ||
| import { FormattedMessage } from '@kbn/i18n-react'; | ||
| import type { UseQueryResult } from '@tanstack/react-query'; | ||
| import type { GetEntityStoreStatusResponse } from '../../../../../common/api/entity_analytics/entity_store/enablement.gen'; | ||
| import type { StoreStatus } from '../../../../../common/api/entity_analytics'; | ||
| import { RiskEngineStatusEnum } from '../../../../../common/api/entity_analytics'; | ||
| import { useInitRiskEngineMutation } from '../../../api/hooks/use_init_risk_engine_mutation'; | ||
| import { useEnableEntityStoreMutation } from '../hooks/use_entity_store'; | ||
| import { | ||
| ENABLEMENT_INITIALIZING_RISK_ENGINE, | ||
| ENABLEMENT_INITIALIZING_ENTITY_STORE, | ||
| ENABLE_ALL_TITLE, | ||
| ENABLEMENT_DESCRIPTION_BOTH, | ||
| ENABLE_RISK_SCORE_TITLE, | ||
| ENABLEMENT_DESCRIPTION_RISK_ENGINE_ONLY, | ||
| ENABLE_ENTITY_STORE_TITLE, | ||
| ENABLEMENT_DESCRIPTION_ENTITY_STORE_ONLY, | ||
| } from '../translations'; | ||
| import type { Enablements } from './enablement_modal'; | ||
| import { EntityStoreEnablementModal } from './enablement_modal'; | ||
| import dashboardEnableImg from '../../../images/entity_store_dashboard.png'; | ||
| import type { RiskEngineStatus } from '../../../api/hooks/use_risk_engine_status'; | ||
|
|
||
| interface EnableEntityStorePanelProps { | ||
| state: { | ||
| riskEngine: UseQueryResult<RiskEngineStatus>; | ||
| entityStore: UseQueryResult<GetEntityStoreStatusResponse>; | ||
| }; | ||
| } | ||
|
|
||
| export const EnablementPanel: React.FC<EnableEntityStorePanelProps> = ({ state }) => { | ||
| const riskEngineStatus = state.riskEngine.data?.risk_engine_status; | ||
| const entityStoreStatus = state.entityStore.data?.status; | ||
|
|
||
| const [modal, setModalState] = useState({ visible: false }); | ||
| const [riskEngineInitializing, setRiskEngineInitializing] = useState(false); | ||
|
|
||
| const initRiskEngine = useInitRiskEngineMutation(); | ||
| const storeEnablement = useEnableEntityStoreMutation(); | ||
|
|
||
| const enableEntityStore = useCallback( | ||
| (enable: Enablements) => () => { | ||
| if (enable.riskScore) { | ||
| const options = { | ||
| onSuccess: () => { | ||
| setRiskEngineInitializing(false); | ||
| if (enable.entityStore) { | ||
| storeEnablement.mutate(); | ||
| } | ||
| }, | ||
| }; | ||
| setRiskEngineInitializing(true); | ||
| initRiskEngine.mutate(undefined, options); | ||
| setModalState({ visible: false }); | ||
| return; | ||
| } | ||
|
|
||
| if (enable.entityStore) { | ||
| storeEnablement.mutate(); | ||
| setModalState({ visible: false }); | ||
| } | ||
| }, | ||
| [storeEnablement, initRiskEngine] | ||
| ); | ||
|
|
||
| if (storeEnablement.error) { | ||
| return ( | ||
| <> | ||
| <EuiCallOut | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.securitySolution.entityAnalytics.entityStore.enablement.mutation.errorTitle" | ||
| defaultMessage={'There was a problem initializing the entity store'} | ||
| /> | ||
| } | ||
| color="danger" | ||
| iconType="error" | ||
| > | ||
| <p>{storeEnablement.error.body.message}</p> | ||
| </EuiCallOut> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| if (riskEngineInitializing) { | ||
| return ( | ||
| <EuiPanel hasBorder data-test-subj="riskEngineInitializingPanel"> | ||
| <EuiEmptyPrompt | ||
| icon={<EuiLoadingLogo logo="logoElastic" size="xl" />} | ||
| title={<h2>{ENABLEMENT_INITIALIZING_RISK_ENGINE}</h2>} | ||
| /> | ||
| </EuiPanel> | ||
| ); | ||
| } | ||
|
|
||
| if (entityStoreStatus === 'installing' || storeEnablement.isLoading) { | ||
| return ( | ||
| <EuiPanel hasBorder data-test-subj="entityStoreInitializingPanel"> | ||
| <EuiEmptyPrompt | ||
| icon={<EuiLoadingLogo logo="logoElastic" size="xl" />} | ||
| title={<h2>{ENABLEMENT_INITIALIZING_ENTITY_STORE}</h2>} | ||
| body={ | ||
| <p> | ||
| <FormattedMessage | ||
| id="xpack.securitySolution.entityAnalytics.entityStore.enablement.initializing.description" | ||
| defaultMessage="This can take up to 5 minutes." | ||
| /> | ||
| </p> | ||
| } | ||
| /> | ||
| </EuiPanel> | ||
| ); | ||
| } | ||
|
|
||
| if ( | ||
| riskEngineStatus !== RiskEngineStatusEnum.NOT_INSTALLED && | ||
| (entityStoreStatus === 'running' || entityStoreStatus === 'stopped') | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| const [title, body] = getEnablementTexts(entityStoreStatus, riskEngineStatus); | ||
| return ( | ||
| <> | ||
| <EuiEmptyPrompt | ||
| css={{ minWidth: '100%' }} | ||
| hasBorder | ||
| layout="horizontal" | ||
| title={<h2>{title}</h2>} | ||
tiansivive marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| body={<p>{body}</p>} | ||
| actions={ | ||
| <EuiToolTip content={title}> | ||
| <EuiButton | ||
| color="primary" | ||
| fill | ||
| onClick={() => setModalState({ visible: true })} | ||
| data-test-subj={`entityStoreEnablementButton`} | ||
| > | ||
| <FormattedMessage | ||
| id="xpack.securitySolution.entityAnalytics.entityStore.enablement.enableButton" | ||
| defaultMessage="Enable" | ||
| /> | ||
| </EuiButton> | ||
| </EuiToolTip> | ||
| } | ||
| icon={<EuiImage size="l" hasShadow src={dashboardEnableImg} alt={title} />} | ||
| data-test-subj="entityStoreEnablementPanel" | ||
| /> | ||
|
|
||
| <EntityStoreEnablementModal | ||
| visible={modal.visible} | ||
| toggle={(visible) => setModalState({ visible })} | ||
| enableStore={enableEntityStore} | ||
| riskScore={{ | ||
tiansivive marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| disabled: riskEngineStatus !== RiskEngineStatusEnum.NOT_INSTALLED, | ||
| checked: riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED, | ||
| }} | ||
| entityStore={{ | ||
| disabled: entityStoreStatus === 'running', | ||
| checked: entityStoreStatus === 'not_installed', | ||
| }} | ||
| /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const getEnablementTexts = ( | ||
| entityStoreStatus?: StoreStatus, | ||
| riskEngineStatus?: RiskEngineStatus['risk_engine_status'] | ||
| ): [string, string] => { | ||
| if ( | ||
| (entityStoreStatus === 'not_installed' || entityStoreStatus === 'stopped') && | ||
| riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED | ||
| ) { | ||
| return [ENABLE_ALL_TITLE, ENABLEMENT_DESCRIPTION_BOTH]; | ||
| } | ||
|
|
||
| if (riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED) { | ||
| return [ENABLE_RISK_SCORE_TITLE, ENABLEMENT_DESCRIPTION_RISK_ENGINE_ONLY]; | ||
| } | ||
|
|
||
| return [ENABLE_ENTITY_STORE_TITLE, ENABLEMENT_DESCRIPTION_ENTITY_STORE_ONLY]; | ||
| }; | ||
95 changes: 95 additions & 0 deletions
95
...lic/entity_analytics/components/entity_store/components/dashboard_entity_store_panels.tsx
This file contains hidden or 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,95 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
| import { | ||
| EuiEmptyPrompt, | ||
| EuiLoadingSpinner, | ||
| EuiFlexItem, | ||
| EuiFlexGroup, | ||
| EuiPanel, | ||
| EuiCallOut, | ||
| } from '@elastic/eui'; | ||
|
|
||
| import { FormattedMessage } from '@kbn/i18n-react'; | ||
| import { RiskEngineStatusEnum } from '../../../../../common/api/entity_analytics'; | ||
| import { RiskScoreEntity } from '../../../../../common/search_strategy'; | ||
| import { EntitiesList } from '../entities_list'; | ||
| import { useEntityStoreStatus } from '../hooks/use_entity_store'; | ||
| import { EntityAnalyticsRiskScores } from '../../entity_analytics_risk_score'; | ||
| import { useRiskEngineStatus } from '../../../api/hooks/use_risk_engine_status'; | ||
|
|
||
| import { EnablementPanel } from './dashboard_enablement_panel'; | ||
|
|
||
| const EntityStoreDashboardPanelsComponent = () => { | ||
| const riskEngineStatus = useRiskEngineStatus(); | ||
| const storeStatusQuery = useEntityStoreStatus({}); | ||
|
|
||
| const callouts = (storeStatusQuery.data?.engines ?? []) | ||
| .filter((engine) => engine.status === 'error') | ||
| .map((engine) => { | ||
| const err = engine.error as { | ||
| message: string; | ||
| }; | ||
| return ( | ||
| <EuiCallOut | ||
| title={ | ||
| <FormattedMessage | ||
| id="xpack.securitySolution.entityAnalytics.entityStore.enablement.errors.title" | ||
| defaultMessage={'An error occurred during entity store resource initialization'} | ||
| /> | ||
| } | ||
| color="danger" | ||
| iconType="error" | ||
| > | ||
| <p>{err?.message}</p> | ||
| </EuiCallOut> | ||
| ); | ||
| }); | ||
|
|
||
| if (storeStatusQuery.status === 'loading') { | ||
| return ( | ||
| <EuiPanel hasBorder> | ||
| <EuiEmptyPrompt icon={<EuiLoadingSpinner size="xl" />} /> | ||
| </EuiPanel> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <EuiFlexGroup direction="column" data-test-subj="entityStorePanelsGroup"> | ||
| {storeStatusQuery.status === 'error' ? ( | ||
| callouts | ||
| ) : ( | ||
| <EnablementPanel | ||
| state={{ | ||
| riskEngine: riskEngineStatus, | ||
| entityStore: storeStatusQuery, | ||
| }} | ||
| /> | ||
| )} | ||
|
|
||
| {riskEngineStatus.data?.risk_engine_status !== RiskEngineStatusEnum.NOT_INSTALLED && ( | ||
| <> | ||
| <EuiFlexItem> | ||
| <EntityAnalyticsRiskScores riskEntity={RiskScoreEntity.user} /> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem> | ||
| <EntityAnalyticsRiskScores riskEntity={RiskScoreEntity.host} /> | ||
| </EuiFlexItem> | ||
| </> | ||
| )} | ||
| {storeStatusQuery.data?.status !== 'not_installed' && | ||
| storeStatusQuery.data?.status !== 'installing' && ( | ||
| <EuiFlexItem data-test-subj="entitiesListPanel"> | ||
| <EntitiesList /> | ||
| </EuiFlexItem> | ||
| )} | ||
| </EuiFlexGroup> | ||
| ); | ||
| }; | ||
|
|
||
| export const EntityStoreDashboardPanels = React.memo(EntityStoreDashboardPanelsComponent); | ||
| EntityStoreDashboardPanels.displayName = 'EntityStoreDashboardPanels'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.