Skip to content
Snippets Groups Projects
GridCell.jsx 3.55 KiB
Newer Older
  • Learn to ignore specific revisions
  • import _ from 'lodash'
    import React from 'react'
    import { withStyles } from '@material-ui/core/styles'
    import TableCell from '@material-ui/core/TableCell'
    
    import Link from '@material-ui/core/Link'
    import messages from '@src/js/common/messages.js'
    
        paddingTop: theme.spacing(1),
        paddingBottom: theme.spacing(1),
    
        paddingLeft: 0,
        paddingRight: theme.spacing(2),
    
        borderColor: theme.palette.border.secondary,
        '&:empty:before': {
          content: '"\\a0"'
        }
    
      },
      truncateWithMore: {
        maxHeight: TRUNCATE_HEIGHT - MORE_HEIGHT + 'px',
    
      }
    })
    
    class GridCell extends React.PureComponent {
      constructor(props) {
        super(props)
    
        this.handleMoreClick = this.handleMoreClick.bind(this)
    
        const { column, row, onMeasured } = this.props
        if (column.truncate && this.ref.current) {
    
        const { column, height, className, classes } = this.props
    
    
        const cellClasses = [classes.cell]
    
        const divClasses = []
        if (column.nowrap) {
          divClasses.push(classes.nowrap)
        }
    
          if (height && height > TRUNCATE_HEIGHT) {
            divClasses.push(classes.truncateWithMore)
          } else {
            divClasses.push(classes.truncate)
          }
    
          <TableCell key={column.name} classes={{ root: cellClasses.join(' ') }}>
            <div ref={this.ref} className={divClasses.join(' ')}>
              {column.renderDOMValue ? null : this.renderValue()}
            </div>
            {this.renderMore()}
    
        const value = column.getValue({ row, column, operation: 'render' })
    
        const renderedValue = column.renderValue
          ? column.renderValue({
              value,
              row,
    
            })
          : value
    
        if (renderedValue === null || renderedValue === undefined) {
    
        } else if (_.isNumber(renderedValue) || _.isBoolean(renderedValue)) {
          return String(renderedValue)
        } else {
          return renderedValue
        }
      }
    
        if (column.renderDOMValue && this.ref.current) {
    
          const value = column.getValue({ row, column, operation: 'render' })
    
          column.renderDOMValue({
            container: this.ref.current,
            value,
            row,
    
        const { column, height } = this.props
        const { more } = this.state
    
        if (column.truncate && height && height > TRUNCATE_HEIGHT) {
    
          return (
            <div>
              <Link onClick={this.handleMoreClick}>
                {more ? messages.get(messages.LESS) : messages.get(messages.MORE)}
              </Link>
            </div>
          )
        } else {
          return null