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

Fixed default message for index threshold includes both threshold values #60545

Merged
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 @@ -50,7 +50,7 @@ const DEFAULT_VALUES = {
THRESHOLD_COMPARATOR: COMPARATORS.GREATER_THAN,
TIME_WINDOW_SIZE: 5,
TIME_WINDOW_UNIT: 'm',
THRESHOLD: [1000, 5000],
THRESHOLD: [1000],
GROUP_BY: 'all',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const validateExpression = (alertParams: IndexThresholdAlertParams): Vali
})
);
}
if (!threshold || threshold.length === 0 || (threshold.length === 1 && !threshold[0])) {
if (!threshold || threshold.length === 0 || threshold[0] === undefined) {
errors.threshold0.push(
i18n.translate('xpack.triggersActionsUI.sections.addAlert.error.requiredThreshold0Text', {
defaultMessage: 'Threshold0 is required.',
Expand All @@ -100,6 +100,7 @@ export const validateExpression = (alertParams: IndexThresholdAlertParams): Vali
thresholdComparator &&
builtInComparators[thresholdComparator].requiredValues > 1 &&
(!threshold ||
threshold[1] === undefined ||
(threshold && threshold.length < builtInComparators[thresholdComparator!].requiredValues))
) {
errors.threshold1.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('threshold expression', () => {
const wrapper = shallow(
<ThresholdExpression
thresholdComparator={'between'}
errors={{ threshold0: [] }}
errors={{ threshold0: [], threshold1: [] }}
onChangeSelectedThreshold={onChangeSelectedThreshold}
onChangeSelectedThresholdComparator={onChangeSelectedThresholdComparator}
/>
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('threshold expression', () => {
const wrapper = shallow(
<ThresholdExpression
thresholdComparator={'between'}
errors={{ threshold0: [] }}
errors={{ threshold0: [], threshold1: [] }}
onChangeSelectedThreshold={onChangeSelectedThreshold}
onChangeSelectedThresholdComparator={onChangeSelectedThresholdComparator}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export const ThresholdExpression = ({
value={thresholdComparator}
onChange={e => {
onChangeSelectedThresholdComparator(e.target.value);
const thresholdValues = threshold.slice(
0,
comparators[e.target.value].requiredValues
);
onChangeSelectedThreshold(thresholdValues);
}}
options={Object.values(comparators).map(({ text, value }) => {
return { text, value };
Expand All @@ -123,18 +128,23 @@ export const ThresholdExpression = ({
</EuiFlexItem>
) : null}
<EuiFlexItem grow={false}>
<EuiFormRow>
<EuiFormRow
isInvalid={errors[`threshold${i}`].length > 0 || !threshold[i]}
error={errors[`threshold${i}`]}
>
<EuiFieldNumber
data-test-subj="alertThresholdInput"
value={!threshold || threshold[i] === null ? 0 : threshold[i]}
min={0}
step={0.1}
value={!threshold || threshold[i] === undefined ? '' : threshold[i]}
isInvalid={errors[`threshold${i}`].length > 0 || !threshold[i]}
onChange={e => {
const { value } = e.target;
const thresholdVal = value !== '' ? parseFloat(value) : undefined;
const newThreshold = [...threshold];
if (thresholdVal) {
if (thresholdVal !== undefined) {
newThreshold[i] = thresholdVal;
} else {
delete newThreshold[i];
}
onChangeSelectedThreshold(newThreshold);
}}
Expand Down