All files / web/modules/admin/reports Reports.tsx

0% Statements 0/18
100% Branches 0/0
0% Functions 0/4
0% Lines 0/14

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                                                                                                   
import * as React from 'react';
import { Query } from 'react-apollo';
import { getArticlePath } from '../../article/utils';
import Link from '../../components/Link';
import Table from '../../components/Table';
import { SETTINGS_MOST_VISITED } from '../queries';
 
const columns = [
  {
    title: 'Název Článku',
    dataIndex: 'article.title',
  },
  {
    title: 'Počet návštěv',
    dataIndex: 'value',
  },
  {
    title: 'Akce',
    dataIndex: 'article.slug',
    render: (text: string, mostVisited: any) => (
      <Link to={getArticlePath(mostVisited.article)}>zobrazit</Link>
    ),
  },
];
 
const getRowKey = (mostVisited: any) => mostVisited.article._id;
 
const Reports = () => (
  <Query query={SETTINGS_MOST_VISITED}>
    {({ loading, error, data }) => {
      if (error) {
        console.log(error);
        return null; // TODO: show error
      }
      return (
        <React.Fragment>
          <Table
            rowKey={getRowKey}
            loading={loading}
            dataSource={data.mostVisited}
            columns={columns}
          />
        </React.Fragment>
      );
    }}
  </Query>
);
 
export default Reports;