mirror of
https://github.com/optim-enterprises-bv/OptimCloud-gw-ui.git
synced 2025-11-01 18:57:46 +00:00
Merge pull request #100 from stephb9959/main
[WIFI-10515] Crash fix when receiving corrupted statistics
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ucentral-client",
|
"name": "ucentral-client",
|
||||||
"version": "2.7.0(0)",
|
"version": "2.7.0(1)",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ucentral-client",
|
"name": "ucentral-client",
|
||||||
"version": "2.7.0(0)",
|
"version": "2.7.0(1)",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@coreui/coreui": "^3.4.0",
|
"@coreui/coreui": "^3.4.0",
|
||||||
"@coreui/icons": "^2.0.1",
|
"@coreui/icons": "^2.0.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ucentral-client",
|
"name": "ucentral-client",
|
||||||
"version": "2.7.0(0)",
|
"version": "2.7.0(1)",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@coreui/coreui": "^3.4.0",
|
"@coreui/coreui": "^3.4.0",
|
||||||
"@coreui/icons": "^2.0.1",
|
"@coreui/icons": "^2.0.1",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, useMemo } from 'react';
|
||||||
import { CButton, CModal, CModalHeader, CModalBody, CModalTitle, CPopover } from '@coreui/react';
|
import { CButton, CModal, CModalHeader, CModalBody, CModalTitle, CPopover } from '@coreui/react';
|
||||||
import CIcon from '@coreui/icons-react';
|
import CIcon from '@coreui/icons-react';
|
||||||
import { cilX } from '@coreui/icons';
|
import { cilX } from '@coreui/icons';
|
||||||
@@ -32,6 +32,17 @@ const LatestStatisticsModal = ({ show, toggle }) => {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const latestStatsString = useMemo(() => {
|
||||||
|
if (latestStats) {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(latestStats, null, 2);
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}, [latestStats]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (show) {
|
if (show) {
|
||||||
getLatestStats();
|
getLatestStats();
|
||||||
@@ -52,13 +63,9 @@ const LatestStatisticsModal = ({ show, toggle }) => {
|
|||||||
</CModalHeader>
|
</CModalHeader>
|
||||||
<CModalBody>
|
<CModalBody>
|
||||||
<div style={{ textAlign: 'right' }}>
|
<div style={{ textAlign: 'right' }}>
|
||||||
<CopyToClipboardButton
|
<CopyToClipboardButton t={t} size="lg" content={latestStatsString} />
|
||||||
t={t}
|
|
||||||
size="lg"
|
|
||||||
content={JSON.stringify(latestStats ?? {}, null, 4)}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<pre className="ignore">{JSON.stringify(latestStats, null, 2)}</pre>
|
<pre className="ignore">{latestStatsString}</pre>
|
||||||
</CModalBody>
|
</CModalBody>
|
||||||
</CModal>
|
</CModal>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { CSpinner } from '@coreui/react';
|
import { CSpinner, CAlert } from '@coreui/react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { v4 as createUuid } from 'uuid';
|
import { v4 as createUuid } from 'uuid';
|
||||||
import axiosInstance from 'utils/axiosInstance';
|
import axiosInstance from 'utils/axiosInstance';
|
||||||
@@ -23,8 +23,10 @@ const StatisticsChartList = ({ deviceSerialNumber, setOptions, section, time })
|
|||||||
memory: [],
|
memory: [],
|
||||||
settings: {},
|
settings: {},
|
||||||
});
|
});
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
const transformIntoDataset = (data) => {
|
const transformIntoDataset = (data) => {
|
||||||
|
try {
|
||||||
let sortedData = data.sort((a, b) => {
|
let sortedData = data.sort((a, b) => {
|
||||||
if (a.recorded > b.recorded) return 1;
|
if (a.recorded > b.recorded) return 1;
|
||||||
if (b.recorded > a.recorded) return -1;
|
if (b.recorded > a.recorded) return -1;
|
||||||
@@ -244,9 +246,20 @@ const StatisticsChartList = ({ deviceSerialNumber, setOptions, section, time })
|
|||||||
setOptions([...sectionOptions, { value: 'memory', label: t('statistics.memory') }]);
|
setOptions([...sectionOptions, { value: 'memory', label: t('statistics.memory') }]);
|
||||||
setStatOptions({ ...newOptions });
|
setStatOptions({ ...newOptions });
|
||||||
}
|
}
|
||||||
|
setError(false);
|
||||||
|
} catch (e) {
|
||||||
|
setError(true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getInterface = useCallback(() => {
|
const getInterface = useCallback(() => {
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<CAlert color="danger" style={{ width: '240px' }}>
|
||||||
|
Error while parsing statistics
|
||||||
|
</CAlert>
|
||||||
|
);
|
||||||
|
}
|
||||||
if (statOptions.interfaceList.length === 0) return <p>N/A</p>;
|
if (statOptions.interfaceList.length === 0) return <p>N/A</p>;
|
||||||
|
|
||||||
const interfaceToShow = statOptions.interfaceList.find(
|
const interfaceToShow = statOptions.interfaceList.find(
|
||||||
@@ -273,8 +286,9 @@ const StatisticsChartList = ({ deviceSerialNumber, setOptions, section, time })
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <p>N/A</p>;
|
return <p>N/A</p>;
|
||||||
}, [statOptions, section]);
|
}, [statOptions, section, error]);
|
||||||
|
|
||||||
const getStatistics = () => {
|
const getStatistics = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|||||||
@@ -31,25 +31,3 @@ export const extractWebSocketResponse = (message) => {
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getStatusFromNotification = (notification) => {
|
|
||||||
let status = 'success';
|
|
||||||
if (notification.content.warning?.length > 0) status = 'warning';
|
|
||||||
if (notification.content.error?.length > 0) status = 'error';
|
|
||||||
|
|
||||||
return status;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getNotificationDescription = (t, notification) => {
|
|
||||||
if (
|
|
||||||
notification.content.type === 'venue_configuration_update' ||
|
|
||||||
notification.content.type === 'entity_configuration_update'
|
|
||||||
) {
|
|
||||||
return t('configurations.notification_details', {
|
|
||||||
success: notification.content.success.length,
|
|
||||||
warning: notification.content.warning.length,
|
|
||||||
error: notification.content.error.length,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return notification.content.details;
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user