From 070a03c73e715bd61a01488ab4665933a3e8ff20 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 18 May 2023 08:59:11 +0200 Subject: [PATCH] [WIFI-12614] Dynamic VLAN support fix Signed-off-by: Charles --- package-lock.json | 4 +- package.json | 2 +- .../LogHistory/DetailedLogViewModal.tsx | 19 ++++++++- .../LogHistory/useDeviceLogsTable.tsx | 40 +++++++++++++++++-- .../Device/StatisticsCard/InterfaceChart.tsx | 18 ++++++++- src/pages/Device/StatisticsCard/VlanChart.tsx | 16 +++++++- 6 files changed, 87 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index e11cdf1..d589e2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ucentral-client", - "version": "2.10.0(44)", + "version": "2.10.0(45)", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ucentral-client", - "version": "2.10.0(44)", + "version": "2.10.0(45)", "license": "ISC", "dependencies": { "@chakra-ui/icons": "^2.0.18", diff --git a/package.json b/package.json index c995dfb..856654d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucentral-client", - "version": "2.10.0(44)", + "version": "2.10.0(45)", "description": "", "private": true, "main": "index.tsx", diff --git a/src/pages/Device/LogsCard/LogHistory/DetailedLogViewModal.tsx b/src/pages/Device/LogsCard/LogHistory/DetailedLogViewModal.tsx index 6df24bb..74681a6 100644 --- a/src/pages/Device/LogsCard/LogHistory/DetailedLogViewModal.tsx +++ b/src/pages/Device/LogsCard/LogHistory/DetailedLogViewModal.tsx @@ -18,11 +18,26 @@ const DetailedLogViewModal = ({ modalProps, log }: Props) => { const { hasCopied, onCopy, setValue } = useClipboard(JSON.stringify(log?.log ?? {}, null, 2)); React.useEffect(() => { - setValue(JSON.stringify(log?.log ?? {}, null, 2)); + if (log?.logType === 2) { + setValue(JSON.stringify(log.data ?? {}, null, 2)); + } else { + setValue(JSON.stringify(log?.log ?? {}, null, 2)); + } }, [log]); if (!log) return null; + const getCodeContent = () => { + if (log.logType === 2) { + if (log.data.info !== undefined && Array.isArray(log.data.info)) { + return log.data.info.map((v) => v).join('\n'); + } + return JSON.stringify(log.data, null, 2); + } + + return log.log; + }; + return ( { {t('controller.devices.config_id')}: {log.UUID} - {log.log} + {getCodeContent()} diff --git a/src/pages/Device/LogsCard/LogHistory/useDeviceLogsTable.tsx b/src/pages/Device/LogsCard/LogHistory/useDeviceLogsTable.tsx index 380f448..90628a1 100644 --- a/src/pages/Device/LogsCard/LogHistory/useDeviceLogsTable.tsx +++ b/src/pages/Device/LogsCard/LogHistory/useDeviceLogsTable.tsx @@ -53,6 +53,28 @@ const useDeviceLogsTable = ({ serialNumber, limit, logType }: Props) => { [onOpen], ); + const detailsCell = React.useCallback((v: DeviceLog) => { + if (logType === 2) { + return ( + + onOpen(v)} + colorScheme="blue" + icon={} + size="xs" + mr={2} + /> + + {JSON.stringify(v.data, null, 0)} + + + ); + } + + return
{JSON.stringify(v.data, null, 0)}
; + }, []); + const dateCell = React.useCallback( (v: number) => ( @@ -62,8 +84,6 @@ const useDeviceLogsTable = ({ serialNumber, limit, logType }: Props) => { [], ); - const jsonCell = React.useCallback((v: Record) =>
{JSON.stringify(v, null, 0)}
, []); - const columns: Column[] = React.useMemo( (): Column[] => [ { @@ -106,7 +126,7 @@ const useDeviceLogsTable = ({ serialNumber, limit, logType }: Props) => { Header: t('common.details'), Footer: '', accessor: 'data', - Cell: (v) => jsonCell(v.cell.row.original.data), + Cell: (v) => detailsCell(v.cell.row.original), disableSortBy: true, }, ], @@ -114,7 +134,19 @@ const useDeviceLogsTable = ({ serialNumber, limit, logType }: Props) => { ); return { - columns, + columns: + logType === 2 + ? columns + .filter((c) => c.id !== 'severity') + .map((col) => + col.id === 'log' + ? { + ...col, + Header: 'Type', + } + : col, + ) + : columns, getLogs, getCustomLogs, time, diff --git a/src/pages/Device/StatisticsCard/InterfaceChart.tsx b/src/pages/Device/StatisticsCard/InterfaceChart.tsx index e65286b..e2dfea2 100644 --- a/src/pages/Device/StatisticsCard/InterfaceChart.tsx +++ b/src/pages/Device/StatisticsCard/InterfaceChart.tsx @@ -117,11 +117,25 @@ const InterfaceChart = ({ data, format }: Props) => { ], }; + const dataTick = (value: string | number) => { + try { + const temp = String(value); + + if (temp.includes('.')) { + return Number(temp).toFixed(1); + } + + return temp; + } catch (e) { + return value; + } + }; + const packetsTick = (value: number) => { if (packetsFactor.factor === 1) { return value.toLocaleString(); } - return `${(value / packetsFactor.factor).toLocaleString()}${packetsFactor.unit}`; + return `${(value / packetsFactor.factor).toFixed(1).toLocaleString()}${packetsFactor.unit}`; }; return ( @@ -168,7 +182,7 @@ const InterfaceChart = ({ data, format }: Props) => { color: colorMode === 'dark' ? 'white' : undefined, callback: format === 'bytes' - ? (tickValue) => `${tickValue} ${unit}` + ? (tickValue) => `${dataTick(tickValue)} ${unit}` : (tickValue) => (typeof tickValue === 'number' ? packetsTick(tickValue) : tickValue), }, }, diff --git a/src/pages/Device/StatisticsCard/VlanChart.tsx b/src/pages/Device/StatisticsCard/VlanChart.tsx index 55b9f53..f56406c 100644 --- a/src/pages/Device/StatisticsCard/VlanChart.tsx +++ b/src/pages/Device/StatisticsCard/VlanChart.tsx @@ -117,6 +117,20 @@ const VlanChart = ({ data, format }: Props) => { ], }; + const dataTick = (value: string | number) => { + try { + const temp = String(value); + + if (temp.includes('.')) { + return Number(temp).toFixed(1); + } + + return temp; + } catch (e) { + return value; + } + }; + const packetsTick = (value: number) => { if (packetsFactor.factor === 1) { return value.toLocaleString(); @@ -168,7 +182,7 @@ const VlanChart = ({ data, format }: Props) => { color: colorMode === 'dark' ? 'white' : undefined, callback: format === 'bytes' - ? (tickValue) => `${tickValue} ${unit}` + ? (tickValue) => `${dataTick(tickValue)} ${unit}` : (tickValue) => (typeof tickValue === 'number' ? packetsTick(tickValue) : tickValue), }, },