All files / widgets/data-table config-item.js

0% Statements 0/34
0% Branches 0/10
0% Functions 0/7
0% Lines 0/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                                                   
import React from 'react'
import Col from './col'
 
class ConfigItem {
 
  constructor (config) {
    this.config = config
    this.visible = ('visible' in config) ? config.visible : true
  }
 
  isVisible = () => {
    return this.visible
  }
 
  getValue = (data) => {
    const { attribute, renderCol } = this.config
 
    return renderCol ? renderCol(data) : data[attribute]
  }
 
  renderHeaderCol = () => {
    const { width, labelHeader, attribute, bordered } = this.config
 
    return (
      <Col key={attribute} width={width} bordered={bordered}>
        {labelHeader}
      </Col>
    )
  }
 
  renderDataCol = (data) => {
    const { width, attribute, bordered } = this.config
    return (
      <Col key={attribute} width={width} bordered={bordered}>
        {this.getValue(data)}
      </Col>
    )
  }
}
 
export default ConfigItem