All files / recent-reports index.jsx

91.67% Statements 11/12
100% Branches 2/2
85.71% Functions 6/7
91.67% Lines 11/12
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                      1x 1x       2x 1x         3x       1x       1x         7x         4x         2x 1x              
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { push } from 'connected-react-router';
import store from '@bufferapp/analyze-store';
import { addMiddleware } from 'redux-dynamic-middlewares';
import reducer, { actions } from './reducer';
import middleware from './middleware';
 
import ReportsTable from './components/ReportsTable';
 
store.injectReducer('listReports', reducer);
addMiddleware(middleware);
 
export class RecentReports extends React.Component {
  componentDidMount() {
    if (Object.keys(this.props.reports).length === 0) {
      this.props.fetch();
    }
  }
 
  render() {
    return <ReportsTable {...this.props} />;
  }
}
 
RecentReports.defaultProps = {
  reports: []
};
 
RecentReports.propTypes = {
  reports: PropTypes.array
};
 
export function sortReportsByDateDesc(a, b) {
  return b.updated_at - a.updated_at;
}
 
export default connect(
  state => {
    return ({
      reports: state.reportList.reports.sort(sortReportsByDateDesc),
      loading: state.reportList.loading,
    })
  },
  dispatch => ({
    fetch: () => dispatch(actions.fetch()),
    openReport: id => dispatch(push(`/reports/${id}`)),
  }),
)(RecentReports);
 
export reducer from './reducer';
export middleware from './middleware';