Skip to content

Commit

Permalink
[8.16] Confirmation Modal - show warning message when nothing has bee…
Browse files Browse the repository at this point in the history
…n changed in modal. (#199523) (#200691)

# Backport

This will backport the following commits from `main` to `8.16`:
- [Confirmation Modal - show warning message when nothing has been
changed in modal.
(#199523)](#199523)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Charlotte Alexandra
Wilson","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-12T18:21:50Z","message":"Confirmation
Modal - show warning message when nothing has been changed in modal.
(#199523)","sha":"5d0b62ce9eb19a23cc8abfd6506be3f0f687ee80","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:
SecuritySolution","Theme: entity_analytics","Feature:Entity
Analytics","Team:Entity
Analytics","v8.16.0","backport:version","v8.17.0"],"number":199523,"url":"https://github.com/elastic/kibana/pull/199523","mergeCommit":{"message":"Confirmation
Modal - show warning message when nothing has been changed in modal.
(#199523)","sha":"5d0b62ce9eb19a23cc8abfd6506be3f0f687ee80"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199523","number":199523,"mergeCommit":{"message":"Confirmation
Modal - show warning message when nothing has been changed in modal.
(#199523)","sha":"5d0b62ce9eb19a23cc8abfd6506be3f0f687ee80"}},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/199858","number":199858,"state":"MERGED","mergeCommit":{"sha":"079c2269714073af316e501ec5fb2d8442e76620","message":"[8.x]
Confirmation Modal - show warning message when nothing has been changed
in modal. (#199523) (#199858)\n\n# Backport\n\nThis will backport the
following commits from `main` to `8.x`:\n- [Confirmation Modal - show
warning message when nothing has been\nchanged in
modal.\n(#199523)](https://github.com/elastic/kibana/pull/199523)\n\n<!---
Backport version: 9.4.3 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Charlotte
Alexandra\nWilson\",\"email\":\"[email protected]\"},\"sourceCommit\":{\"committedDate\":\"2024-11-12T18:21:50Z\",\"message\":\"Confirmation\nModal
- show warning message when nothing has been changed in
modal.\n(#199523)\",\"sha\":\"5d0b62ce9eb19a23cc8abfd6506be3f0f687ee80\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.17.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"release_note:skip\",\"v9.0.0\",\"Team:\nSecuritySolution\",\"Theme:
entity_analytics\",\"Feature:Entity\nAnalytics\",\"Team:Entity\nAnalytics\",\"v8.16.0\",\"backport:version\",\"v8.17.0\"],\"title\":\"Confirmation\nModal
- show warning message when nothing has been changed in
modal.\n\",\"number\":199523,\"url\":\"https://github.com/elastic/kibana/pull/199523\",\"mergeCommit\":{\"message\":\"Confirmation\nModal
- show warning message when nothing has been changed in
modal.\n(#199523)\",\"sha\":\"5d0b62ce9eb19a23cc8abfd6506be3f0f687ee80\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.16\",\"8.x\"],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/199523\",\"number\":199523,\"mergeCommit\":{\"message\":\"Confirmation\nModal
- show warning message when nothing has been changed in
modal.\n(#199523)\",\"sha\":\"5d0b62ce9eb19a23cc8abfd6506be3f0f687ee80\"}},{\"branch\":\"8.16\",\"label\":\"v8.16.0\",\"branchLabelMappingKey\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"},{\"branch\":\"8.x\",\"label\":\"v8.17.0\",\"branchLabelMappingKey\":\"^v8.17.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Charlotte Alexandra Wilson <[email protected]>"}}]}]
BACKPORT-->
  • Loading branch information
CAWilson94 authored Nov 19, 2024
1 parent 44bfa2d commit 24efe79
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 { fireEvent, render, screen } from '@testing-library/react';
import { EntityStoreEnablementModal } from './enablement_modal';
import { TestProviders } from '../../../../common/mock';

const mockToggle = jest.fn();
const mockEnableStore = jest.fn(() => jest.fn());

const defaultProps = {
visible: true,
toggle: mockToggle,
enableStore: mockEnableStore,
riskScore: { disabled: false, checked: false },
entityStore: { disabled: false, checked: false },
};

const renderComponent = (props = defaultProps) => {
return render(<EntityStoreEnablementModal {...props} />, { wrapper: TestProviders });
};

describe('EntityStoreEnablementModal', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should render the modal when visible is true', () => {
renderComponent();
expect(screen.getByRole('dialog')).toBeInTheDocument();
});

it('should not render the modal when visible is false', () => {
renderComponent({ ...defaultProps, visible: false });
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});

it('should call toggle function when cancel button is clicked', () => {
renderComponent();
fireEvent.click(screen.getByText('Cancel'));
expect(mockToggle).toHaveBeenCalledWith(false);
});

it('should call enableStore function when enable button is clicked', () => {
renderComponent({
...defaultProps,
riskScore: { ...defaultProps.riskScore, checked: true },
entityStore: { ...defaultProps.entityStore, checked: true },
});
fireEvent.click(screen.getByText('Enable'));
expect(mockEnableStore).toHaveBeenCalledWith({ riskScore: true, entityStore: true });
});

it('should display proceed warning when no enablement options are selected', () => {
renderComponent();
expect(screen.getByText('Please enable at least one option to proceed.')).toBeInTheDocument();
});

it('should disable the enable button when enablementOptions are false', () => {
renderComponent({
...defaultProps,
riskScore: { ...defaultProps.riskScore, checked: false },
entityStore: { ...defaultProps.entityStore, checked: false },
});

const enableButton = screen.getByRole('button', { name: /Enable/i });
expect(enableButton).toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import {
EuiButtonEmpty,
EuiBetaBadge,
EuiToolTip,
EuiCallOut,
useEuiTheme,
} from '@elastic/eui';
import { css } from '@emotion/react';
import React, { useState } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { TECHNICAL_PREVIEW, TECHNICAL_PREVIEW_TOOLTIP } from '../../../../common/translations';
import {
ENABLEMENT_DESCRIPTION_RISK_ENGINE_ONLY,
ENABLEMENT_DESCRIPTION_ENTITY_STORE_ONLY,
ENABLEMENT_WARNING_SELECT_TO_PROCEED,
} from '../translations';
import { useMissingRiskEnginePrivileges } from '../../../hooks/use_missing_risk_engine_privileges';
import { RiskEnginePrivilegesCallOut } from '../../risk_engine_privileges_callout';
Expand Down Expand Up @@ -57,18 +61,31 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
riskScore,
entityStore,
}) => {
const { euiTheme } = useEuiTheme();
const [enablements, setEnablements] = useState({
riskScore: !!riskScore.checked,
entityStore: !!entityStore.checked,
});
const riskEnginePrivileges = useMissingRiskEnginePrivileges();
const enablementOptions = enablements.riskScore || enablements.entityStore;

if (!visible) {
return null;
}
const hasRiskEnginePrivileges =
!riskEnginePrivileges.isLoading && riskEnginePrivileges?.hasAllRequiredPrivileges;

const proceedWarning = (
<EuiCallOut
size="s"
color="danger"
css={css`
border-radius: ${euiTheme.border.radius.medium};
`}
>
<p>{ENABLEMENT_WARNING_SELECT_TO_PROCEED}</p>
</EuiCallOut>
);
return (
<EuiModal onClose={() => toggle(false)}>
<EuiModalHeader>
Expand Down Expand Up @@ -131,13 +148,25 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
</EuiModalBody>

<EuiModalFooter>
<EuiButtonEmpty onClick={() => toggle(false)}>{'Cancel'}</EuiButtonEmpty>
<EuiButton onClick={enableStore(enablements)} fill>
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.enablements.modal.enable"
defaultMessage="Enable"
/>
</EuiButton>
<EuiFlexGroup justifyContent="flexEnd" alignItems="center">
{!enablementOptions ? <EuiFlexItem>{proceedWarning}</EuiFlexItem> : null}
<EuiFlexItem grow={false}>
<EuiFlexGroup direction="row" justifyContent="flexEnd">
<EuiButtonEmpty onClick={() => toggle(false)}>{'Cancel'}</EuiButtonEmpty>
<EuiButton
onClick={enableStore(enablements)}
fill
isDisabled={!enablementOptions}
aria-disabled={!enablementOptions}
>
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.enablements.modal.enable"
defaultMessage="Enable"
/>
</EuiButton>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiModalFooter>
</EuiModal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ export const ENABLEMENT_DESCRIPTION_BOTH = i18n.translate(
'Your entity store is currently empty. Add information about your entities directly from your logs, or import them using a text file.',
}
);

export const ENABLEMENT_WARNING_SELECT_TO_PROCEED = i18n.translate(
'xpack.securitySolution.entityAnalytics.entityStore.enablement.description.enablementWarningMessage',
{
defaultMessage: 'Please enable at least one option to proceed.',
}
);

0 comments on commit 24efe79

Please sign in to comment.