Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import React, { useCallback, useEffect } from 'react';
import { EuiFieldNumber } from '@elastic/eui';
import { MAX_CONSECUTIVE_BREACHES } from '@kbn/alerting-v2-schemas';
import { i18n } from '@kbn/i18n';
import { Controller, useFormContext } from 'react-hook-form';
import type { FormValues } from '../types';
import { INVALID_NUMBER_KEYS, parsePositiveIntegerInput } from '../utils';

const MAX_PENDING_COUNT = 1000;
const DEFAULT_PENDING_COUNT = 2;

interface StateTransitionCountFieldProps {
Expand Down Expand Up @@ -46,7 +45,7 @@ export const StateTransitionCountField: React.FC<StateTransitionCountFieldProps>
defaultMessage: 'Consecutive breaches is required.',
}),
min: 1,
max: MAX_PENDING_COUNT,
max: MAX_CONSECUTIVE_BREACHES,
validate: (value) => {
if (value != null && !Number.isInteger(value)) {
return i18n.translate('xpack.alertingV2.ruleForm.stateTransition.countIntegerError', {
Expand All @@ -61,13 +60,13 @@ export const StateTransitionCountField: React.FC<StateTransitionCountFieldProps>
value={value ?? DEFAULT_PENDING_COUNT}
onChange={(e) => {
const parsedValue = parsePositiveIntegerInput(e.target.value);
if (parsedValue != null && parsedValue <= MAX_PENDING_COUNT) {
if (parsedValue != null && parsedValue <= MAX_CONSECUTIVE_BREACHES) {
onChange(parsedValue);
}
}}
onKeyDown={onKeyDown}
min={1}
max={MAX_PENDING_COUNT}
max={MAX_CONSECUTIVE_BREACHES}
step={1}
isInvalid={!!error}
data-test-subj="stateTransitionCountInput"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

/** Maximum number of consecutive breaches before transition */
export const MAX_CONSECUTIVE_BREACHES = 1000;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

export * from './rule_data_schema';
export * from './constants';
export type { RuleResponse } from './rule_response';
export { validateDuration, validateEsqlQuery } from './validation';
export * from './notification_policy_data_schema';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { z } from '@kbn/zod';
import { validateEsqlQuery } from './validation';
import { durationSchema } from './common';
import { MAX_CONSECUTIVE_BREACHES } from './constants';

/** Primitives */

Expand Down Expand Up @@ -111,7 +112,7 @@ const stateTransitionSchema = z
.number()
.int()
.min(0)
.max(1000)
.max(MAX_CONSECUTIVE_BREACHES)
.optional()
.describe('Consecutive breaches before active.'),
pending_timeframe: durationSchema.optional().describe('Time window for pending evaluation.'),
Expand Down