2019-05-23 11:14:22 +00:00
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { withNamespaces } from 'react-i18next';
|
|
|
|
|
import ReactTable from 'react-table';
|
|
|
|
|
|
|
|
|
|
import Card from '../../ui/Card';
|
2019-09-23 13:01:51 +00:00
|
|
|
|
import WhoisCell from './WhoisCell';
|
|
|
|
|
import WrapCell from './WrapCell';
|
2019-05-23 11:14:22 +00:00
|
|
|
|
|
|
|
|
|
class AutoClients extends Component {
|
|
|
|
|
getStats = (ip, stats) => {
|
2019-08-22 13:10:47 +00:00
|
|
|
|
if (stats) {
|
|
|
|
|
const statsForCurrentIP = stats.find(item => item.name === ip);
|
|
|
|
|
return statsForCurrentIP && statsForCurrentIP.count;
|
2019-05-23 11:14:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
columns = [
|
|
|
|
|
{
|
|
|
|
|
Header: this.props.t('table_client'),
|
|
|
|
|
accessor: 'ip',
|
2019-09-23 13:01:51 +00:00
|
|
|
|
Cell: WrapCell,
|
2019-05-23 11:14:22 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Header: this.props.t('table_name'),
|
|
|
|
|
accessor: 'name',
|
2019-09-23 13:01:51 +00:00
|
|
|
|
Cell: WrapCell,
|
2019-05-23 11:14:22 +00:00
|
|
|
|
},
|
2019-05-23 13:27:54 +00:00
|
|
|
|
{
|
|
|
|
|
Header: this.props.t('source_label'),
|
|
|
|
|
accessor: 'source',
|
2019-09-23 13:01:51 +00:00
|
|
|
|
Cell: WrapCell,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Header: this.props.t('whois'),
|
|
|
|
|
accessor: 'whois_info',
|
|
|
|
|
Cell: WhoisCell,
|
2019-05-23 13:27:54 +00:00
|
|
|
|
},
|
2019-05-23 11:14:22 +00:00
|
|
|
|
{
|
2019-08-22 13:10:47 +00:00
|
|
|
|
Header: this.props.t('requests_count'),
|
2019-05-23 11:14:22 +00:00
|
|
|
|
accessor: 'statistics',
|
|
|
|
|
Cell: (row) => {
|
|
|
|
|
const clientIP = row.original.ip;
|
2019-08-22 13:10:47 +00:00
|
|
|
|
const clientStats = clientIP && this.getStats(clientIP, this.props.topClients);
|
2019-05-23 11:14:22 +00:00
|
|
|
|
|
|
|
|
|
if (clientStats) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="logs__row">
|
|
|
|
|
<div className="logs__text" title={clientStats}>
|
|
|
|
|
{clientStats}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '–';
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { t, autoClients } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card
|
|
|
|
|
title={t('auto_clients_title')}
|
|
|
|
|
subtitle={t('auto_clients_desc')}
|
|
|
|
|
bodyType="card-body box-body--settings"
|
|
|
|
|
>
|
|
|
|
|
<ReactTable
|
|
|
|
|
data={autoClients || []}
|
|
|
|
|
columns={this.columns}
|
|
|
|
|
className="-striped -highlight card-table-overflow"
|
|
|
|
|
showPagination={true}
|
|
|
|
|
defaultPageSize={10}
|
|
|
|
|
minRows={5}
|
|
|
|
|
previousText={t('previous_btn')}
|
|
|
|
|
nextText={t('next_btn')}
|
|
|
|
|
loadingText={t('loading_table_status')}
|
|
|
|
|
pageText={t('page_table_footer_text')}
|
|
|
|
|
ofText={t('of_table_footer_text')}
|
|
|
|
|
rowsText={t('rows_table_footer_text')}
|
|
|
|
|
noDataText={t('clients_not_found')}
|
|
|
|
|
/>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoClients.propTypes = {
|
|
|
|
|
t: PropTypes.func.isRequired,
|
|
|
|
|
autoClients: PropTypes.array.isRequired,
|
2019-08-22 13:10:47 +00:00
|
|
|
|
topClients: PropTypes.array.isRequired,
|
2019-05-23 11:14:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default withNamespaces()(AutoClients);
|