mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[8.x] [refactoring] Distinguish User Controls from Risk Engine in DashboardEnablementPanel (#212441) (#212556)
# Backport This will backport the following commits from `main` to `8.x`: - [[refactoring] Distinguish User Controls from Risk Engine in DashboardEnablementPanel (#212441)](https://github.com/elastic/kibana/pull/212441) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Charlotte Alexandra Wilson","email":"CAWilson94@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-02-26T13:29:21Z","message":"[refactoring] Distinguish User Controls from Risk Engine in DashboardEnablementPanel (#212441)\n\n## Summary\nThis PR refactors naming and logic in EntityStoreEnablementModal to\nimprove readability and better distinguish between:\n1. Feature enablement state – Whether Risk Score or Entity Store is\nactually enabled.\n2. User-selected state – Whether the user has checked the corresponding\ntoggle.\n\n#### Changes\n\n- Renamed disabled → canToggle to clearly represent UI interaction.\n- Renamed enablements → userSelectedEnablements to reflect user-selected\ntoggle states, not feature enablement.\n- Refactored shouldAllowEnablement logic for clarity and correctness:\n- If riskScore is enabled, return whether the user has enabled\nentityStore.\n- If entityStore is enabled, return whether the user has enabled\nriskScore.\n - Otherwise, return true if either toggle is selected.\n- Updated corresponding tests to reflect naming and logic changes.\n\n## Testing/Validation\nManually tested the toggling behaviour still works as before and modal\nstill shows warning, and disables the \"enable\" button when there are no\navailable options selected.\n\n### Validation Video\n\n\nhttps://github.com/user-attachments/assets/0f2a3f59-e2a0-4c8b-a350-70a9573a8566","sha":"874cee2c575efe75ede0702ac243855abe008a69","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["refactoring","release_note:skip","v9.0.0","Theme: entity_analytics","Team:Entity Analytics","backport:version","v8.17.0","v8.18.0","v9.1.0","v8.19.0"],"title":"[refactoring] Distinguish User Controls from Risk Engine in DashboardEnablementPanel ","number":212441,"url":"https://github.com/elastic/kibana/pull/212441","mergeCommit":{"message":"[refactoring] Distinguish User Controls from Risk Engine in DashboardEnablementPanel (#212441)\n\n## Summary\nThis PR refactors naming and logic in EntityStoreEnablementModal to\nimprove readability and better distinguish between:\n1. Feature enablement state – Whether Risk Score or Entity Store is\nactually enabled.\n2. User-selected state – Whether the user has checked the corresponding\ntoggle.\n\n#### Changes\n\n- Renamed disabled → canToggle to clearly represent UI interaction.\n- Renamed enablements → userSelectedEnablements to reflect user-selected\ntoggle states, not feature enablement.\n- Refactored shouldAllowEnablement logic for clarity and correctness:\n- If riskScore is enabled, return whether the user has enabled\nentityStore.\n- If entityStore is enabled, return whether the user has enabled\nriskScore.\n - Otherwise, return true if either toggle is selected.\n- Updated corresponding tests to reflect naming and logic changes.\n\n## Testing/Validation\nManually tested the toggling behaviour still works as before and modal\nstill shows warning, and disables the \"enable\" button when there are no\navailable options selected.\n\n### Validation Video\n\n\nhttps://github.com/user-attachments/assets/0f2a3f59-e2a0-4c8b-a350-70a9573a8566","sha":"874cee2c575efe75ede0702ac243855abe008a69"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.17","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/212519","number":212519,"state":"OPEN"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212441","number":212441,"mergeCommit":{"message":"[refactoring] Distinguish User Controls from Risk Engine in DashboardEnablementPanel (#212441)\n\n## Summary\nThis PR refactors naming and logic in EntityStoreEnablementModal to\nimprove readability and better distinguish between:\n1. Feature enablement state – Whether Risk Score or Entity Store is\nactually enabled.\n2. User-selected state – Whether the user has checked the corresponding\ntoggle.\n\n#### Changes\n\n- Renamed disabled → canToggle to clearly represent UI interaction.\n- Renamed enablements → userSelectedEnablements to reflect user-selected\ntoggle states, not feature enablement.\n- Refactored shouldAllowEnablement logic for clarity and correctness:\n- If riskScore is enabled, return whether the user has enabled\nentityStore.\n- If entityStore is enabled, return whether the user has enabled\nriskScore.\n - Otherwise, return true if either toggle is selected.\n- Updated corresponding tests to reflect naming and logic changes.\n\n## Testing/Validation\nManually tested the toggling behaviour still works as before and modal\nstill shows warning, and disables the \"enable\" button when there are no\navailable options selected.\n\n### Validation Video\n\n\nhttps://github.com/user-attachments/assets/0f2a3f59-e2a0-4c8b-a350-70a9573a8566","sha":"874cee2c575efe75ede0702ac243855abe008a69"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
This commit is contained in:
parent
aa3eb6f9b4
commit
2bda83db41
3 changed files with 18 additions and 18 deletions
|
@ -228,11 +228,11 @@ export const EnablementPanel: React.FC<EnableEntityStorePanelProps> = ({ state }
|
|||
toggle={(visible) => setModalState({ visible })}
|
||||
enableStore={enableEntityStore}
|
||||
riskScore={{
|
||||
disabled: combinedRiskEngineStatus !== RiskEngineStatusEnum.NOT_INSTALLED,
|
||||
canToggle: combinedRiskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED,
|
||||
checked: combinedRiskEngineStatus === RiskEngineStatusEnum.NOT_INSTALLED,
|
||||
}}
|
||||
entityStore={{
|
||||
disabled: entityStoreStatus === 'running',
|
||||
canToggle: entityStoreStatus !== 'running',
|
||||
checked: entityStoreStatus === 'not_installed',
|
||||
}}
|
||||
/>
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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<EntityStoreEnablementModalProps> = ({
|
||||
|
@ -85,8 +85,8 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
|
|||
const riskEnginePrivileges = useMissingRiskEnginePrivileges();
|
||||
|
||||
const enablementOptions = shouldAllowEnablement(
|
||||
!!riskScore.disabled,
|
||||
!!entityStore.disabled,
|
||||
!riskScore.canToggle,
|
||||
!entityStore.canToggle,
|
||||
enablements
|
||||
);
|
||||
const { AdditionalChargesMessage } = useContractComponents();
|
||||
|
@ -129,7 +129,7 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
|
|||
}
|
||||
checked={enablements.riskScore}
|
||||
disabled={
|
||||
riskScore.disabled ||
|
||||
!riskScore.canToggle ||
|
||||
(!riskEnginePrivileges.isLoading && !riskEnginePrivileges?.hasAllRequiredPrivileges)
|
||||
}
|
||||
onChange={() => setEnablements((prev) => ({ ...prev, riskScore: !prev.riskScore }))}
|
||||
|
@ -156,7 +156,7 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
|
|||
}
|
||||
checked={enablements.entityStore}
|
||||
disabled={
|
||||
entityStore.disabled ||
|
||||
!entityStore.canToggle ||
|
||||
(!isLoadingEntityEnginePrivileges && !entityEnginePrivileges?.has_all_required)
|
||||
}
|
||||
onChange={() =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue