Skip to content
Snippets Groups Projects
GridRow.jsx 3.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • import React from 'react'
    import { withStyles } from '@material-ui/core/styles'
    import TableRow from '@material-ui/core/TableRow'
    
    import GridCell from '@src/js/components/common/grid/GridCell.jsx'
    
    import GridMultiselectCell from '@src/js/components/common/grid/GridMultiselectCell.jsx'
    
    import logger from '@src/js/common/logger.js'
    
    
      row: {
        backgroundColor: theme.palette.background.paper,
        '&:hover': {
          backgroundColor: '#f5f5f5'
        },
        '&:hover$selected': {
          backgroundColor: '#e8f7fd'
        }
      },
      clickable: {
        cursor: 'pointer'
      },
      selectable: {
    
      selected: {
        backgroundColor: '#e8f7fd'
      },
      multiselectable: {},
      cell: {
        backgroundColor: 'inherit',
        '&$firstCell': {
          paddingLeft: theme.spacing(2),
          position: 'sticky',
          left: 0,
          zIndex: 100
        },
        '$multiselectable &$firstCell': {
    
    })
    
    class GridRow extends React.PureComponent {
      constructor(props) {
        super(props)
    
        this.handleClick = this.handleClick.bind(this)
    
        this.handleDoubleClick = this.handleDoubleClick.bind(this)
    
        this.handleMultiselect = this.handleMultiselect.bind(this)
    
      handleClick() {
        const { clickable, selectable, onClick, onSelect, row } = this.props
    
    
      handleDoubleClick() {
        const { doubleClickable, onDoubleClick, row } = this.props
    
        if (doubleClickable && onDoubleClick) {
          onDoubleClick(row)
        }
      }
    
    
      handleMultiselect(event) {
        event.preventDefault()
        event.stopPropagation()
    
        const { multiselectable, onMultiselect, row } = this.props
    
        if (multiselectable && onMultiselect) {
          onMultiselect(row)
    
        }
      }
    
      render() {
        logger.log(logger.DEBUG, 'GridRow.render')
    
    
        const {
          multiselectable,
          columns,
          row,
          clickable,
          selectable,
          selected,
          classes
        } = this.props
    
    
        const rowClasses = [classes.row]
    
        if (multiselectable) {
          rowClasses.push(classes.multiselectable)
        }
        if (selectable) {
          rowClasses.push(classes.selectable)
        }
        if (selected) {
          rowClasses.push(classes.selected)
        }
        if (clickable) {
          rowClasses.push(classes.clickable)
        }
    
            onDoubleClick={this.handleDoubleClick}
    
            classes={{ root: rowClasses.join(' ') }}
    
            {columns.map((column, columnIndex) =>
              this.renderCell(column, columnIndex, row)
            )}
    
      renderCell(column, columnIndex, row) {
    
    
        const cellClasses = [classes.cell]
        if (columnIndex === 0) {
          cellClasses.push(classes.firstCell)
        }
    
        return (
          <GridCell
            key={column.name}
            row={row}
    
            height={heights ? heights[column.name] : undefined}
    
        const { multiselectable, multiselected } = this.props
    
            <GridMultiselectCell
              value={multiselected}
              onClick={this.handleMultiselect}
            />
    
    }
    
    export default withStyles(styles)(GridRow)