[Metrics UI] Display No Data context.values as [NO DATA] (#78038)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Zacqary Adam Xeper 2020-10-01 11:31:39 -05:00 committed by GitHub
parent a61f4d4cbf
commit 7836998e76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -148,8 +148,10 @@ export const FIRED_ACTIONS = {
const formatMetric = (metric: SnapshotMetricType, value: number) => {
const metricFormatter = get(METRIC_FORMATTERS, metric, METRIC_FORMATTERS.count);
if (value == null) {
return '';
if (isNaN(value)) {
return i18n.translate('xpack.infra.metrics.alerting.inventory.noDataFormattedValue', {
defaultMessage: '[NO DATA]',
});
}
const formatter = createFormatter(metricFormatter.formatter, metricFormatter.template);
return formatter(value);

View file

@ -131,11 +131,24 @@ const formatAlertResult = <AlertResult>(
} & AlertResult
) => {
const { metric, currentValue, threshold } = alertResult;
if (!metric.endsWith('.pct')) return alertResult;
const noDataValue = i18n.translate(
'xpack.infra.metrics.alerting.threshold.noDataFormattedValue',
{
defaultMessage: '[NO DATA]',
}
);
if (!metric.endsWith('.pct'))
return {
...alertResult,
currentValue: currentValue ?? noDataValue,
};
const formatter = createFormatter('percent');
return {
...alertResult,
currentValue: formatter(currentValue),
currentValue:
currentValue !== null && typeof currentValue !== 'undefined'
? formatter(currentValue)
: noDataValue,
threshold: Array.isArray(threshold) ? threshold.map((v: number) => formatter(v)) : threshold,
};
};