Adds new operatorsList prop in exceptions builder to allow pass a list of operators. Add this prop in event filters form (#108015)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
David Sánchez 2021-08-12 12:59:33 +02:00 committed by GitHub
parent 99e73c7960
commit de9d784035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 1 deletions

View file

@ -85,6 +85,13 @@ export const isNotInListOperator: OperatorOption = {
value: 'is_not_in_list',
};
export const EVENT_FILTERS_OPERATORS: OperatorOption[] = [
isOperator,
isNotOperator,
isOneOfOperator,
isNotOneOfOperator,
];
export const EXCEPTION_OPERATORS: OperatorOption[] = [
isOperator,
isNotOperator,

View file

@ -65,6 +65,7 @@ export interface EntryItemProps {
onlyShowListOperators?: boolean;
setErrorsExist: (arg: boolean) => void;
isDisabled?: boolean;
operatorsList?: OperatorOption[];
}
export const BuilderEntryItem: React.FC<EntryItemProps> = ({
@ -81,6 +82,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
setErrorsExist,
showLabel,
isDisabled = false,
operatorsList,
}): JSX.Element => {
const handleError = useCallback(
(err: boolean): void => {
@ -194,7 +196,9 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
);
const renderOperatorInput = (isFirst: boolean): JSX.Element => {
const operatorOptions = onlyShowListOperators
const operatorOptions = operatorsList
? operatorsList
: onlyShowListOperators
? EXCEPTION_OPERATORS_ONLY_LISTS
: getOperatorOptions(
entry,

View file

@ -15,6 +15,7 @@ import {
BuilderEntry,
ExceptionsBuilderExceptionItem,
FormattedBuilderEntry,
OperatorOption,
getFormattedBuilderEntries,
getUpdatedEntriesOnDelete,
} from '@kbn/securitysolution-list-utils';
@ -60,6 +61,7 @@ interface BuilderExceptionListItemProps {
setErrorsExist: (arg: boolean) => void;
onlyShowListOperators?: boolean;
isDisabled?: boolean;
operatorsList?: OperatorOption[];
}
export const BuilderExceptionListItemComponent = React.memo<BuilderExceptionListItemProps>(
@ -80,6 +82,7 @@ export const BuilderExceptionListItemComponent = React.memo<BuilderExceptionList
setErrorsExist,
onlyShowListOperators = false,
isDisabled = false,
operatorsList,
}) => {
const handleEntryChange = useCallback(
(entry: BuilderEntry, entryIndex: number): void => {
@ -152,6 +155,7 @@ export const BuilderExceptionListItemComponent = React.memo<BuilderExceptionList
showLabel={
exceptionItemIndex === 0 && index === 0 && item.nested !== 'child'
}
operatorsList={operatorsList}
/>
</MyOverflowContainer>
<BuilderEntryDeleteButtonComponent

View file

@ -24,6 +24,7 @@ import {
import {
CreateExceptionListItemBuilderSchema,
ExceptionsBuilderExceptionItem,
OperatorOption,
containsValueListEntry,
filterExceptionItems,
getDefaultEmptyEntry,
@ -90,6 +91,7 @@ export interface ExceptionBuilderProps {
onChange: (arg: OnChangeProps) => void;
ruleName: string;
isDisabled?: boolean;
operatorsList?: OperatorOption[];
}
export const ExceptionBuilderComponent = ({
@ -109,6 +111,7 @@ export const ExceptionBuilderComponent = ({
ruleName,
isDisabled = false,
osTypes,
operatorsList,
}: ExceptionBuilderProps): JSX.Element => {
const [
{
@ -413,6 +416,7 @@ export const ExceptionBuilderComponent = ({
setErrorsExist={setErrorsExist}
osTypes={osTypes}
isDisabled={isDisabled}
operatorsList={operatorsList}
/>
</EuiFlexItem>
</EuiFlexGroup>

View file

@ -19,6 +19,7 @@ import {
} from '@elastic/eui';
import type { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types';
import { EVENT_FILTERS_OPERATORS } from '@kbn/securitysolution-list-utils';
import { OperatingSystem } from '../../../../../../../common/endpoint/types';
import { AddExceptionComments } from '../../../../../../common/components/exceptions/add_exception_comments';
@ -135,6 +136,7 @@ export const EventFiltersForm: React.FC<EventFiltersFormProps> = memo(
idAria: 'alert-exception-builder',
onChange: handleOnBuilderChange,
listTypeSpecificIndexPatternFilter: filterIndexPatterns,
operatorsList: EVENT_FILTERS_OPERATORS,
}),
[data, handleOnBuilderChange, http, indexPatterns, exception]
);