All files / src/components DatatableContainer.js

100% Statements 7/7
96% Branches 24/25
100% Functions 2/2
100% Lines 7/7

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 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145                                                            8x                       8x   8x                     8x                                                                                                                             3x                     3x 8x                            
import React, { Component, Fragment } from "react";
import { connect } from "react-redux";
import { ScrollSync, ScrollSyncPane } from "react-scroll-sync";
import Header from "./DatatableCore/Header/Header";
import Body from "./DatatableCore/Body/Body";
import DatatableHeader from "./DatatableHeader/DatatableHeader";
import DatatableFooter from "./DatatableFooter/DatatableFooter";
import Notifier from "./Notifier";
import Loader from "./Loader";
import {
  dataPropType,
  heightNumberPropType,
  widthNumberPropType,
  featuresPropType,
  titlePropType,
  isRefreshingPropType,
  columnSizeMultiplierPropType
} from "../proptypes";
 
class DatatableContainer extends Component {
  render() {
    const {
      data,
      height,
      columnSizeMultiplier,
      width,
      features,
      title,
      totalWidthNumber,
      isRefreshing
    } = this.props;
 
    const {
      canGlobalEdit,
      canPrint,
      canDownload,
      canSearch,
      canRefreshRows,
      canOrderColumns,
      canSaveUserConfiguration,
      additionalIcons,
      selectionIcons
    } = features;
    const hasHeader =
      canGlobalEdit ||
      canPrint ||
      canDownload ||
      canSearch ||
      canRefreshRows ||
      canOrderColumns ||
      canSaveUserConfiguration ||
      title.length > 0 ||
      additionalIcons.length > 0 ||
      selectionIcons.length > 0;
 
    return (
      <Fragment>
        <ScrollSync>
          <div id="o2xp" style={{ width }}>
            {hasHeader && <DatatableHeader />}
 
            <div className="Table">
              {data.columns.length > 0 && (
                <Fragment>
                  <Header />
                  {data.rows.length > 0 && !isRefreshing && <Body />}
                </Fragment>
              )}
              {(data.columns.length === 0 || data.rows.length === 0) &&
                !isRefreshing && (
                  <Fragment>
                    <div
                      id="no-rows"
                      style={{ height: height - 15, width: width - 15 }}
                    >
                      There is no data yet, try to refresh <span> .</span>
                      <span>.</span>
                      <span>.</span>
                    </div>
                    <ScrollSyncPane>
                      <div
                        style={{
                          overflowX:
                            columnSizeMultiplier === 1 ? "scroll" : "hidden",
                          overflowY: "hidden",
                          height: "15px",
                          width: width - 15
                        }}
                      >
                        <div
                          style={{
                            width: totalWidthNumber
                          }}
                        >
                          .
                        </div>
                      </div>
                    </ScrollSyncPane>
                  </Fragment>
                )}
 
              {isRefreshing &&
                Loader({
                  height,
                  width,
                  columnSizeMultiplier,
                  totalWidthNumber
                })}
            </div>
            <DatatableFooter />
          </div>
        </ScrollSync>
        <Notifier />
      </Fragment>
    );
  }
}
 
DatatableContainer.propTypes = {
  data: dataPropType.isRequired,
  height: heightNumberPropType.isRequired,
  width: widthNumberPropType.isRequired,
  isRefreshing: isRefreshingPropType.isRequired,
  totalWidthNumber: widthNumberPropType,
  features: featuresPropType,
  title: titlePropType,
  columnSizeMultiplier: columnSizeMultiplierPropType
};
 
const mapStateToProps = state => {
  return {
    data: state.datatableReducer.data,
    height: state.datatableReducer.dimensions.body.heightNumber,
    width: state.datatableReducer.dimensions.datatable.widthNumber,
    features: state.datatableReducer.features,
    title: state.datatableReducer.title,
    isRefreshing: state.datatableReducer.isRefreshing,
    totalWidthNumber:
      state.datatableReducer.dimensions.datatable.totalWidthNumber,
    columnSizeMultiplier: state.datatableReducer.dimensions.columnSizeMultiplier
  };
};
 
export default connect(mapStateToProps)(DatatableContainer);