fix(ui): render table cell as number only for numbers

pull/5882/head
Pavel Zavora 2022-03-14 19:29:00 +01:00
parent 8528bb368f
commit d6fb94af88
2 changed files with 7 additions and 7 deletions

View File

@ -304,14 +304,15 @@ export const transformTableData = (
- `parseFloat('02abc')` is 2
*/
export const isNumerical = <T>(x: T | string): x is string =>
!isNaN(Number(x)) && !isNaN(parseFloat(x as string))
export const isNumerical = (x: number | string): boolean =>
typeof x === 'number' || (!isNaN(Number(x)) && !isNaN(parseFloat(x)))
export const formatNumericCell = (
cellData: string,
cellData: string | number,
decimalPlaces: DecimalPlaces
) => {
const cellValue = parseFloat(cellData)
const cellValue =
typeof cellData === 'number' ? cellData : parseFloat(cellData)
if (isTruncatedNumber(cellValue, decimalPlaces)) {
return toFixed(cellValue, decimalPlaces)

View File

@ -14,7 +14,6 @@ import {fastReduce} from 'src/utils/fast'
import {ErrorHandlingWith, DefaultError} from 'src/shared/decorators/errors'
import {
getDefaultTimeField,
isNumerical,
formatNumericCell,
} from 'src/dashboards/utils/tableGraph'
@ -480,7 +479,7 @@ class TableGraph extends PureComponent<Props, State> {
return _.defaultTo(fieldName, '').toString()
}
if (isNumerical(cellData)) {
if (typeof cellData === 'number') {
return formatNumericCell(cellData, decimalPlaces)
}
@ -540,7 +539,7 @@ class TableGraph extends PureComponent<Props, State> {
const isFieldName = this.isVerticalTimeAxis ? isFirstRow : isFirstCol
const isFixedCorner = isFirstRow && isFirstCol
const cellDataIsNumerical = isNumerical(cellData)
const cellDataIsNumerical = typeof cellData === 'number'
let cellStyle: React.CSSProperties = style // tslint:disable-line
if (