Skip to content

Commit c51c7aa

Browse files
fix(MetricChart): do not convert nulls (#677)
1 parent ab646bc commit c51c7aa

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/components/MetricChart/convertReponse.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ export const convertResponse = (
88
const preparedMetrics = data
99
.map(({datapoints, target}) => {
1010
const metricDescription = metrics.find((metric) => metric.target === target);
11-
const chartData = datapoints.map((datapoint) => datapoint[0] || 0);
1211

1312
if (!metricDescription) {
1413
return undefined;
1514
}
1615

16+
const chartData = datapoints.map((datapoint) => datapoint[0]);
17+
1718
return {
1819
...metricDescription,
1920
data: chartData,

src/components/MetricChart/getDefaultDataFormatter.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {formatBytes} from '../../utils/bytesParsers';
2+
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
23
import {roundToPrecision} from '../../utils/dataFormatters/dataFormatters';
34
import {formatToMs} from '../../utils/timeParsers';
45
import {isNumeric} from '../../utils/utils';
@@ -18,11 +19,19 @@ export const getDefaultDataFormatter = (dataType?: ChartDataType) => {
1819
}
1920
};
2021

22+
// Values in y axis won't be null and will always be present and properly formatted
23+
// EMPTY_DATA_PLACEHOLDER is actually empty data format for values in a tooltip
2124
function formatChartValueToMs(value: ChartValue) {
25+
if (value === null) {
26+
return EMPTY_DATA_PLACEHOLDER;
27+
}
2228
return formatToMs(roundToPrecision(convertToNumber(value), 2));
2329
}
2430

2531
function formatChartValueToSize(value: ChartValue) {
32+
if (value === null) {
33+
return EMPTY_DATA_PLACEHOLDER;
34+
}
2635
return formatBytes({value: convertToNumber(value), precision: 3});
2736
}
2837

src/components/MetricChart/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface MetricDescription {
1515
}
1616

1717
export interface PreparedMetric extends MetricDescription {
18-
data: number[];
18+
data: (number | null)[];
1919
}
2020

2121
export interface PreparedMetricsData {

src/utils/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export const COLORS_PRIORITY = {
7171

7272
export const TENANT_OVERVIEW_TABLES_LIMIT = 5;
7373

74+
export const EMPTY_DATA_PLACEHOLDER = '—';
75+
7476
// ==== Titles ====
7577
export const DEVELOPER_UI_TITLE = 'Developer UI';
7678
export const CLUSTER_DEFAULT_TITLE = 'Cluster';

0 commit comments

Comments
 (0)