[Stack Monitoring] Prefer units if they are defined when rende… (#43709)

* Prefer units if they are defined when rendering cells

* Jest snapshot update

* Lint recommendations

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
cachedout 2020-01-28 18:28:45 +00:00 committed by GitHub
parent 5108eb378d
commit 54d40e3670
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -28,12 +28,12 @@ exports[`Node Listing Metric Cell should format a non-percentage metric 1`] = `
<div
class="euiText euiText--extraSmall"
>
206.5 GB max
206.5 GB max
</div>
<div
class="euiText euiText--extraSmall"
>
206.3 GB min
206.3 GB min
</div>
</div>
</div>

View file

@ -21,11 +21,11 @@ const getSlopeArrow = slope => {
return null;
};
const metricVal = (metric, format, isPercent) => {
const metricVal = (metric, format, isPercent, units) => {
if (isPercent) {
return formatMetric(metric, format, '%', { prependSpace: false });
}
return formatMetric(metric, format);
return formatMetric(metric, format, units);
};
const noWrapStyle = { overflowX: 'hidden', whiteSpace: 'nowrap' };
@ -34,6 +34,7 @@ function MetricCell({ isOnline, metric = {}, isPercent, ...props }) {
if (isOnline) {
const { lastVal, maxVal, minVal, slope } = get(metric, 'summary', {});
const format = get(metric, 'metric.format');
const units = get(metric, 'metric.units');
return (
<EuiFlexGroup gutterSize="m" alignItems="center" wrap {...props}>
@ -49,7 +50,7 @@ function MetricCell({ isOnline, metric = {}, isPercent, ...props }) {
{i18n.translate('xpack.monitoring.elasticsearch.nodes.cells.maxText', {
defaultMessage: '{metric} max',
values: {
metric: metricVal(maxVal, format, isPercent),
metric: metricVal(maxVal, format, isPercent, units),
},
})}
</EuiText>
@ -57,7 +58,7 @@ function MetricCell({ isOnline, metric = {}, isPercent, ...props }) {
{i18n.translate('xpack.monitoring.elasticsearch.nodes.cells.minText', {
defaultMessage: '{metric} min',
values: {
metric: metricVal(minVal, format, isPercent),
metric: metricVal(minVal, format, isPercent, units),
},
})}
</EuiText>