@@ -16,7 +16,7 @@ import {
1616 useDisclosure ,
1717} from '@chakra-ui/react' ;
1818import { JsonViewer } from '@textea/json-viewer' ;
19- import { Barcode } from '@phosphor-icons/react' ;
19+ import { Barcode , DownloadSimple } from '@phosphor-icons/react' ;
2020import { useTranslation } from 'react-i18next' ;
2121import { Modal } from 'components/Modals/Modal' ;
2222import { useGetDevice } from 'hooks/Network/Devices' ;
@@ -35,6 +35,17 @@ const ViewConfigurationModal = ({ serialNumber }: { serialNumber: string }) => {
3535 }
3636 } , [ getDevice . data ?. configuration ] ) ;
3737
38+ const handleDownload = ( ) => {
39+ const jsonString = JSON . stringify ( getDevice . data ?. configuration ?? { } , null , 2 ) ;
40+ const blob = new Blob ( [ jsonString ] , { type : 'application/json' } ) ;
41+ const url = URL . createObjectURL ( blob ) ;
42+ const link = document . createElement ( 'a' ) ;
43+ link . href = url ;
44+ link . download = `${ serialNumber } -configuration.json` ;
45+ link . click ( ) ;
46+ URL . revokeObjectURL ( url ) ;
47+ } ;
48+
3849 const handleOpenClick = ( ) => {
3950 getDevice . refetch ( ) ;
4051 onOpen ( ) ;
@@ -58,6 +69,14 @@ const ViewConfigurationModal = ({ serialNumber }: { serialNumber: string }) => {
5869 < Button onClick = { onCopy } size = "md" colorScheme = "teal" >
5970 { hasCopied ? `${ t ( 'common.copied' ) } !` : t ( 'common.copy' ) }
6071 </ Button >
72+ < Tooltip label = { t ( 'common.download' ) } hasArrow >
73+ < IconButton
74+ aria-label = { t ( 'common.download' ) }
75+ icon = { < DownloadSimple size = { 20 } /> }
76+ onClick = { handleDownload }
77+ colorScheme = "blue"
78+ />
79+ </ Tooltip >
6180 < RefreshButton onClick = { getDevice . refetch } isFetching = { getDevice . isFetching } />
6281 </ >
6382 }
0 commit comments