2.5.30: fix for device statistics

This commit is contained in:
Charles
2022-01-18 19:42:08 +01:00
parent 1481626b1b
commit 3ca900af6c
5 changed files with 10 additions and 70 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ucentral-client",
"version": "2.5.29",
"version": "2.5.30",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ucentral-client",
"version": "2.5.29",
"version": "2.5.30",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",

View File

@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "2.5.29",
"version": "2.5.30",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",

View File

@@ -127,8 +127,8 @@ const StatisticsChartList = ({ setOptions, section, setStart, setEnd, time }) =>
totalTx += assoc.deltas?.tx_bytes ?? 0;
totalRx += assoc.deltas?.rx_bytes ?? 0;
} else {
totalTx += assoc.counters?.tx_bytes ?? 0;
totalRx += assoc.counters?.rx_bytes ?? 0;
totalTx += assoc.tx_bytes ?? 0;
totalRx += assoc.rx_bytes ?? 0;
}
}
}

View File

@@ -13,14 +13,12 @@ import {
import DatePicker from 'react-widgets/DatePicker';
import { cilSync } from '@coreui/icons';
import CIcon from '@coreui/icons-react';
import LifetimeStatsmodal from 'components/LifetimeStatsModal';
import StatisticsChartList from './StatisticsChartList';
import LatestStatisticsmodal from './LatestStatisticsModal';
const DeviceStatisticsCard = () => {
const { t } = useTranslation();
const [showLatestModal, setShowLatestModal] = useState(false);
const [showLifetimeModal, setShowLifetimeModal] = useState(false);
const [options, setOptions] = useState([]);
const [section, setSection] = useState('');
const [start, setStart] = useState(null);
@@ -33,10 +31,6 @@ const DeviceStatisticsCard = () => {
setShowLatestModal(!showLatestModal);
};
const toggleLifetimeModal = () => {
setShowLifetimeModal(!showLifetimeModal);
};
const modifyStart = (value) => {
try {
new Date(value).toISOString();
@@ -102,16 +96,6 @@ const DeviceStatisticsCard = () => {
</div>
From:
<div className="px-2">
<CButton size="sm" color="info" onClick={toggleLifetimeModal}>
Lifetime Statistics
</CButton>
</div>
<div className="pl-2">
<CButton size="sm" color="info" onClick={toggleLatestModal}>
{t('statistics.show_latest')}
</CButton>
</div>
<div className="pl-2">
<CSelect
custom
value={section}
@@ -125,6 +109,11 @@ const DeviceStatisticsCard = () => {
))}
</CSelect>
</div>
<div className="pl-2">
<CButton size="sm" color="info" onClick={toggleLatestModal}>
{t('statistics.show_latest')}
</CButton>
</div>
</div>
</CCardHeader>
<CCardBody className="p-1">
@@ -138,7 +127,6 @@ const DeviceStatisticsCard = () => {
</CCardBody>
</CCard>
<LatestStatisticsmodal show={showLatestModal} toggle={toggleLatestModal} />
<LifetimeStatsmodal show={showLifetimeModal} toggle={toggleLifetimeModal} />
</div>
);
};

View File

@@ -1,48 +0,0 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import axiosInstance from 'utils/axiosInstance';
import { useTranslation } from 'react-i18next';
import { LifetimeStatsModal as Modal, useAuth, useDevice } from 'ucentral-libs';
const LifetimeStatsModal = ({ show, toggle }) => {
const { t } = useTranslation();
const { currentToken, endpoints } = useAuth();
const { deviceSerialNumber } = useDevice();
const [loading, setLoading] = useState(false);
const [data, setData] = useState({});
const getData = () => {
setLoading(true);
const options = {
headers: {
Accept: 'application/json',
Authorization: `Bearer ${currentToken}`,
},
};
axiosInstance
.get(
`${endpoints.owgw}/api/v1/device/${deviceSerialNumber}/statistics?lifetime=true`,
options,
)
.then((response) => {
setData(response.data);
})
.catch(() => {})
.finally(() => setLoading(false));
};
useEffect(() => {
if (show) getData();
}, [show]);
return <Modal t={t} loading={loading} show={show} toggle={toggle} data={data} />;
};
LifetimeStatsModal.propTypes = {
show: PropTypes.bool.isRequired,
toggle: PropTypes.func.isRequired,
};
export default LifetimeStatsModal;