fix(ui): render table cell as number only for numbers
parent
8528bb368f
commit
d6fb94af88
|
@ -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)
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue