All files / widgets/data-table index.js

0% Statements 0/72
0% Branches 0/35
0% Functions 0/15
0% Lines 0/19
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112                                                                                                                                                                                                                               
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Table, Pagination } from 'src'
import ConfigItem from './config-item'
import Headers from './headers'
import Rows from './rows'
import styled from 'styled-components'
 
const DataTableStyled = styled.div`
  position: relative;
 
  .tableHeader{
    padding: 0;
  }
 
  .tableFooter{
    height: 80px;
    display: flex;
    align-items: center;
    position: relative;
  }
 
  .pageCount{
    position: absolute;
    right: 0;
 
    > span{
      color:#000;
      font-size: 14px;
    }
  }
`
 
class DataTable extends Component {
 
  state = {
    columns: []
  }
 
  componentDidMount () {
    this.normalizeData(this.props)
  }
 
  componentWillReceiveProps (props) {
    this.normalizeData(props)
  }
 
  normalizeData = ({ columns }) => {
    this.setState({
      columns: columns.map(item => new ConfigItem(item))
    })
  }
 
  render () {
    const {
      paintBorderRow,
      data = [],
      isLoading,
      onClickPage,
      onClickNextPage,
      onClickPreviousPage,
      page,
      totalCount,
      countPages,
      renderEmpty
     } = this.props
    const { columns } = this.state
 
    return (
      <DataTableStyled>
        <Table>
          <Headers columns={columns} />
          <Rows
            list={data}
            columns={columns}
            paintBorderRow={paintBorderRow}
          />
        </Table>
        <div className="tableFooter">
          <Pagination
            onClickPage={onClickPage}
            onClickNextPage={onClickNextPage}
            onClickPreviousPage={onClickPreviousPage}
            total={countPages}
            activePage={page}
          />
          <div className="pageCount">
            <span>Total de registros: {totalCount}</span>
          </div>
        </div>
        {/* <If test={data.length === 0 && !isLoading && renderEmpty}>{renderEmpty}</If> */}
      </DataTableStyled>
    )
  }
}
 
DataTable.propTypes = {
  blankslate: PropTypes.node,
  paintBorderRow: PropTypes.object,
  columns: PropTypes.array,
  isLoading: PropTypes.bool,
  onClickPage: PropTypes.func,
  onClickNextPage: PropTypes.func,
  onClickPreviousPage: PropTypes.func,
  page: PropTypes.number,
  totalCount: PropTypes.number,
  countPages: PropTypes.number,
  renderEmpty: PropTypes.node
}
 
export { DataTable }