Skip to content

Commit

Permalink
Add false_positives
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaindik committed Oct 16, 2024
1 parent 783a27e commit 96bee4f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { DescriptionEdit, descriptionSchema } from './fields/description';
import { NameEdit, nameSchema } from './fields/name';
import { TagsEdit, tagsSchema } from './fields/tags';
import { ReferencesEdit, referencesSchema, referencesSerializer } from './fields/references';
import {
FalsePositivesEdit,
falsePositivesSchema,
falsePositivesSerializer,
falsePositivesDeserializer,
} from './fields/false_positives';

interface CommonRuleFieldEditProps {
fieldName: UpgradeableCommonFields;
Expand All @@ -21,6 +27,15 @@ export function CommonRuleFieldEdit({ fieldName }: CommonRuleFieldEditProps) {
switch (fieldName) {
case 'description':
return <FieldFormWrapper component={DescriptionEdit} fieldFormSchema={descriptionSchema} />;
case 'false_positives':
return (
<FieldFormWrapper
component={FalsePositivesEdit}
fieldFormSchema={falsePositivesSchema}
serializer={falsePositivesSerializer}
deserializer={falsePositivesDeserializer}
/>
);
case 'name':
return <FieldFormWrapper component={NameEdit} fieldFormSchema={nameSchema} />;
case 'references':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 { compact } from 'lodash';
import * as i18n from '../../../../../../rule_creation_ui/components/step_about_rule/translations';
import type { FormSchema, FormData } from '../../../../../../../shared_imports';
import { UseField } from '../../../../../../../shared_imports';
import { schema } from '../../../../../../rule_creation_ui/components/step_about_rule/schema';
import type { RuleFalsePositiveArray } from '../../../../../../../../common/api/detection_engine';
import { AddItem } from '../../../../../../rule_creation_ui/components/add_item_form';

export const falsePositivesSchema = { falsePositives: schema.falsePositives } as FormSchema<{
falsePositives: RuleFalsePositiveArray;
}>;

const componentProps = {
addText: i18n.ADD_FALSE_POSITIVE,
};

export function FalsePositivesEdit(): JSX.Element {
return <UseField path="falsePositives" component={AddItem} componentProps={componentProps} />;
}

export function falsePositivesDeserializer(defaultValue: FormData) {
/* Set initial form value with camelCase "falsePositives" key instead of "false_positives" */
return {
falsePositives: defaultValue,
};
}

export function falsePositivesSerializer(formData: FormData): {
false_positives: RuleFalsePositiveArray;
} {
return {
/* Remove empty items from the falsePositives array */
false_positives: compact(formData.falsePositives),
};
}

0 comments on commit 96bee4f

Please sign in to comment.