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 support for editing prebuilt rules to the Rule Editing page #199550

Merged
merged 5 commits into from
Nov 13, 2024
Merged
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 @@ -69,6 +69,7 @@ import { useRuleForms, useRuleFormsErrors, useRuleIndexPattern } from '../form';
import { useEsqlIndex, useEsqlQueryForAboutStep } from '../../hooks';
import { CustomHeaderPageMemo } from '..';
import { SaveWithErrorsModal } from '../../components/save_with_errors_confirmation';
import { useIsPrebuiltRulesCustomizationEnabled } from '../../../rule_management/hooks/use_is_prebuilt_rules_customization_enabled';
import { ALERT_SUPPRESSION_FIELDS_FIELD_NAME } from '../../../rule_creation/components/alert_suppression_edit';

const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
Expand All @@ -86,11 +87,14 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
useListsConfig();
const { application, triggersActionsUi } = useKibana().services;
const { navigateToApp } = application;
const isPrebuiltRulesCustomizationEnabled = useIsPrebuiltRulesCustomizationEnabled();

const { detailName: ruleId } = useParams<{ detailName: string }>();

const [activeStep, setActiveStep] = useState<RuleStep>(
rule.immutable ? RuleStep.ruleActions : RuleStep.defineRule
!isPrebuiltRulesCustomizationEnabled && rule.immutable
? RuleStep.ruleActions
: RuleStep.defineRule
);
const { mutateAsync: updateRule, isLoading } = useUpdateRule();
const [isRulePreviewVisible, setIsRulePreviewVisible] = useState(true);
Expand Down Expand Up @@ -211,7 +215,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
'data-test-subj': 'edit-rule-define-tab',
id: RuleStep.defineRule,
name: ruleI18n.DEFINITION,
disabled: rule?.immutable,
disabled: !isPrebuiltRulesCustomizationEnabled && rule?.immutable,
content: (
<div
style={{
Expand Down Expand Up @@ -256,7 +260,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
'data-test-subj': 'edit-rule-about-tab',
id: RuleStep.aboutRule,
name: ruleI18n.ABOUT,
disabled: rule?.immutable,
disabled: !isPrebuiltRulesCustomizationEnabled && rule?.immutable,
content: (
<div
style={{
Expand Down Expand Up @@ -288,7 +292,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
'data-test-subj': 'edit-rule-schedule-tab',
id: RuleStep.scheduleRule,
name: ruleI18n.SCHEDULE,
disabled: rule?.immutable,
disabled: !isPrebuiltRulesCustomizationEnabled && rule?.immutable,
content: (
<div
style={{
Expand Down Expand Up @@ -340,6 +344,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
},
],
[
isPrebuiltRulesCustomizationEnabled,
rule?.immutable,
rule?.id,
activeStep,
Expand All @@ -356,15 +361,15 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
isIndexPatternLoading,
isQueryBarValid,
defineStepData,
memoizedIndex,
aboutStepData,
aboutStepForm,
esqlQueryForAboutStep,
scheduleStepData,
scheduleStepForm,
actionsStepData,
actionMessageParams,
actionsStepForm,
memoizedIndex,
esqlQueryForAboutStep,
]
);

Expand Down Expand Up @@ -414,7 +419,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
setNonBlockingRuleErrors([]);

const actionsStepFormValid = await actionsStepForm.validate();
if (rule.immutable) {
if (!isPrebuiltRulesCustomizationEnabled && 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.
Expand Down Expand Up @@ -451,11 +456,12 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
showSaveWithErrorsModal();
}
}, [
actionsStepForm,
isPrebuiltRulesCustomizationEnabled,
rule.immutable,
defineStepForm,
aboutStepForm,
scheduleStepForm,
actionsStepForm,
getRuleFormsErrors,
saveChanges,
showSaveWithErrorsModal,
Expand Down