-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8013dcd
commit d13fb76
Showing
14 changed files
with
491 additions
and
228 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...solution/public/detection_engine/rule_creation/components/threshold_edit/field_configs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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 type { ValidationFunc } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; | ||
import { FIELD_TYPES } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; | ||
import type { ERROR_CODE } from '@kbn/es-ui-shared-plugin/static/forms/helpers/field_validators/types'; | ||
import { isEmpty } from 'lodash'; | ||
import { fieldValidators } from '../../../../shared_imports'; | ||
import * as i18n from './translations'; | ||
|
||
export const THRESHOLD_FIELD_CONFIG = { | ||
type: FIELD_TYPES.COMBO_BOX, | ||
label: i18n.THRESHOLD_FIELD_LABEL, | ||
helpText: i18n.THRESHOLD_FIELD_HELP_TEXT, | ||
validations: [ | ||
{ | ||
validator: ( | ||
...args: Parameters<ValidationFunc> | ||
): ReturnType<ValidationFunc<{}, ERROR_CODE>> | undefined => { | ||
return fieldValidators.maxLengthField({ | ||
length: 3, | ||
message: i18n.THRESHOLD_FIELD_COUNT_VALIDATION_ERROR, | ||
})(...args); | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export const THRESHOLD_VALUE_CONFIG = { | ||
type: FIELD_TYPES.NUMBER, | ||
label: i18n.THRESHOLD_VALUE_LABEL, | ||
validations: [ | ||
{ | ||
validator: ( | ||
...args: Parameters<ValidationFunc> | ||
): ReturnType<ValidationFunc<{}, ERROR_CODE>> | undefined => { | ||
return fieldValidators.numberGreaterThanField({ | ||
than: 1, | ||
message: i18n.THRESHOLD_VALUE_VALIDATION_ERROR, | ||
allowEquality: true, | ||
})(...args); | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export function getCardinalityFieldConfig(path: string) { | ||
return { | ||
defaultValue: [] as unknown, | ||
fieldsToValidateOnChange: [`${path}.cardinality.field`, `${path}.cardinality.value`], | ||
type: FIELD_TYPES.COMBO_BOX, | ||
label: i18n.CARDINALITY_FIELD_LABEL, | ||
validations: [ | ||
{ | ||
validator: ( | ||
...args: Parameters<ValidationFunc> | ||
): ReturnType<ValidationFunc<{}, ERROR_CODE>> | undefined => { | ||
const [{ formData }] = args; | ||
|
||
if ( | ||
isEmpty(formData[`${path}.cardinality.field`]) && | ||
!isEmpty(formData[`${path}.cardinality.value`]) | ||
) { | ||
return fieldValidators.emptyField(i18n.CARDINALITY_FIELD_MISSING_VALIDATION_ERROR)( | ||
...args | ||
); | ||
} | ||
}, | ||
}, | ||
], | ||
helpText: i18n.CARDINALITY_FIELD_HELP_TEXT, | ||
}; | ||
} | ||
|
||
export function getCardinalityValueConfig(path: string) { | ||
return { | ||
fieldsToValidateOnChange: [`${path}.cardinality.field`, `${path}.cardinality.value`], | ||
type: FIELD_TYPES.NUMBER, | ||
label: i18n.CARDINALITY_VALUE_LABEL, | ||
validations: [ | ||
{ | ||
validator: ( | ||
...args: Parameters<ValidationFunc> | ||
): ReturnType<ValidationFunc<{}, ERROR_CODE>> | undefined => { | ||
const [{ formData }] = args; | ||
|
||
if (!isEmpty(formData[`${path}.cardinality.field`])) { | ||
return fieldValidators.numberGreaterThanField({ | ||
than: 1, | ||
message: i18n.CARDINALITY_VALUE_VALIDATION_ERROR, | ||
allowEquality: true, | ||
})(...args); | ||
} | ||
}, | ||
}, | ||
], | ||
}; | ||
} |
8 changes: 8 additions & 0 deletions
8
...curity_solution/public/detection_engine/rule_creation/components/threshold_edit/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { ThresholdEdit } from './threshold_edit'; |
76 changes: 76 additions & 0 deletions
76
...lution/public/detection_engine/rule_creation/components/threshold_edit/threshold_edit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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, { useCallback, useMemo } from 'react'; | ||
import { type FieldSpec } from '@kbn/data-views-plugin/common'; | ||
import { type FieldHook, UseMultiFields } from '../../../../shared_imports'; | ||
import { ThresholdInput } from '../../../rule_creation_ui/components/threshold_input'; | ||
import { | ||
THRESHOLD_FIELD_CONFIG, | ||
THRESHOLD_VALUE_CONFIG, | ||
getCardinalityFieldConfig, | ||
getCardinalityValueConfig, | ||
} from './field_configs'; | ||
|
||
interface ThresholdEditProps { | ||
path: string; | ||
esFields: FieldSpec[]; | ||
direction?: 'row' | 'column'; | ||
} | ||
|
||
export function ThresholdEdit({ | ||
path, | ||
esFields, | ||
direction = 'row', | ||
}: ThresholdEditProps): JSX.Element { | ||
const ThresholdInputChildren = useCallback( | ||
({ | ||
thresholdField, | ||
thresholdValue, | ||
thresholdCardinalityField, | ||
thresholdCardinalityValue, | ||
}: Record<string, FieldHook>) => ( | ||
<ThresholdInput | ||
browserFields={esFields} | ||
thresholdField={thresholdField} | ||
thresholdValue={thresholdValue} | ||
thresholdCardinalityField={thresholdCardinalityField} | ||
thresholdCardinalityValue={thresholdCardinalityValue} | ||
direction={direction} | ||
/> | ||
), | ||
[esFields, direction] | ||
); | ||
|
||
const cardinalityFieldConfig = useMemo(() => getCardinalityFieldConfig(path), [path]); | ||
const cardinalityValueConfig = useMemo(() => getCardinalityValueConfig(path), [path]); | ||
|
||
return ( | ||
<UseMultiFields | ||
fields={{ | ||
thresholdField: { | ||
path: `${path}.field`, | ||
config: THRESHOLD_FIELD_CONFIG, | ||
}, | ||
thresholdValue: { | ||
path: `${path}.value`, | ||
config: THRESHOLD_VALUE_CONFIG, | ||
}, | ||
thresholdCardinalityField: { | ||
path: `${path}.cardinality.field`, | ||
config: cardinalityFieldConfig, | ||
}, | ||
thresholdCardinalityValue: { | ||
path: `${path}.cardinality.value`, | ||
config: cardinalityValueConfig, | ||
}, | ||
}} | ||
> | ||
{ThresholdInputChildren} | ||
</UseMultiFields> | ||
); | ||
} |
78 changes: 78 additions & 0 deletions
78
..._solution/public/detection_engine/rule_creation/components/threshold_edit/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const THRESHOLD_FIELD_LABEL = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepAboutRule.fieldThresholdFieldLabel', | ||
{ | ||
defaultMessage: 'Group by', | ||
} | ||
); | ||
|
||
export const THRESHOLD_FIELD_HELP_TEXT = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepAboutRule.fieldThresholdFieldHelpText', | ||
{ | ||
defaultMessage: "Select fields to group by. Fields are joined together with 'AND'", | ||
} | ||
); | ||
|
||
export const THRESHOLD_FIELD_COUNT_VALIDATION_ERROR = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.validations.thresholdFieldFieldData.arrayLengthGreaterThanMaxErrorMessage', | ||
{ | ||
defaultMessage: 'Number of fields must be 3 or less.', | ||
} | ||
); | ||
|
||
export const THRESHOLD_VALUE_LABEL = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepAboutRule.fieldThresholdValueLabel', | ||
{ | ||
defaultMessage: 'Threshold', | ||
} | ||
); | ||
|
||
export const THRESHOLD_VALUE_VALIDATION_ERROR = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.validations.thresholdValueFieldData.numberGreaterThanOrEqualOneErrorMessage', | ||
{ | ||
defaultMessage: 'Value must be greater than or equal to one.', | ||
} | ||
); | ||
|
||
export const CARDINALITY_FIELD_LABEL = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepDefineRule.fieldThresholdCardinalityFieldLabel', | ||
{ | ||
defaultMessage: 'Count', | ||
} | ||
); | ||
|
||
export const CARDINALITY_FIELD_MISSING_VALIDATION_ERROR = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.validations.thresholdCardinalityFieldFieldData.thresholdCardinalityFieldNotSuppliedMessage', | ||
{ | ||
defaultMessage: 'A Cardinality Field is required.', | ||
} | ||
); | ||
|
||
export const CARDINALITY_FIELD_HELP_TEXT = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepDefineRule.fieldThresholdFieldCardinalityFieldHelpText', | ||
{ | ||
defaultMessage: 'Select a field to check cardinality', | ||
} | ||
); | ||
|
||
export const CARDINALITY_VALUE_LABEL = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepDefineRule.fieldThresholdCardinalityValueFieldLabel', | ||
{ | ||
defaultMessage: 'Unique values', | ||
} | ||
); | ||
|
||
export const CARDINALITY_VALUE_VALIDATION_ERROR = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.validations.thresholdCardinalityValueFieldData.numberGreaterThanOrEqualOneErrorMessage', | ||
{ | ||
defaultMessage: 'Value must be greater than or equal to one.', | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.