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'