From 18c5a901ce2de07addb4f2229b0f3ac58cda3cdb Mon Sep 17 00:00:00 2001 From: Charlotte Alexandra Wilson Date: Wed, 26 Feb 2025 13:29:21 +0000 Subject: [PATCH] [refactoring] Distinguish User Controls from Risk Engine in DashboardEnablementPanel (#212441) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This PR refactors naming and logic in EntityStoreEnablementModal to improve readability and better distinguish between: 1. Feature enablement state – Whether Risk Score or Entity Store is actually enabled. 2. User-selected state – Whether the user has checked the corresponding toggle. #### Changes - Renamed disabled → canToggle to clearly represent UI interaction. - Renamed enablements → userSelectedEnablements to reflect user-selected toggle states, not feature enablement. - Refactored shouldAllowEnablement logic for clarity and correctness: - If riskScore is enabled, return whether the user has enabled entityStore. - If entityStore is enabled, return whether the user has enabled riskScore. - Otherwise, return true if either toggle is selected. - Updated corresponding tests to reflect naming and logic changes. ## Testing/Validation Manually tested the toggling behaviour still works as before and modal still shows warning, and disables the "enable" button when there are no available options selected. ### Validation Video https://github.com/user-attachments/assets/0f2a3f59-e2a0-4c8b-a350-70a9573a8566 (cherry picked from commit 874cee2c575efe75ede0702ac243855abe008a69) --- .../components/dashboard_enablement_panel.tsx | 4 ++-- .../components/enablement_modal.test.tsx | 12 +++++------ .../components/enablement_modal.tsx | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_enablement_panel.tsx b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_enablement_panel.tsx index 9f5a70b3f7332..984c00fac579b 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_enablement_panel.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_enablement_panel.tsx @@ -223,11 +223,11 @@ export const EnablementPanel: React.FC = ({ state } toggle={(visible) => setModalState({ visible })} enableStore={enableEntityStore} riskScore={{ - disabled: riskEngineStatus !== RiskEngineStatusEnum.NOT_INSTALLED, + canToggle: riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED, checked: riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED, }} entityStore={{ - disabled: entityStoreStatus === 'running', + canToggle: entityStoreStatus !== 'running', checked: entityStoreStatus === 'not_installed', }} /> diff --git a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx index 7b51958df18b3..80a16e18ef6c8 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx @@ -35,8 +35,8 @@ const defaultProps = { visible: true, toggle: mockToggle, enableStore: mockEnableStore, - riskScore: { disabled: false, checked: false }, - entityStore: { disabled: false, checked: false }, + riskScore: { canToggle: false, checked: false }, + entityStore: { canToggle: false, checked: false }, }; const allEntityEnginePrivileges: EntityAnalyticsPrivileges = { @@ -149,8 +149,8 @@ describe('EntityStoreEnablementModal', () => { it('should show proceed warning when riskScore is enabled but entityStore is disabled and unchecked', () => { renderComponent({ ...defaultProps, - riskScore: { disabled: false, checked: false }, // Enabled & Checked - entityStore: { disabled: true, checked: false }, // Disabled & Unchecked + riskScore: { canToggle: false, checked: false }, // Enabled & Checked + entityStore: { canToggle: true, checked: false }, // Disabled & Unchecked }); expect(screen.getByText('Please enable at least one option to proceed.')).toBeInTheDocument(); }); @@ -158,8 +158,8 @@ describe('EntityStoreEnablementModal', () => { it('should show proceed warning when entityStore is enabled but riskScore is disabled and unchecked', () => { renderComponent({ ...defaultProps, - entityStore: { disabled: false, checked: false }, // Enabled & Checked - riskScore: { disabled: true, checked: false }, // Disabled & Unchecked + entityStore: { canToggle: false, checked: false }, // Enabled & Checked + riskScore: { canToggle: true, checked: false }, // Disabled & Unchecked }); expect(screen.getByText('Please enable at least one option to proceed.')).toBeInTheDocument(); }); diff --git a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx index e104c6a76bb88..9347273ce5590 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx @@ -45,11 +45,11 @@ interface EntityStoreEnablementModalProps { toggle: (visible: boolean) => void; enableStore: (enablements: Enablements) => () => void; riskScore: { - disabled?: boolean; + canToggle?: boolean; checked?: boolean; }; entityStore: { - disabled?: boolean; + canToggle?: boolean; checked?: boolean; }; } @@ -57,15 +57,15 @@ interface EntityStoreEnablementModalProps { const shouldAllowEnablement = ( riskScoreEnabled: boolean, entityStoreEnabled: boolean, - enablements: Enablements + userHasEnabled: Enablements ) => { if (riskScoreEnabled) { - return enablements.entityStore; + return userHasEnabled.entityStore; } if (entityStoreEnabled) { - return enablements.riskScore; + return userHasEnabled.riskScore; } - return enablements.riskScore || enablements.entityStore; + return userHasEnabled.riskScore || userHasEnabled.entityStore; }; export const EntityStoreEnablementModal: React.FC = ({ @@ -85,8 +85,8 @@ export const EntityStoreEnablementModal: React.FC setEnablements((prev) => ({ ...prev, riskScore: !prev.riskScore }))} @@ -156,7 +156,7 @@ export const EntityStoreEnablementModal: React.FC