Skip to content

Commit 1a37c27

Browse files
committed
fix(Overview): format undefined values to empty string, not 0
1 parent 8c9228e commit 1a37c27

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/containers/Tenant/Schema/SchemaInfoViewer/SchemaInfoViewer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import cn from 'bem-cn-lite';
44
import './SchemaInfoViewer.scss';
55

6-
import {formatCPU, formatBytes, formatNumber, formatBps} from '../../../../utils';
6+
import {formatCPU, formatBytes, formatNumber, formatBps, formatDateTime} from '../../../../utils';
77

88
import {InfoViewer, createInfoFormatter} from '../../../../components/InfoViewer';
99

@@ -38,8 +38,8 @@ const formatTableStatsItem = createInfoFormatter({
3838
values: {
3939
DataSize: formatBytes,
4040
IndexSize: formatBytes,
41-
LastAccessTime: (value) => value > 0 ? new Date(Number(value)).toUTCString() : 'N/A',
42-
LastUpdateTime: (value) => value > 0 ? new Date(Number(value)).toUTCString() : 'N/A',
41+
LastAccessTime: formatDateTime,
42+
LastUpdateTime: formatDateTime,
4343
},
4444
defaultValueFormatter: formatNumber,
4545
});

src/utils/index.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import numeral from 'numeral';
2+
import locales from 'numeral/locales'; // eslint-disable-line no-unused-vars
23
import _ from 'lodash';
34

45
import {i18n} from './i18n';
56
import {MEGABYTE, TERABYTE, DAY_IN_SECONDS, GIGABYTE} from './constants';
6-
7-
import locales from 'numeral/locales'; // eslint-disable-line no-unused-vars
7+
import {isNumeric} from './utils';
88

99
numeral.locale(i18n.lang);
1010

1111
export const formatBytes = (bytes) => {
12+
if (!isNumeric(bytes)) {
13+
return '';
14+
}
15+
1216
// by agreement, display byte values in decimal scale
1317
return numeral(bytes).format('0 b');
1418
};
@@ -53,13 +57,29 @@ export const formatThroughput = (value, total) => {
5357
};
5458

5559
export const formatNumber = (number) => {
60+
if (!isNumeric(number)) {
61+
return '';
62+
}
63+
5664
return numeral(number).format();
5765
};
5866

5967
export const formatCPU = (value) => {
68+
if (!isNumeric(value)) {
69+
return '';
70+
}
71+
6072
return numeral(value / 1000000).format('0.00');
6173
};
6274

75+
export const formatDateTime = (value) => {
76+
if (!isNumeric(value)) {
77+
return '';
78+
}
79+
80+
return value > 0 ? new Date(Number(value)).toUTCString() : 'N/A';
81+
};
82+
6383
export const calcUptime = (milliseconds) => {
6484
const currentDate = new Date();
6585
return formatUptime((currentDate - Number(milliseconds)) / 1000);

0 commit comments

Comments
 (0)