From 04684ff866f385cb5baf1ce122afebd9b090a087 Mon Sep 17 00:00:00 2001 From: Charlotte Alexandra Wilson Date: Wed, 26 Feb 2025 13:29:21 +0000 Subject: [PATCH 1/3] =?UTF-8?q?[refactoring]=20Distinguish=20User=20Contro?= =?UTF-8?q?ls=20from=20Risk=20Engine=20in=20DashboardEnablementPanel=20=20?= =?UTF-8?q?(#212441)=20This=20PR=20refactors=20naming=20and=20logic=20in?= =?UTF-8?q?=20EntityStoreEnablementModal=20to=20improve=20readability=20an?= =?UTF-8?q?d=20better=20distinguish=20between:=201.=20Feature=20enablement?= =?UTF-8?q?=20state=20=E2=80=93=20Whether=20Risk=20Score=20or=20Entity=20S?= =?UTF-8?q?tore=20is=20actually=20enabled.=202.=20User-selected=20state=20?= =?UTF-8?q?=E2=80=93=20Whether=20the=20user=20has=20checked=20the=20corres?= =?UTF-8?q?ponding=20toggle.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. 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. https://github.com/user-attachments/assets/0f2a3f59-e2a0-4c8b-a350-70a9573a8566 (cherry picked from commit 874cee2c575efe75ede0702ac243855abe008a69) --- .../components/enablement_modal.test.tsx | 12 +++++------ .../components/enablement_modal.tsx | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx index 888ed8403a4fd..5c5815e239799 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx +++ b/x-pack/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/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx index 5902182f6c89a..d18aaa9c835cf 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.tsx @@ -48,11 +48,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; }; } @@ -60,15 +60,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 = ({ @@ -88,8 +88,8 @@ export const EntityStoreEnablementModal: React.FC setEnablements((prev) => ({ ...prev, riskScore: !prev.riskScore }))} @@ -158,7 +158,7 @@ export const EntityStoreEnablementModal: React.FC From 6e06a129bba55444b7c3313db8b68549017b1127 Mon Sep 17 00:00:00 2001 From: Charlotte Alexandra Wilson Date: Wed, 26 Feb 2025 17:21:11 +0000 Subject: [PATCH 2/3] [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 --- .../entity_store/components/dashboard_panels.tsx | 7 +++++-- .../entity_store/components/enablement_modal.test.tsx | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx index d70eb9fe34b51..3d0d2024fcc2f 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx @@ -236,9 +236,12 @@ const EntityStoreDashboardPanelsComponent = () => { visible={modal.visible} toggle={(visible) => setModalState({ visible })} enableStore={enableEntityStore} - riskScore={{ disabled: isRiskScoreAvailable, checked: !isRiskScoreAvailable }} + riskScore={{ + canToggle: riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED, + checked: riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED, + }} entityStore={{ - disabled: entityStore.status === 'enabled', + canToggle: entityStore.status === 'enabled', checked: entityStore.status !== 'enabled', }} /> diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx index 5c5815e239799..1e33f9443e67d 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/enablement_modal.test.tsx @@ -149,8 +149,8 @@ describe('EntityStoreEnablementModal', () => { it('should show proceed warning when riskScore is enabled but entityStore is disabled and unchecked', () => { renderComponent({ ...defaultProps, - riskScore: { canToggle: false, checked: false }, // Enabled & Checked - entityStore: { canToggle: true, checked: false }, // Disabled & Unchecked + riskScore: { canToggle: false, checked: false }, + entityStore: { canToggle: true, checked: false }, }); 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: { canToggle: false, checked: false }, // Enabled & Checked - riskScore: { canToggle: true, checked: false }, // Disabled & Unchecked + entityStore: { canToggle: false, checked: false }, + riskScore: { canToggle: true, checked: false }, }); expect(screen.getByText('Please enable at least one option to proceed.')).toBeInTheDocument(); }); From 92e0acfe0ed1d0748bc8f4d75006580c9a603c71 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Wed, 26 Feb 2025 18:10:30 +0000 Subject: [PATCH 3/3] fix merge issues and logic --- .../entity_store/components/dashboard_panels.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx index 3d0d2024fcc2f..c4e7ecc8ab9d9 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/dashboard_panels.tsx @@ -237,12 +237,12 @@ const EntityStoreDashboardPanelsComponent = () => { toggle={(visible) => setModalState({ visible })} enableStore={enableEntityStore} riskScore={{ - canToggle: riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED, - checked: riskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED, + canToggle: !isRiskScoreAvailable, + checked: true, }} entityStore={{ - canToggle: entityStore.status === 'enabled', - checked: entityStore.status !== 'enabled', + canToggle: entityStore.status !== 'enabled', + checked: true, }} />