Files
AdGuardHome/client/src/components/Settings/Clients/AutoClients.js
Ildar Kamalov 6a36615629 6206 get table page size from local storage
Updates #6206

Squashed commit of the following:

commit 03089136a749fbda7da9be1af5997a24738eabb6
Merge: 7078c449c 3ce3c41b5
Author: Ildar Kamalov <ik@adguard.com>
Date:   Wed Oct 11 15:25:11 2023 +0300

    Merge branch 'master' into ADG-7558

commit 7078c449cb02039b47bdd085de12145b6982ea2c
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Oct 9 19:47:58 2023 +0300

    fix default page size

commit 64569487a916797bbb42246eb935f1388626590e
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Oct 9 19:47:22 2023 +0300

    remove unused

commit 17614fa76b5aab617b807e226f743b9fd461c247
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Oct 9 19:30:22 2023 +0300

    ADG-7473 get table page size from local storage
2023-10-11 16:17:33 +03:00

114 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import ReactTable from 'react-table';
import Card from '../../ui/Card';
import CellWrap from '../../ui/CellWrap';
import whoisCell from './whoisCell';
import LogsSearchLink from '../../ui/LogsSearchLink';
import { sortIp } from '../../../helpers/helpers';
import { LocalStorageHelper, LOCAL_STORAGE_KEYS } from '../../../helpers/localStorageHelper';
const COLUMN_MIN_WIDTH = 200;
class AutoClients extends Component {
columns = [
{
Header: this.props.t('table_client'),
accessor: 'ip',
minWidth: COLUMN_MIN_WIDTH,
Cell: CellWrap,
sortMethod: sortIp,
},
{
Header: this.props.t('table_name'),
accessor: 'name',
minWidth: COLUMN_MIN_WIDTH,
Cell: CellWrap,
},
{
Header: this.props.t('source_label'),
accessor: 'source',
minWidth: COLUMN_MIN_WIDTH,
Cell: CellWrap,
},
{
Header: this.props.t('whois'),
accessor: 'whois_info',
minWidth: COLUMN_MIN_WIDTH,
Cell: whoisCell(this.props.t),
},
{
Header: this.props.t('requests_count'),
accessor: (row) => this.props.normalizedTopClients.auto[row.ip] || 0,
sortMethod: (a, b) => b - a,
id: 'statistics',
minWidth: COLUMN_MIN_WIDTH,
Cell: (row) => {
const { value: clientStats } = row;
if (clientStats) {
return (
<div className="logs__row">
<div className="logs__text" title={clientStats}>
<LogsSearchLink search={row.original.ip}>
{clientStats}
</LogsSearchLink>
</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,
},
]}
className="-striped -highlight card-table-overflow"
showPagination
defaultPageSize={LocalStorageHelper.getItem(LOCAL_STORAGE_KEYS.AUTO_CLIENTS_PAGE_SIZE) || 10}
onPageSizeChange={(size) => (
LocalStorageHelper.setItem(LOCAL_STORAGE_KEYS.AUTO_CLIENTS_PAGE_SIZE, size)
)}
minRows={5}
ofText="/"
previousText={t('previous_btn')}
nextText={t('next_btn')}
pageText={t('page_table_footer_text')}
rowsText={t('rows_table_footer_text')}
loadingText={t('loading_table_status')}
noDataText={t('clients_not_found')}
/>
</Card>
);
}
}
AutoClients.propTypes = {
t: PropTypes.func.isRequired,
autoClients: PropTypes.array.isRequired,
normalizedTopClients: PropTypes.object.isRequired,
};
export default withTranslation()(AutoClients);