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

105 lines
3.1 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';
2019-09-26 09:17:58 +00:00
import WrapCell from './WrapCell';
2019-09-24 12:28:59 +00:00
import whoisCell from './whoisCell';
2019-09-26 09:17:58 +00:00
const COLUMN_MIN_WIDTH = 200;
2019-05-23 11:14:22 +00:00
class AutoClients extends Component {
columns = [
{
Header: this.props.t('table_client'),
accessor: 'ip',
2019-09-26 09:17:58 +00:00
minWidth: COLUMN_MIN_WIDTH,
Cell: WrapCell,
2019-05-23 11:14:22 +00:00
},
{
Header: this.props.t('table_name'),
accessor: 'name',
2019-09-26 09:17:58 +00:00
minWidth: COLUMN_MIN_WIDTH,
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-26 09:17:58 +00:00
minWidth: COLUMN_MIN_WIDTH,
Cell: WrapCell,
},
{
Header: this.props.t('whois'),
accessor: 'whois_info',
2019-09-26 09:17:58 +00:00
minWidth: COLUMN_MIN_WIDTH,
2019-09-24 12:28:59 +00:00
Cell: whoisCell(this.props.t),
2019-05-23 13:27:54 +00:00
},
2019-05-23 11:14:22 +00:00
{
Header: this.props.t('requests_count'),
accessor: row => this.props.normalizedTopClients.auto[row.ip] || 0,
sortMethod: (a, b) => b - a,
id: 'statistics',
2019-09-26 09:17:58 +00:00
minWidth: COLUMN_MIN_WIDTH,
2019-05-23 11:14:22 +00:00
Cell: (row) => {
const { value: clientStats } = row;
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}
defaultSorted={[
{
id: 'statistics',
asc: true,
},
]}
2019-05-23 11:14:22 +00:00
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="/"
2019-05-23 11:14:22 +00:00
rowsText={t('rows_table_footer_text')}
noDataText={t('clients_not_found')}
/>
</Card>
);
}
}
AutoClients.propTypes = {
t: PropTypes.func.isRequired,
autoClients: PropTypes.array.isRequired,
normalizedTopClients: PropTypes.object.isRequired,
2019-05-23 11:14:22 +00:00
};
export default withNamespaces()(AutoClients);