all files / src/welcome/ DashboardTable.jsx

85.71% Statements 24/28
57.14% Branches 8/14
66.67% Functions 4/6
86.36% Lines 19/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                                                                                                          
EI/* eslint no-unused-vars: 0 */
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { Table, Tr, Td, Thead, Th, unsafe } from 'reactable';
 
import '../../stylesheets/reactable-pagination.css';
 
const $ = window.$ = require('jquery');
 
const propTypes = {
  search: PropTypes.string,
};
 
export default class DashboardTable extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      dashboards: false,
    };
  }
  componentDidMount() {
    const url = (
      '/dashboardmodelviewasync/api/read' +
      '?_oc_DashboardModelViewAsync=changed_on' +
      '&_od_DashboardModelViewAsync=desc');
    $.getJSON(url, (data) => {
      this.setState({ dashboards: data.result });
    });
  }
  render() {
    if (Ithis.state.dashboards) {
      return (
        <Table
          className="table"
          sortable={['dashboard', 'creator', 'modified']}
          filterBy={this.props.search}
          filterable={['dashboard', 'creator']}
          itemsPerPage={50}
          hideFilterInput
          columns={[
            { key: 'dashboard', label: 'Dashboard' },
            { key: 'creator', label: 'Creator' },
            { key: 'modified', label: 'Modified' },
          ]}
          defaultSort={{ column: 'modified', direction: 'desc' }}
        >
          {this.state.dashboards.map(o => (
            <Tr key={o.id}>
              <Td column="dashboard" value={o.dashboard_title}>
                <a href={o.url}>{o.dashboard_title}</a>
              </Td>
              <Td column="creator" value={o.changed_by_name}>
                {unsafe(o.creator)}
              </Td>
              <Td column="modified" value={o.changed_on} className="text-muted">
                {unsafe(o.modified)}
              </Td>
            </Tr>))}
        </Table>
      );
    }
    return (
      <img
        className="loading"
        alt="Loading..."
        src="/static/assets/images/loading.gif"
      />);
  }
}
DashboardTable.propTypes = propTypes;