From 67c9abe119f749775d1e8a70a760484575b0dd83 Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Fri, 24 Mar 2023 16:49:02 +0300 Subject: [PATCH] Pull request 1782: 5630-fix-interval Merge in DNS/adguard-home from 5630-fix-interval to master Updates #5630. Squashed commit of the following: commit eb3839bb63cde40c477843cad1262c8eaa95406a Author: Ildar Kamalov Date: Fri Mar 24 16:25:23 2023 +0300 fix lint commit 1899810ba8e3d2496f35bb052aeda60da565ffa3 Merge: 52526687 2409282d Author: Ildar Kamalov Date: Fri Mar 24 16:01:50 2023 +0300 Merge branch 'master' into 5630-fix-interval commit 52526687e651254a81da091106d88b50b656af2f Author: Ildar Kamalov Date: Fri Mar 24 15:26:01 2023 +0300 convert milliseconds to days for stats interval commit e719814e84bf0ddaec8f4d47a94cc2b5075a7dc5 Author: Stanislav Chzhen Date: Fri Mar 24 14:05:55 2023 +0300 openapi: fix description --- client/src/components/Dashboard/index.js | 16 ++++++++++++---- client/src/helpers/helpers.js | 2 ++ client/src/reducers/queryLogs.js | 4 ++-- client/src/reducers/stats.js | 3 ++- openapi/openapi.yaml | 4 ++-- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/client/src/components/Dashboard/index.js b/client/src/components/Dashboard/index.js index ab8d4efc..73d9c595 100644 --- a/client/src/components/Dashboard/index.js +++ b/client/src/components/Dashboard/index.js @@ -10,7 +10,12 @@ import Clients from './Clients'; import QueriedDomains from './QueriedDomains'; import BlockedDomains from './BlockedDomains'; import { DISABLE_PROTECTION_TIMINGS, ONE_SECOND_IN_MS, SETTINGS_URLS } from '../../helpers/constants'; -import { msToSeconds, msToMinutes, msToHours } from '../../helpers/helpers'; +import { + msToSeconds, + msToMinutes, + msToHours, + msToDays, +} from '../../helpers/helpers'; import PageTitle from '../ui/PageTitle'; import Loading from '../ui/Loading'; @@ -39,13 +44,16 @@ const Dashboard = ({ getAllStats(); }, []); const getSubtitle = () => { - if (stats.interval === 0) { + const ONE_DAY = 1; + const intervalInDays = msToDays(stats.interval); + + if (intervalInDays < ONE_DAY) { return t('stats_disabled_short'); } - return stats.interval === 1 + return intervalInDays === ONE_DAY ? t('for_last_24_hours') - : t('for_last_days', { count: stats.interval }); + : t('for_last_days', { count: msToDays(stats.interval) }); }; const buttonClass = classNames('btn btn-sm dashboard-protection-button', { diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index 3806a755..d3c69054 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -402,6 +402,8 @@ export const secondsToMilliseconds = (seconds) => { return seconds; }; +export const msToDays = (milliseconds) => Math.floor(milliseconds / 1000 / 60 / 60 / 24); + export const normalizeRulesTextarea = (text) => text?.replace(/^\n/g, '') .replace(/\n\s*\n/g, '\n'); diff --git a/client/src/reducers/queryLogs.js b/client/src/reducers/queryLogs.js index 1575c62d..26d47025 100644 --- a/client/src/reducers/queryLogs.js +++ b/client/src/reducers/queryLogs.js @@ -1,7 +1,7 @@ import { handleActions } from 'redux-actions'; import * as actions from '../actions/queryLogs'; -import { DEFAULT_LOGS_FILTER } from '../helpers/constants'; +import { DEFAULT_LOGS_FILTER, DAY } from '../helpers/constants'; const queryLogs = handleActions( { @@ -86,7 +86,7 @@ const queryLogs = handleActions( processingGetConfig: false, processingSetConfig: false, processingAdditionalLogs: false, - interval: 1, + interval: DAY, logs: [], enabled: true, oldest: '', diff --git a/client/src/reducers/stats.js b/client/src/reducers/stats.js index 4f8e25f1..2e5a7e48 100644 --- a/client/src/reducers/stats.js +++ b/client/src/reducers/stats.js @@ -1,5 +1,6 @@ import { handleActions } from 'redux-actions'; import { normalizeTopClients } from '../helpers/helpers'; +import { DAY } from '../helpers/constants'; import * as actions from '../actions/stats'; @@ -91,7 +92,7 @@ const stats = handleActions( processingSetConfig: false, processingStats: true, processingReset: false, - interval: 1, + interval: DAY, ...defaultStats, }, ); diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 8dd2d6a7..21f6ef66 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1777,7 +1777,7 @@ 'description': 'Are statistics enabled' 'type': 'boolean' 'interval': - 'description': 'Statistics rotation interval' + 'description': 'Statistics rotation interval in milliseconds' 'type': 'number' 'ignored': 'description': 'List of host names, which should not be counted' @@ -2203,7 +2203,7 @@ 'description': 'Is query log enabled' 'interval': 'description': > - Time period for query log rotation. + Time period for query log rotation in milliseconds. 'type': 'number' 'anonymize_client_ip': 'type': 'boolean'