Skip to content

Commit

Permalink
Merge pull request #207 from stephb9959/main
Browse files Browse the repository at this point in the history
[WIFI-13281] Add support for OLS
  • Loading branch information
BourqueCharles authored Jan 11, 2024
2 parents e3f6ab4 + deb7715 commit 863fda3
Show file tree
Hide file tree
Showing 17 changed files with 902 additions and 49 deletions.
340 changes: 332 additions & 8 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "3.0.0(6)",
"version": "3.0.1(2)",
"description": "",
"private": true,
"main": "index.tsx",
Expand Down Expand Up @@ -94,6 +94,7 @@
"lint-staged": "^13.2.1",
"prettier": "^2.8.7",
"vite-plugin-pwa": "^0.14.7",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.2.0"
},
"browserslist": {
Expand Down
Binary file added public/devices/edgecore_ecs4125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions src/components/Buttons/DeviceActionDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const DeviceActionDropdown = ({
}: Props) => {
const { t } = useTranslation();
const toast = useToast();
const deviceType = device?.deviceType ?? 'AP';
const connectColor = useColorModeValue('blackAlpha', 'gray');
const addEventListeners = useControllerStore((state) => state.addEventListeners);
const { refetch: getRtty, isFetching: isRtty } = useGetDeviceRtty({
Expand Down Expand Up @@ -172,7 +173,7 @@ const DeviceActionDropdown = ({
isLoading={isRtty}
onClick={handleConnectClick}
colorScheme={connectColor}
hidden={isCompact}
hidden={isCompact || deviceType !== 'AP'}
/>
</Tooltip>
<Tooltip label={t('controller.configure.title')}>
Expand Down Expand Up @@ -205,7 +206,7 @@ const DeviceActionDropdown = ({
isDisabled={isDisabled}
onClick={handleOpenScan}
colorScheme="teal"
hidden={isCompact}
hidden={isCompact || deviceType !== 'AP'}
/>
</Tooltip>
<Menu>
Expand All @@ -221,7 +222,7 @@ const DeviceActionDropdown = ({
<Portal>
<MenuList maxH="315px" overflowY="auto">
<MenuItem onClick={handleBlinkClick}>{t('commands.blink')}</MenuItem>
<MenuItem onClick={handleOpenConfigure} hidden={!isCompact}>
<MenuItem onClick={handleOpenConfigure} hidden={!isCompact || deviceType !== 'AP'}>
{t('controller.configure.title')}
</MenuItem>
<MenuItem onClick={handleConnectClick} hidden={!isCompact}>
Expand All @@ -239,7 +240,7 @@ const DeviceActionDropdown = ({
<MenuItem onClick={handleUpdateToLatest} hidden>
{t('premium.toolbox.upgrade_to_latest')}
</MenuItem>
<MenuItem onClick={handleOpenScan} hidden={!isCompact}>
<MenuItem onClick={handleOpenScan} hidden={!isCompact || deviceType !== 'AP'}>
{t('commands.wifiscan')}
</MenuItem>
</MenuList>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Containers/ResponsiveTag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ResponsiveTag = React.memo(({ label, icon, tooltip, isCompact, ...p
return (
<Tooltip label={tooltip ?? label}>
<Tag size="lg" colorScheme="blue" {...props}>
<TagLeftIcon boxSize="18px" as={icon} />
<TagLeftIcon boxSize="18px" as={icon} mt={-0.5} />
<TagLabel>{label}</TagLabel>
</Tag>
</Tooltip>
Expand Down
1 change: 1 addition & 0 deletions src/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ declare module '*.png' {
const value: string;
export = value;
}
/// <reference types="vite-plugin-svgr/client" />
53 changes: 41 additions & 12 deletions src/hooks/Network/Devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import { DeviceRttyApiResponse, GatewayDevice, WifiScanCommand, WifiScanResult }
import { Note } from 'models/Note';
import { PageInfo } from 'models/Table';

const getDeviceCount = () =>
axiosGw.get('devices?countOnly=true').then((response) => response.data) as Promise<{ count: number }>;
export const DEVICE_PLATFORMS = ['ALL', 'AP', 'SWITCH'] as const;
export type DevicePlatform = (typeof DEVICE_PLATFORMS)[number];

export const useGetDeviceCount = ({ enabled }: { enabled: boolean }) => {
const getDeviceCount = (platform: DevicePlatform) =>
axiosGw.get(`devices?countOnly=true&platform=${platform}`).then((response) => response.data) as Promise<{
count: number;
}>;

export const useGetDeviceCount = ({ enabled, platform = 'ALL' }: { enabled: boolean; platform?: DevicePlatform }) => {
const { t } = useTranslation();
const toast = useToast();

return useQuery(['devices', 'count'], getDeviceCount, {
return useQuery(['devices', 'count', { platform }], () => getDeviceCount(platform), {
enabled,
onError: (e: AxiosError) => {
if (!toast.isActive('inventory-fetching-error'))
Expand Down Expand Up @@ -96,25 +101,27 @@ export const getSingleDeviceWithStatus = (serialNumber: string) =>
})
.catch(() => undefined);

const getDevices = (limit: number, offset: number) =>
const getDevices = (limit: number, offset: number, platform: DevicePlatform) =>
axiosGw
.get(`devices?deviceWithStatus=true&limit=${limit}&offset=${offset}`)
.get(`devices?deviceWithStatus=true&limit=${limit}&offset=${offset}&platform=${platform}`)
.then((response) => response.data) as Promise<{ devicesWithStatus: DeviceWithStatus[] }>;

export const useGetDevices = ({
pageInfo,
enabled,
onError,
platform = 'ALL',
}: {
pageInfo?: PageInfo;
enabled: boolean;
onError?: (e: AxiosError) => void;
platform?: DevicePlatform;
}) => {
const offset = pageInfo?.limit !== undefined ? pageInfo.limit * pageInfo.index : 0;

return useQuery(
['devices', 'all', { limit: pageInfo?.limit, offset }],
() => getDevices(pageInfo?.limit || 0, offset),
['devices', 'all', { limit: pageInfo?.limit, offset, platform }],
() => getDevices(pageInfo?.limit || 0, offset, platform),
{
keepPreviousData: true,
enabled: enabled && pageInfo !== undefined,
Expand All @@ -124,22 +131,28 @@ export const useGetDevices = ({
);
};

const getAllDevices = async () => {
const getAllDevices = async (platform: DevicePlatform) => {
let offset = 0;
let devices: DeviceWithStatus[] = [];
let devicesResponse: { devicesWithStatus: DeviceWithStatus[] };
do {
// eslint-disable-next-line no-await-in-loop
devicesResponse = await getDevices(500, offset);
devicesResponse = await getDevices(500, offset, platform);
devices = devices.concat(devicesResponse.devicesWithStatus);
offset += 500;
} while (devicesResponse.devicesWithStatus.length === 500);
return devices;
};

export const useGetAllDevicesWithStatus = ({ onError }: { onError?: (e: AxiosError) => void }) => {
export const useGetAllDevicesWithStatus = ({
onError,
platform = 'ALL',
}: {
onError?: (e: AxiosError) => void;
platform?: DevicePlatform;
}) => {
const { isReady } = useEndpointStatus('owgw');
return useQuery(['devices', 'all', 'full'], getAllDevices, {
return useQuery(['devices', 'all', 'full', { platform }], () => getAllDevices(platform), {
enabled: isReady && false,
onError,
});
Expand Down Expand Up @@ -432,3 +445,19 @@ export const useUpdateDevice = ({ serialNumber }: { serialNumber: string }) => {
},
});
};

const deleteDeviceBatch = async (pattern: string) => {
if (pattern.length < 6) throw new Error('Pattern must be at least 6 characters long');

axiosGw.delete(`devices?macPattern=${pattern}`);
};

export const useDeleteDeviceBatch = () => {
const queryClient = useQueryClient();

return useMutation(deleteDeviceBatch, {
onSuccess: () => {
queryClient.invalidateQueries(['devices']);
},
});
};
32 changes: 21 additions & 11 deletions src/hooks/Network/Statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@ import { useQuery } from '@tanstack/react-query';
import { axiosGw } from 'constants/axiosInstances';
import { AxiosError } from 'models/Axios';

type DeviceInterfaceStatistics = {
export type DeviceLinkState = {
carrier?: number;
counters?: {
collisions: number;
multicast: number;
rx_bytes: number;
rx_dropped: number;
rx_errors: number;
rx_packets: number;
tx_bytes: number;
tx_dropped: number;
tx_errors: number;
tx_packets: number;
};
duplex?: string;
speed?: number;
};
export type DeviceInterfaceStatistics = {
clients: {
ipv4_addresses?: string[];
ipv6_addresses?: string[];
Expand Down Expand Up @@ -138,18 +155,10 @@ export type DeviceStatistics = {
};
'link-state'?: {
downstream: {
eth1?: {
carrier?: number;
duplex?: string;
speed?: number;
};
[key: string]: DeviceLinkState;
};
upstream: {
eth0?: {
carrier?: number;
duplex?: string;
speed?: number;
};
[key: string]: DeviceLinkState;
};
};
'lldp-peers'?: {
Expand Down Expand Up @@ -190,6 +199,7 @@ export const useGetDeviceLastStats = ({
useQuery(['device', serialNumber, 'last-statistics'], () => getLastStats(serialNumber), {
enabled: serialNumber !== undefined && serialNumber !== '',
staleTime: 1000 * 60,
refetchInterval: 1000 * 60,
onError,
});

Expand Down
Loading

0 comments on commit 863fda3

Please sign in to comment.