Skip to content

Commit

Permalink
Adds new operatorsList prop in exceptions builder to allow pass a lis…
Browse files Browse the repository at this point in the history
…t of operators. Add this prop in event filters form (#108015)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
dasansol92 and kibanamachine committed Aug 12, 2021
1 parent 99e73c7 commit de9d784
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface EntryItemProps {
onlyShowListOperators?: boolean;
setErrorsExist: (arg: boolean) => void;
isDisabled?: boolean;
operatorsList?: OperatorOption[];
}

export const BuilderEntryItem: React.FC<EntryItemProps> = ({
Expand All @@ -81,6 +82,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
setErrorsExist,
showLabel,
isDisabled = false,
operatorsList,
}): JSX.Element => {
const handleError = useCallback(
(err: boolean): void => {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BuilderEntry,
ExceptionsBuilderExceptionItem,
FormattedBuilderEntry,
OperatorOption,
getFormattedBuilderEntries,
getUpdatedEntriesOnDelete,
} from '@kbn/securitysolution-list-utils';
Expand Down Expand Up @@ -60,6 +61,7 @@ interface BuilderExceptionListItemProps {
setErrorsExist: (arg: boolean) => void;
onlyShowListOperators?: boolean;
isDisabled?: boolean;
operatorsList?: OperatorOption[];
}

export const BuilderExceptionListItemComponent = React.memo<BuilderExceptionListItemProps>(
Expand All @@ -80,6 +82,7 @@ export const BuilderExceptionListItemComponent = React.memo<BuilderExceptionList
setErrorsExist,
onlyShowListOperators = false,
isDisabled = false,
operatorsList,
}) => {
const handleEntryChange = useCallback(
(entry: BuilderEntry, entryIndex: number): void => {
Expand Down Expand Up @@ -152,6 +155,7 @@ export const BuilderExceptionListItemComponent = React.memo<BuilderExceptionList
showLabel={
exceptionItemIndex === 0 && index === 0 && item.nested !== 'child'
}
operatorsList={operatorsList}
/>
</MyOverflowContainer>
<BuilderEntryDeleteButtonComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import {
CreateExceptionListItemBuilderSchema,
ExceptionsBuilderExceptionItem,
OperatorOption,
containsValueListEntry,
filterExceptionItems,
getDefaultEmptyEntry,
Expand Down Expand Up @@ -90,6 +91,7 @@ export interface ExceptionBuilderProps {
onChange: (arg: OnChangeProps) => void;
ruleName: string;
isDisabled?: boolean;
operatorsList?: OperatorOption[];
}

export const ExceptionBuilderComponent = ({
Expand All @@ -109,6 +111,7 @@ export const ExceptionBuilderComponent = ({
ruleName,
isDisabled = false,
osTypes,
operatorsList,
}: ExceptionBuilderProps): JSX.Element => {
const [
{
Expand Down Expand Up @@ -413,6 +416,7 @@ export const ExceptionBuilderComponent = ({
setErrorsExist={setErrorsExist}
osTypes={osTypes}
isDisabled={isDisabled}
operatorsList={operatorsList}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]
);
Expand Down

0 comments on commit de9d784

Please sign in to comment.