diff --git a/package-lock.json b/package-lock.json index cc92d50..5c4baed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ucentral-client", - "version": "2.9.0(13)", + "version": "2.9.0(16)", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ucentral-client", - "version": "2.9.0(13)", + "version": "2.9.0(16)", "license": "ISC", "dependencies": { "@chakra-ui/icons": "^2.0.11", diff --git a/package.json b/package.json index b1c8108..a46831a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucentral-client", - "version": "2.9.0(13)", + "version": "2.9.0(16)", "description": "", "private": true, "main": "index.tsx", diff --git a/src/components/DataTables/DataTable/index.tsx b/src/components/DataTables/DataTable/index.tsx index fcadbbd..d505c2d 100644 --- a/src/components/DataTables/DataTable/index.tsx +++ b/src/components/DataTables/DataTable/index.tsx @@ -44,12 +44,14 @@ const defaultProps = { sortBy: [], }; -export type DataTableProps = { - columns: readonly Column[]; - data: object[]; +export type DataTableProps = { + columns: Column[]; + data: TValue[]; count?: number; setPageInfo?: React.Dispatch>; isLoading?: boolean; + onRowClick?: (row: TValue) => void; + isRowClickable?: (row: TValue) => boolean; obj?: string; sortBy?: { id: string; desc: boolean }[]; hiddenColumns?: string[]; @@ -68,7 +70,7 @@ type TableInstanceWithHooks = TableInstance & state: UsePaginationState; }; -const _DataTable = ({ +const _DataTable = ({ columns, data, isLoading, @@ -84,7 +86,9 @@ const _DataTable = ({ isManual, saveSettingsId, showAllRows, -}: DataTableProps) => { + onRowClick, + isRowClickable, +}: DataTableProps) => { const { t } = useTranslation(); const breakpoint = useBreakpoint(); const textColor = useColorModeValue('gray.700', 'white'); @@ -143,7 +147,7 @@ const _DataTable = ({ }, useSortBy, usePagination, - ) as TableInstanceWithHooks; + ) as TableInstanceWithHooks; const handleGoToPage = (newPage: number) => { if (saveSettingsId) localStorage.setItem(`${saveSettingsId}.page`, String(newPage)); @@ -260,8 +264,10 @@ const _DataTable = ({ {data.length > 0 && ( - {page.map((row: Row) => { + {page.map((row: Row) => { prepareRow(row); + const rowIsClickable = isRowClickable ? isRowClickable(row.original) : true; + const onClick = rowIsClickable && onRowClick ? () => onRowClick(row.original) : undefined; return ( { // @ts-ignore @@ -288,8 +295,26 @@ const _DataTable = ({ fontSize="14px" // @ts-ignore textAlign={cell.column.isCentered ? 'center' : undefined} - // @ts-ignore - fontFamily={cell.column.isMonospace ? 'monospace' : undefined} + fontFamily={ + // @ts-ignore + cell.column.isMonospace + ? 'Inter, SFMono-Regular, Menlo, Monaco, Consolas, monospace' + : undefined + } + onClick={ + // @ts-ignore + cell.column.stopPropagation || (cell.column.id === 'actions' && onRowClick) + ? (e) => { + e.stopPropagation(); + } + : undefined + } + cursor={ + // @ts-ignore + !cell.column.stopPropagation && cell.column.id !== 'actions' && onRowClick + ? 'pointer' + : undefined + } > {cell.render('Cell')} @@ -414,4 +439,4 @@ const _DataTable = ({ _DataTable.defaultProps = defaultProps; -export const DataTable = React.memo(_DataTable); +export const DataTable = React.memo(_DataTable) as unknown as typeof _DataTable; diff --git a/src/components/DataTables/SortableDataTable/index.tsx b/src/components/DataTables/SortableDataTable/index.tsx index 456fe13..452e857 100644 --- a/src/components/DataTables/SortableDataTable/index.tsx +++ b/src/components/DataTables/SortableDataTable/index.tsx @@ -249,8 +249,12 @@ const SortableDataTable: React.FC = ({ fontSize="14px" // @ts-ignore textAlign={cell.column.isCentered ? 'center' : undefined} - // @ts-ignore - fontFamily={cell.column.isMonospace ? 'monospace' : undefined} + fontFamily={ + // @ts-ignore + cell.column.isMonospace + ? 'Inter, SFMono-Regular, Menlo, Monaco, Consolas, monospace' + : undefined + } > {cell.render('Cell')} diff --git a/src/components/Modals/ConfigureModal/index.tsx b/src/components/Modals/ConfigureModal/index.tsx index 2f3ad1b..270db1a 100644 --- a/src/components/Modals/ConfigureModal/index.tsx +++ b/src/components/Modals/ConfigureModal/index.tsx @@ -5,17 +5,22 @@ import { AlertIcon, AlertTitle, Box, + Button, + Flex, FormControl, FormErrorMessage, FormLabel, Textarea, useToast, } from '@chakra-ui/react'; +import { ClipboardText } from 'phosphor-react'; import { useTranslation } from 'react-i18next'; import { SaveButton } from '../../Buttons/SaveButton'; import { Modal } from '../Modal'; import { FileInputButton } from 'components/Buttons/FileInputButton'; import { useConfigureDevice } from 'hooks/Network/Commands'; +import { useGetDevice } from 'hooks/Network/Devices'; +import { AxiosError } from 'models/Axios'; export type ConfigureModalProps = { serialNumber: string; @@ -29,11 +34,17 @@ export const ConfigureModal = ({ serialNumber, modalProps }: ConfigureModalProps const { t } = useTranslation(); const toast = useToast(); const configure = useConfigureDevice({ serialNumber }); + const getDevice = useGetDevice({ serialNumber }); + const [newConfig, setNewConfig] = React.useState(''); const onChange = React.useCallback((e: React.ChangeEvent) => { setNewConfig(e.target.value); }, []); + + const onImportConfiguration = () => { + setNewConfig(getDevice.data?.configuration ? JSON.stringify(getDevice.data.configuration, null, 4) : ''); + }; const isValid = React.useMemo(() => { try { JSON.parse(newConfig); @@ -60,9 +71,7 @@ export const ConfigureModal = ({ serialNumber, modalProps }: ConfigureModalProps modalProps.onClose(); }, }); - } catch (e) { - // console.log(e); - } + } catch (e) {} }; return ( @@ -79,10 +88,7 @@ export const ConfigureModal = ({ serialNumber, modalProps }: ConfigureModalProps {t('common.error')} - { - // @ts-ignore - {configure.error?.response?.data?.ErrorDescription} - } + {(configure.error as AxiosError)?.response?.data?.ErrorDescription} )} @@ -92,15 +98,25 @@ export const ConfigureModal = ({ serialNumber, modalProps }: ConfigureModalProps 0}> {t('configurations.one')} - - setNewConfig(v)} - refreshId="1" - accept=".json" - isStringFile - /> - + + + setNewConfig(v)} + refreshId="1" + accept=".json" + isStringFile + /> + + +