badguardhome/client/src/components/Settings/Clients/AutoClients.js

99 lines
2.9 KiB
JavaScript
Raw Normal View History

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';
import WhoisCell from './WhoisCell';
import WrapCell from './WrapCell';
2019-05-23 11:14:22 +00:00
class AutoClients extends Component {
getStats = (ip, stats) => {
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',
Cell: WrapCell,
2019-05-23 11:14:22 +00:00
},
{
Header: this.props.t('table_name'),
accessor: 'name',
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',
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
{
Header: this.props.t('requests_count'),
2019-05-23 11:14:22 +00:00
accessor: 'statistics',
Cell: (row) => {
const clientIP = row.original.ip;
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,
topClients: PropTypes.array.isRequired,
2019-05-23 11:14:22 +00:00
};
export default withNamespaces()(AutoClients);