All files / src/components/DatatableHeader/Widgets ExportRows.js

100% Statements 10/10
83.33% Branches 5/6
100% Functions 5/5
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                  10x 10x 10x                             1x                     5x         5x 10x 1x       5x 10x                  
import React, { Component } from "react";
import { connect } from "react-redux";
import { IconButton, Tooltip, Zoom } from "@material-ui/core";
import { CallSplit as CallSplitIcon } from "@material-ui/icons";
import { exportRowPropType, rowsSelectedPropType } from "../../../proptypes";
import { exportRow as exportRowAction } from "../../../redux/actions/datatableActions";
 
class ExportRows extends Component {
  render() {
    const { rowsSelected, exportRow } = this.props;
    const disabled = rowsSelected.length === 0;
    return (
      <Tooltip
        TransitionComponent={Zoom}
        title={
          disabled
            ? "0 row selected"
            : `Export ${rowsSelected.length} row${
                rowsSelected.length > 1 ? "s" : ""
              }`
        }
      >
        <span>
          <IconButton
            aria-label="ExportRows"
            className="export-rows"
            onClick={() => exportRow()}
            disabled={disabled}
          >
            <CallSplitIcon color={disabled ? "disabled" : "primary"} />
          </IconButton>
        </span>
      </Tooltip>
    );
  }
}
 
ExportRows.propTypes = {
  rowsSelected: rowsSelectedPropType.isRequired,
  exportRow: exportRowPropType
};
 
const mapDispatchToProps = dispatch => {
  return {
    exportRow: () => dispatch(exportRowAction())
  };
};
 
const mapStateToProps = state => {
  return {
    rowsSelected: state.datatableReducer.rowsSelected
  };
};
 
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ExportRows);