Skip to content
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

[Security Solution] Add validation error description on prebuilt rule editing (#191832) #192683

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';

import { EuiConfirmModal } from '@elastic/eui';
import { EuiConfirmModal, EuiSpacer, EuiText } from '@elastic/eui';

import * as i18n from './translations';

Expand All @@ -32,7 +32,19 @@ const SaveWithErrorsModalComponent = ({
confirmButtonText={i18n.SAVE_WITH_ERRORS_CONFIRM_BUTTON}
defaultFocusedButton="confirm"
>
<>{i18n.SAVE_WITH_ERRORS_MODAL_MESSAGE(errors.length)}</>
<>
{i18n.SAVE_WITH_ERRORS_MODAL_MESSAGE(errors.length)}
<EuiSpacer size="s" />
<ul>
{errors.map((validationError, idx) => {
return (
<li key={idx}>
<EuiText>{validationError}</EuiText>
</li>
);
})}
</ul>
</>
</EuiConfirmModal>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,20 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
const onSubmit = useCallback(async () => {
setNonBlockingRuleErrors([]);

const actionsStepFormValid = await actionsStepForm.validate();
if (rule.immutable) {
// Since users cannot edit Define, About and Schedule tabs of the rule, we skip validation of those to avoid
// user confusion of seeing that those tabs have error and not being able to see or do anything about that.
// We will need to remove this condition once rule customization work is done.
if (actionsStepFormValid) {
await saveChanges();
}
return;
}

const defineStepFormValid = await defineStepForm.validate();
const aboutStepFormValid = await aboutStepForm.validate();
const scheduleStepFormValid = await scheduleStepForm.validate();
const actionsStepFormValid = await actionsStepForm.validate();

if (
defineStepFormValid &&
aboutStepFormValid &&
Expand All @@ -465,6 +474,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
showSaveWithErrorsModal();
}
}, [
rule.immutable,
defineStepForm,
aboutStepForm,
scheduleStepForm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ describe('EQL rules', { tags: ['@ess', '@serverless'] }, () => {
const rule = getEqlRule();

it('validates missing data source', () => {
login();
visit(CREATE_RULE_URL);
selectEqlRuleType();
getIndexPatternClearButton().click();
Expand All @@ -258,7 +257,6 @@ describe('EQL rules', { tags: ['@ess', '@serverless'] }, () => {
});

it('validates missing data fields', () => {
login();
visit(CREATE_RULE_URL);
selectEqlRuleType();

Expand All @@ -282,7 +280,6 @@ describe('EQL rules', { tags: ['@ess', '@serverless'] }, () => {
});

it('validates syntax errors', () => {
login();
visit(CREATE_RULE_URL);
selectEqlRuleType();

Expand Down