@bigfishtv/cockpit
Version:
27 lines (24 loc) • 748 B
JavaScript
import React, { Component } from 'react'
import { Cell } from 'fixed-data-table'
import _get from 'lodash/get'
import { isObject, isArray } from '../../../utils/typeUtils'
/**
* Table cell for displaying text, the go-to default cell.
*/
export default class FixedDataTableTextCell extends Component {
render() {
const { data, rowIndex, columnKey, schema, ...props } = this.props
let value = _get(data[rowIndex], columnKey)
if (isObject(value)) {
value = _get(value, 'title') || _get(value, 'name') || null
} else if (isArray(value)) {
if (value.length) {
if (typeof value[0] == 'string') value = value.join(', ')
else value = value.length
} else {
value = ''
}
}
return <Cell {...props}>{value}</Cell>
}
}