mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 14:35:48 +03:00
Merge - client: fix logic of top clients normalization
Close #1294 * commit '392535ce3aad89fad52074399ec7b6986de8c4e9': - client: change code style of top clients normalization helper - client: fix logic of top clients normalization
This commit is contained in:
commit
c23c323b1a
4 changed files with 27 additions and 7 deletions
|
@ -38,7 +38,7 @@ class AutoClients extends Component {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: this.props.t('requests_count'),
|
Header: this.props.t('requests_count'),
|
||||||
accessor: row => this.props.normalizedTopClients[row.ip] || 0,
|
accessor: row => this.props.normalizedTopClients.auto[row.ip] || 0,
|
||||||
sortMethod: (a, b) => b - a,
|
sortMethod: (a, b) => b - a,
|
||||||
id: 'statistics',
|
id: 'statistics',
|
||||||
minWidth: COLUMN_MIN_WIDTH,
|
minWidth: COLUMN_MIN_WIDTH,
|
||||||
|
|
|
@ -40,6 +40,7 @@ class ClientsTable extends Component {
|
||||||
} else {
|
} else {
|
||||||
this.handleFormAdd(config);
|
this.handleFormAdd(config);
|
||||||
}
|
}
|
||||||
|
this.props.getStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
getClient = (name, clients) => {
|
getClient = (name, clients) => {
|
||||||
|
@ -64,6 +65,7 @@ class ClientsTable extends Component {
|
||||||
// eslint-disable-next-line no-alert
|
// eslint-disable-next-line no-alert
|
||||||
if (window.confirm(this.props.t('client_confirm_delete', { key: data.name }))) {
|
if (window.confirm(this.props.t('client_confirm_delete', { key: data.name }))) {
|
||||||
this.props.deleteClient(data);
|
this.props.deleteClient(data);
|
||||||
|
this.props.getStats();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,7 +163,7 @@ class ClientsTable extends Component {
|
||||||
{
|
{
|
||||||
Header: this.props.t('requests_count'),
|
Header: this.props.t('requests_count'),
|
||||||
id: 'statistics',
|
id: 'statistics',
|
||||||
accessor: row => this.props.normalizedTopClients[row.name] || 0,
|
accessor: row => this.props.normalizedTopClients.configured[row.name] || 0,
|
||||||
sortMethod: (a, b) => b - a,
|
sortMethod: (a, b) => b - a,
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
Cell: (row) => {
|
Cell: (row) => {
|
||||||
|
@ -305,6 +307,7 @@ ClientsTable.propTypes = {
|
||||||
processingAdding: PropTypes.bool.isRequired,
|
processingAdding: PropTypes.bool.isRequired,
|
||||||
processingDeleting: PropTypes.bool.isRequired,
|
processingDeleting: PropTypes.bool.isRequired,
|
||||||
processingUpdating: PropTypes.bool.isRequired,
|
processingUpdating: PropTypes.bool.isRequired,
|
||||||
|
getStats: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withNamespaces()(ClientsTable);
|
export default withNamespaces()(ClientsTable);
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Clients extends Component {
|
||||||
updateClient,
|
updateClient,
|
||||||
deleteClient,
|
deleteClient,
|
||||||
toggleClientModal,
|
toggleClientModal,
|
||||||
|
getStats,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -44,6 +45,7 @@ class Clients extends Component {
|
||||||
processingAdding={clients.processingAdding}
|
processingAdding={clients.processingAdding}
|
||||||
processingDeleting={clients.processingDeleting}
|
processingDeleting={clients.processingDeleting}
|
||||||
processingUpdating={clients.processingUpdating}
|
processingUpdating={clients.processingUpdating}
|
||||||
|
getStats={getStats}
|
||||||
/>
|
/>
|
||||||
<AutoClients
|
<AutoClients
|
||||||
autoClients={dashboard.autoClients}
|
autoClients={dashboard.autoClients}
|
||||||
|
|
|
@ -261,12 +261,27 @@ export const redirectToCurrentProtocol = (values, httpPort = 80) => {
|
||||||
|
|
||||||
export const normalizeTextarea = text => text && text.replace(/[;, ]/g, '\n').split('\n').filter(n => n);
|
export const normalizeTextarea = text => text && text.replace(/[;, ]/g, '\n').split('\n').filter(n => n);
|
||||||
|
|
||||||
export const normalizeTopClients = clients => clients.reduce((accumulator, clientObj) => {
|
/**
|
||||||
const { name, count } = clientObj;
|
* Normalizes the topClients array
|
||||||
|
*
|
||||||
|
* @param {Object[]} topClients
|
||||||
|
* @param {string} topClients.name
|
||||||
|
* @param {number} topClients.count
|
||||||
|
* @param {Object} topClients.info
|
||||||
|
* @param {string} topClients.info.name
|
||||||
|
* @returns {Object} normalizedTopClients
|
||||||
|
* @returns {Object.<string, number>} normalizedTopClients.auto - auto clients
|
||||||
|
* @returns {Object.<string, number>} normalizedTopClients.configured - configured clients
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const normalizeTopClients = topClients => topClients.reduce((nameToCountMap, clientObj) => {
|
||||||
|
const { name, count, info: { name: infoName } } = clientObj;
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
accumulator[name] = count;
|
nameToCountMap.auto[name] = count;
|
||||||
return accumulator;
|
// eslint-disable-next-line no-param-reassign
|
||||||
}, {});
|
nameToCountMap.configured[infoName] = count;
|
||||||
|
return nameToCountMap;
|
||||||
|
}, { auto: {}, configured: {} });
|
||||||
|
|
||||||
export const getClientInfo = (clients, ip) => {
|
export const getClientInfo = (clients, ip) => {
|
||||||
const client = clients
|
const client = clients
|
||||||
|
|
Loading…
Reference in a new issue