From 3d01c203399b6273b627267a086aa33c4ef5155a Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 15 Mar 2024 17:22:28 +0100 Subject: [PATCH] [WIFI-13515] Supporting deviceTypes in lowercase Signed-off-by: Charles --- package-lock.json | 4 +- package.json | 2 +- .../Buttons/DeviceActionDropdown/index.tsx | 10 ++--- src/hooks/Network/DefaultConfigurations.ts | 2 + src/hooks/Network/Devices.ts | 10 ++--- .../List/CreateModal.tsx | 31 +++++++++++++--- .../DefaultConfigurations/List/EditModal.tsx | 37 ++++++++++++++++--- .../DefaultConfigurations/List/index.tsx | 8 ++++ src/pages/DefaultConfigurations/utils.ts | 2 + src/pages/Device/Wrapper.tsx | 29 +++++++-------- src/pages/Devices/ListCard/index.tsx | 4 +- 11 files changed, 97 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index c136b97..a4f1119 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ucentral-client", - "version": "3.0.2(6)", + "version": "3.0.2(8)", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ucentral-client", - "version": "3.0.2(6)", + "version": "3.0.2(8)", "license": "ISC", "dependencies": { "@chakra-ui/anatomy": "^2.1.1", diff --git a/package.json b/package.json index ddc62bc..01fedfa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucentral-client", - "version": "3.0.2(6)", + "version": "3.0.2(8)", "description": "", "private": true, "main": "index.tsx", diff --git a/src/components/Buttons/DeviceActionDropdown/index.tsx b/src/components/Buttons/DeviceActionDropdown/index.tsx index 47d59b7..6521005 100644 --- a/src/components/Buttons/DeviceActionDropdown/index.tsx +++ b/src/components/Buttons/DeviceActionDropdown/index.tsx @@ -54,7 +54,7 @@ const DeviceActionDropdown = ({ }: Props) => { const { t } = useTranslation(); const toast = useToast(); - const deviceType = device?.deviceType ?? 'AP'; + const deviceType = device?.deviceType ?? 'ap'; const connectColor = useColorModeValue('blackAlpha', 'gray'); const addEventListeners = useControllerStore((state) => state.addEventListeners); const { refetch: getRtty, isFetching: isRtty } = useGetDeviceRtty({ @@ -173,7 +173,7 @@ const DeviceActionDropdown = ({ isLoading={isRtty} onClick={handleConnectClick} colorScheme={connectColor} - hidden={isCompact || deviceType !== 'AP'} + hidden={isCompact || deviceType !== 'ap'} /> @@ -206,7 +206,7 @@ const DeviceActionDropdown = ({ isDisabled={isDisabled} onClick={handleOpenScan} colorScheme="teal" - hidden={isCompact || deviceType !== 'AP'} + hidden={isCompact || deviceType !== 'ap'} /> @@ -222,7 +222,7 @@ const DeviceActionDropdown = ({ {t('commands.blink')} - diff --git a/src/hooks/Network/DefaultConfigurations.ts b/src/hooks/Network/DefaultConfigurations.ts index 4224a0a..66b1de3 100644 --- a/src/hooks/Network/DefaultConfigurations.ts +++ b/src/hooks/Network/DefaultConfigurations.ts @@ -3,10 +3,12 @@ import { axiosGw } from 'constants/axiosInstances'; import { useEndpointStatus } from 'hooks/useEndpointStatus'; import { AxiosError } from 'models/Axios'; import { DeviceConfiguration } from 'models/Device'; +import { DevicePlatform } from './Devices'; export type DefaultConfigurationResponse = { configuration: DeviceConfiguration; created: number; + platform: DevicePlatform; description: string; lastModified: number; modelIds: string[]; diff --git a/src/hooks/Network/Devices.ts b/src/hooks/Network/Devices.ts index c88e98e..3c22158 100644 --- a/src/hooks/Network/Devices.ts +++ b/src/hooks/Network/Devices.ts @@ -11,7 +11,7 @@ import { Note } from 'models/Note'; import { PageInfo } from 'models/Table'; import { DeviceCommandHistory } from './Commands'; -export const DEVICE_PLATFORMS = ['ALL', 'AP', 'SWITCH'] as const; +export const DEVICE_PLATFORMS = ['all', 'ap', 'switch'] as const; export type DevicePlatform = (typeof DEVICE_PLATFORMS)[number]; const getDeviceCount = (platform: DevicePlatform) => @@ -19,7 +19,7 @@ const getDeviceCount = (platform: DevicePlatform) => count: number; }>; -export const useGetDeviceCount = ({ enabled, platform = 'ALL' }: { enabled: boolean; platform?: DevicePlatform }) => { +export const useGetDeviceCount = ({ enabled, platform = 'all' }: { enabled: boolean; platform?: DevicePlatform }) => { const { t } = useTranslation(); const toast = useToast(); @@ -55,7 +55,7 @@ export type DeviceWithStatus = { certificateExpiryDate?: number; createdTimestamp: number; devicePassword: string; - deviceType: 'AP' | 'SWITCH' | 'IOT' | 'MESH'; + deviceType: 'ap' | 'switch'; entity: string; firmware: string; fwUpdatePolicy: string; @@ -111,7 +111,7 @@ export const useGetDevices = ({ pageInfo, enabled, onError, - platform = 'ALL', + platform = 'all', }: { pageInfo?: PageInfo; enabled: boolean; @@ -147,7 +147,7 @@ const getAllDevices = async (platform: DevicePlatform) => { export const useGetAllDevicesWithStatus = ({ onError, - platform = 'ALL', + platform = 'all', }: { onError?: (e: AxiosError) => void; platform?: DevicePlatform; diff --git a/src/pages/DefaultConfigurations/List/CreateModal.tsx b/src/pages/DefaultConfigurations/List/CreateModal.tsx index 34c03dc..2cdabd7 100644 --- a/src/pages/DefaultConfigurations/List/CreateModal.tsx +++ b/src/pages/DefaultConfigurations/List/CreateModal.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Box, SimpleGrid, useBoolean, useDisclosure, useToast } from '@chakra-ui/react'; +import { Box, Flex, useBoolean, useDisclosure, useToast } from '@chakra-ui/react'; import { Formik, FormikProps } from 'formik'; import { useTranslation } from 'react-i18next'; import { v4 as uuid } from 'uuid'; @@ -16,6 +16,7 @@ import { useGetDeviceTypes } from 'hooks/Network/Firmware'; import { useFormModal } from 'hooks/useFormModal'; import { useFormRef } from 'hooks/useFormRef'; import { AxiosError } from 'models/Axios'; +import { SelectField } from 'components/Form/Fields/SelectField'; const CreateDefaultConfigurationModal = () => { const { t } = useTranslation(); @@ -100,10 +101,28 @@ const CreateDefaultConfigurationModal = () => { }} > - - - - + + + + + { } isRequired /> - + diff --git a/src/pages/DefaultConfigurations/List/EditModal.tsx b/src/pages/DefaultConfigurations/List/EditModal.tsx index c1dec13..d85d54c 100644 --- a/src/pages/DefaultConfigurations/List/EditModal.tsx +++ b/src/pages/DefaultConfigurations/List/EditModal.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Box, SimpleGrid, useBoolean, UseDisclosureReturn, useToast } from '@chakra-ui/react'; +import { Box, Flex, useBoolean, UseDisclosureReturn, useToast } from '@chakra-ui/react'; import { Formik, FormikProps } from 'formik'; import { useTranslation } from 'react-i18next'; import { v4 as uuid } from 'uuid'; @@ -15,6 +15,7 @@ import { useGetDeviceTypes } from 'hooks/Network/Firmware'; import { useFormModal } from 'hooks/useFormModal'; import { useFormRef } from 'hooks/useFormRef'; import { AxiosError } from 'models/Axios'; +import { SelectField } from 'components/Form/Fields/SelectField'; type Props = { modalProps: UseDisclosureReturn; @@ -106,10 +107,28 @@ const EditDefaultConfiguration = ({ modalProps, config }: Props) => { }} > - - - - + + + + + { } isRequired /> - + )} diff --git a/src/pages/DefaultConfigurations/List/index.tsx b/src/pages/DefaultConfigurations/List/index.tsx index 2233d91..f7582b3 100644 --- a/src/pages/DefaultConfigurations/List/index.tsx +++ b/src/pages/DefaultConfigurations/List/index.tsx @@ -58,6 +58,14 @@ const DefaultConfigurationsList = () => { Cell: ({ cell }) => dateCell(cell.row.original.lastModified), customWidth: '50px', }, + { + id: 'platform', + Header: 'Platform', + Footer: '', + accessor: 'platform', + Cell: ({ cell }) => cell.row.original.platform.toUpperCase(), + customWidth: '50px', + }, { id: 'modelIds', Header: t('controller.dashboard.device_types'), diff --git a/src/pages/DefaultConfigurations/utils.ts b/src/pages/DefaultConfigurations/utils.ts index 540a341..530801e 100644 --- a/src/pages/DefaultConfigurations/utils.ts +++ b/src/pages/DefaultConfigurations/utils.ts @@ -7,6 +7,7 @@ export const DefaultConfigurationSchema = (t: (str: string) => string) => name: Yup.string().required(t('form.required')), description: Yup.string(), modelIds: Yup.array().of(Yup.string()).required(t('form.required')).min(1, t('form.required')), + platform: Yup.string().oneOf(['ap', 'switch']).required(t('form.required')), configuration: Yup.string() .required(t('form.required')) .test('configuration', t('form.invalid_json'), (v) => testJson(v ?? '')), @@ -15,5 +16,6 @@ export const DefaultConfigurationSchema = (t: (str: string) => string) => name: '', description: '', modelIds: [], + platform: 'ap', configuration: '', }); diff --git a/src/pages/Device/Wrapper.tsx b/src/pages/Device/Wrapper.tsx index 28fde44..66ea61a 100644 --- a/src/pages/Device/Wrapper.tsx +++ b/src/pages/Device/Wrapper.tsx @@ -80,19 +80,8 @@ const DevicePageWrapper = ({ serialNumber }: Props) => { const isCompact = breakpoint === 'base' || breakpoint === 'sm' || breakpoint === 'md'; const boxShadow = useColorModeValue('0px 7px 23px rgba(0, 0, 0, 0.05)', 'none'); - const handleDeleteClick = () => + const handleDeleteClick = () => { deleteDevice(serialNumber, { - onSuccess: () => { - toast({ - id: `delete-device-success-${serialNumber}`, - title: t('common.success'), - status: 'success', - duration: 5000, - isClosable: true, - position: 'top-right', - }); - navigate('/devices'); - }, onError: (e) => { if (axios.isAxiosError(e)) { toast({ @@ -107,6 +96,16 @@ const DevicePageWrapper = ({ serialNumber }: Props) => { } }, }); + toast({ + id: `delete-device-success-${serialNumber}`, + title: t('common.success'), + status: 'success', + duration: 5000, + isClosable: true, + position: 'top-right', + }); + navigate('/'); + }; const connectedTag = React.useMemo(() => { if (!getStatus.data) return null; @@ -123,7 +122,7 @@ const DevicePageWrapper = ({ serialNumber }: Props) => { } let icon = getStatus.data.connected ? WifiHigh : WifiSlash; - if (getDevice.data?.deviceType === 'SWITCH') + if (getDevice.data?.deviceType === 'switch') icon = getStatus.data.connected ? ethernetConnected : ethernetDisconnected; return ( @@ -325,8 +324,8 @@ const DevicePageWrapper = ({ serialNumber }: Props) => { - {getDevice.data?.deviceType === 'AP' ? : null} - {getDevice.data?.deviceType === 'SWITCH' ? : null} + {getDevice.data?.deviceType === 'ap' ? : null} + {getDevice.data?.deviceType === 'switch' ? : null} {getDevice.data && getDevice.data?.hasRADIUSSessions > 0 ? ( diff --git a/src/pages/Devices/ListCard/index.tsx b/src/pages/Devices/ListCard/index.tsx index b674ec7..1e21b89 100644 --- a/src/pages/Devices/ListCard/index.tsx +++ b/src/pages/Devices/ListCard/index.tsx @@ -737,8 +737,8 @@ const DeviceListCard = () => { ml={2} > - - + + ),