diff --git a/src/components/InterfaceStatistics/StatisticsChartList.js b/src/components/InterfaceStatistics/StatisticsChartList.js
index a30f993..9c291bd 100644
--- a/src/components/InterfaceStatistics/StatisticsChartList.js
+++ b/src/components/InterfaceStatistics/StatisticsChartList.js
@@ -4,11 +4,11 @@ import { useTranslation } from 'react-i18next';
import { v4 as createUuid } from 'uuid';
import axiosInstance from 'utils/axiosInstance';
import { useAuth, useDevice } from 'ucentral-libs';
-import { unixToTime, capitalizeFirstLetter } from 'utils/helper';
+import { capitalizeFirstLetter, dateToUnix, prettyDate } from 'utils/helper';
import eventBus from 'utils/eventBus';
import DeviceStatisticsChart from './DeviceStatisticsChart';
-const StatisticsChartList = ({ setOptions, section }) => {
+const StatisticsChartList = ({ setOptions, section, start, end }) => {
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const { currentToken, endpoints } = useAuth();
@@ -52,7 +52,7 @@ const StatisticsChartList = ({ setOptions, section }) => {
// Just building the array for all the interfaces
for (const log of sortedData) {
- categories.push(unixToTime(log.recorded));
+ categories.push(prettyDate(log.recorded));
for (const logInterface of log.data.interfaces) {
if (interfaceTypes[logInterface.name] === undefined) {
interfaceTypes[logInterface.name] = i;
@@ -93,7 +93,6 @@ const StatisticsChartList = ({ setOptions, section }) => {
const interfaceOptions = {
chart: {
id: 'chart',
- group: 'txrx',
},
stroke: {
curve: 'smooth',
@@ -141,7 +140,6 @@ const StatisticsChartList = ({ setOptions, section }) => {
},
},
categories,
- tickAmount: 20,
},
yaxis: {
min: 0,
@@ -174,7 +172,7 @@ const StatisticsChartList = ({ setOptions, section }) => {
value: opt[0].titleName,
label: opt[0].titleName,
}));
- setOptions([...sectionOptions, { value: 'memory', label: t('statistics.memory') }]);
+ setOptions([{ value: 'memory', label: t('statistics.memory') }, ...sectionOptions]);
setStatOptions({ ...newOptions });
}
};
@@ -217,11 +215,22 @@ const StatisticsChartList = ({ setOptions, section }) => {
Accept: 'application/json',
Authorization: `Bearer ${currentToken}`,
},
+ params: {},
};
+ let extraParams = '';
+ if (start !== '' && end !== '') {
+ const utcStart = new Date(start).toISOString();
+ const utcEnd = new Date(end).toISOString();
+ options.params.startDate = dateToUnix(utcStart);
+ options.params.endDate = dateToUnix(utcEnd);
+ } else {
+ extraParams = '?newest=true&limit=50';
+ }
+
axiosInstance
.get(
- `${endpoints.owgw}/api/v1/device/${deviceSerialNumber}/statistics?newest=true&limit=50`,
+ `${endpoints.owgw}/api/v1/device/${deviceSerialNumber}/statistics${extraParams}`,
options,
)
.then((response) => {
@@ -232,10 +241,10 @@ const StatisticsChartList = ({ setOptions, section }) => {
};
useEffect(() => {
- if (deviceSerialNumber) {
+ if (deviceSerialNumber && ((start !== '' && end !== '') || (start === '' && end === ''))) {
getStatistics();
}
- }, [deviceSerialNumber]);
+ }, [deviceSerialNumber, start, end]);
useEffect(() => {
eventBus.on('refreshInterfaceStatistics', () => getStatistics());
@@ -277,6 +286,8 @@ const StatisticsChartList = ({ setOptions, section }) => {
StatisticsChartList.propTypes = {
setOptions: PropTypes.func.isRequired,
section: PropTypes.string.isRequired,
+ start: PropTypes.string.isRequired,
+ end: PropTypes.string.isRequired,
};
export default React.memo(StatisticsChartList);
diff --git a/src/components/InterfaceStatistics/index.js b/src/components/InterfaceStatistics/index.js
index 25070ec..98c52e4 100644
--- a/src/components/InterfaceStatistics/index.js
+++ b/src/components/InterfaceStatistics/index.js
@@ -1,7 +1,16 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { v4 as createUuid } from 'uuid';
-import { CCard, CCardHeader, CCardBody, CPopover, CButton, CSelect } from '@coreui/react';
+import {
+ CCard,
+ CCardHeader,
+ CCardBody,
+ CPopover,
+ CButton,
+ CSelect,
+ CFormText,
+} from '@coreui/react';
+import DatePicker from 'react-widgets/DatePicker';
import { cilSync } from '@coreui/icons';
import CIcon from '@coreui/icons-react';
import eventBus from 'utils/eventBus';
@@ -15,6 +24,10 @@ const DeviceStatisticsCard = () => {
const [showLifetimeModal, setShowLifetimeModal] = useState(false);
const [options, setOptions] = useState([]);
const [section, setSection] = useState('memory');
+ const [start, setStart] = useState('');
+ const [startError, setStartError] = useState(false);
+ const [end, setEnd] = useState('');
+ const [endError, setEndError] = useState(false);
const toggleLatestModal = () => {
setShowLatestModal(!showLatestModal);
@@ -24,6 +37,28 @@ const DeviceStatisticsCard = () => {
setShowLifetimeModal(!showLifetimeModal);
};
+ const modifyStart = (value) => {
+ try {
+ new Date(value).toISOString();
+ setStartError(false);
+ setStart(value);
+ } catch (e) {
+ setStart('');
+ setStartError(true);
+ }
+ };
+
+ const modifyEnd = (value) => {
+ try {
+ new Date(value).toISOString();
+ setEndError(false);
+ setEnd(value);
+ } catch (e) {
+ setEnd('');
+ setEndError(true);
+ }
+ };
+
const refresh = () => {
eventBus.dispatch('refreshInterfaceStatistics', { message: 'Refresh interface statistics' });
};
@@ -64,10 +99,24 @@ const DeviceStatisticsCard = () => {
))}
+
+ modifyEnd(date)} />
+
+ {t('common.invalid_date_explanation')}
+
+
+ To:
+
+ modifyStart(date)} />
+
+ {t('common.invalid_date_explanation')}
+
+
+ From:
-
+