All files / recent-reports/components/ReportsTable index.jsx

95.45% Statements 21/22
83.33% Branches 5/6
100% Functions 4/4
95.45% Lines 21/22
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                                        1x           1x           1x       1x                                 1x       1x 2x         1x       1x 1x               3x                         1x       1x 3x   3x   3x 2x   1x                   3x                       1x         1x            
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
 
import {
  ChartStateLoading as Loading,
  ChartCard,
  ChartHeader,
  ChartStateNoData as NoData,
} from '@bufferapp/analyze-shared-components';
 
import { Text } from '@bufferapp/components';
 
import {
  geyser,
} from '@bufferapp/components/style/color';
 
import Title from '../Title';
import ReportItem from './components/ReportItem';
 
const ChartContainer = styled.div`
  position: relative;
  border-radius: 2px;
  font-size: 12px;
`;
 
const ReportsTableWrapper = styled.table`
  padding: 0;
  margin: 0;
  width: 100%;
`;
 
const GridContainer = styled.div`
  position: relative;
`;
 
const StyledTableHeader = styled.th`
  text-align: left;
  align-items: center;
  border-top: 1px dotted ${geyser};
  border-bottom: 1px solid ${geyser};
  border-right: 1px dotted ${geyser};
  padding: 1rem;
 
  &:first-child {
    padding-left: 1.5rem;
  }
 
  &:last-child {
    border-right: none;
  }
`;
 
const StyledTableRow = styled.tr`
  box-shadow: 0 2px 2px rgba(0,0,0,0.025);
`;
 
const TableHeader = ({ children }) => (
  <StyledTableHeader>
    <Text size="mini" color="outerSpace" weight="medium">{children}</Text>
  </StyledTableHeader>
);
 
TableHeader.propTypes = {
  children: PropTypes.node.isRequired,
};
 
export const Table = ({ reports, ...props }) => (
  <ChartContainer>
    <ReportsTableWrapper>
      <tbody>
        <StyledTableRow>
          <TableHeader key={'title'}>Title</TableHeader>
          <TableHeader key={'dateRange'}>Date range</TableHeader>
        </StyledTableRow>
        {reports.length && reports.slice(0, 3).map(report =>
          <ReportItem
            title={report.name}
            dateRange={report.date_range}
            reportId={report._id}
            key={report._id}
            {...props}
          />
        )}
      </tbody>
    </ReportsTableWrapper>
  </ChartContainer>
);
 
Table.propTypes = {
  reports: PropTypes.array
};
 
const ReportsTable = ({ reports, loading, ...props }) => {
  let content = null;
 
  Iif (loading) {
    content = <Loading active noBorder />;
  } else if (reports.length === 0) {
    content = <NoData children={<Text>There are no reports</Text>}/>;
  } else {
    content = (
      <div>
        <Table
          reports={reports}
          {...props}
        />
      </div>
    );
  }
 
  return (
    <ChartCard>
      <ChartHeader>
        <Title />
      </ChartHeader>
      <GridContainer>
        {content}
      </GridContainer>
    </ChartCard>
  );
};
 
ReportsTable.defaultProps = {
  reports: [],
  loading: false,
};
 
ReportsTable.propTypes = {
  reports: PropTypes.array,
  loading: PropTypes.bool,
};
 
export default ReportsTable;