Skip to content

Commit c4ff7d4

Browse files
Merge branch '7.8' into backport/7.8/pr-65783
2 parents d572679 + 163ea07 commit c4ff7d4

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_chart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ export const ExpressionChart: React.FC<Props> = ({
265265
<EuiText size="xs" color="subdued">
266266
<FormattedMessage
267267
id="xpack.infra.metrics.alerts.dataTimeRangeLabel"
268-
defaultMessage="Last 20 {timeLabel}"
269-
values={{ timeLabel }}
268+
defaultMessage="Last {lookback} {timeLabel}"
269+
values={{ timeLabel, lookback: timeSize * 20 }}
270270
/>
271271
</EuiText>
272272
)}

x-pack/plugins/infra/public/alerting/metric_threshold/components/validation.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { i18n } from '@kbn/i18n';
8+
import { isNumber } from 'lodash';
89
import {
910
MetricExpressionParams,
1011
Comparator,
@@ -63,6 +64,21 @@ export function validateMetricThreshold({
6364
);
6465
}
6566

67+
// The Threshold component returns an empty array with a length ([empty]) because it's using delete newThreshold[i].
68+
// We need to use [...c.threshold] to convert it to an array with an undefined value ([undefined]) so we can test each element.
69+
if (c.threshold && c.threshold.length && ![...c.threshold].every(isNumber)) {
70+
[...c.threshold].forEach((v, i) => {
71+
if (!isNumber(v)) {
72+
const key = i === 0 ? 'threshold0' : 'threshold1';
73+
errors[id][key].push(
74+
i18n.translate('xpack.infra.metrics.alertFlyout.error.thresholdTypeRequired', {
75+
defaultMessage: 'Thresholds must contain a valid number.',
76+
})
77+
);
78+
}
79+
});
80+
}
81+
6682
if (c.comparator === Comparator.BETWEEN && (!c.threshold || c.threshold.length < 2)) {
6783
errors[id].threshold1.push(
6884
i18n.translate('xpack.infra.metrics.alertFlyout.error.thresholdRequired', {

x-pack/plugins/infra/public/components/alerting/inventory/validation.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import { i18n } from '@kbn/i18n';
88
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
9+
import { isNumber } from 'lodash';
10+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
911
import { MetricExpressionParams } from '../../../../server/lib/alerting/metric_threshold/types';
1012
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1113
import { ValidationResult } from '../../../../../triggers_actions_ui/public/types';
@@ -51,6 +53,21 @@ export function validateMetricThreshold({
5153
);
5254
}
5355

56+
// The Threshold component returns an empty array with a length ([empty]) because it's using delete newThreshold[i].
57+
// We need to use [...c.threshold] to convert it to an array with an undefined value ([undefined]) so we can test each element.
58+
if (c.threshold && c.threshold.length && ![...c.threshold].every(isNumber)) {
59+
[...c.threshold].forEach((v, i) => {
60+
if (!isNumber(v)) {
61+
const key = i === 0 ? 'threshold0' : 'threshold1';
62+
errors[id][key].push(
63+
i18n.translate('xpack.infra.metrics.alertFlyout.error.thresholdTypeRequired', {
64+
defaultMessage: 'Thresholds must contain a valid number.',
65+
})
66+
);
67+
}
68+
});
69+
}
70+
5471
if (c.comparator === 'between' && (!c.threshold || c.threshold.length < 2)) {
5572
errors[id].threshold1.push(
5673
i18n.translate('xpack.infra.metrics.alertFlyout.error.thresholdRequired', {

0 commit comments

Comments
 (0)