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

[Detection Engine] add validation for new terms history window #191038

Merged
merged 7 commits into from
Oct 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,35 @@ export const schema: FormSchema<DefineStepRule> = {
defaultMessage: "New terms rules only alert if terms don't appear in historical data.",
}
),
validations: [
{
validator: (
...args: Parameters<ValidationFunc>
): ReturnType<ValidationFunc<{}, ERROR_CODE>> | undefined => {
const [{ path, formData }] = args;
const needsValidation = isNewTermsRule(formData.ruleType);

if (!needsValidation) {
return;
}

const filterTimeVal = formData.historyWindowSize.match(/\d+/g);

if (filterTimeVal <= 0) {
return {
code: 'ERR_MIN_LENGTH',
path,
message: i18n.translate(
'xpack.securitySolution.detectionEngine.validations.stepDefineRule.historyWindowSize.errMin',
{
defaultMessage: 'History window size must be greater than 0.',
}
),
};
}
},
},
],
},
groupByFields: {
type: FIELD_TYPES.COMBO_BOX,
Expand Down