Skip to content

Commit bf00c8c

Browse files
Add Download Button
- Add download button on ViewConfigurationModal.tsx - Add download logic on ViewConfigurationModal.tsx Signed-off-by: Sebastian Rubina <[email protected]>
1 parent c4aff41 commit bf00c8c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/pages/Device/ViewConfigurationModal.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
useDisclosure,
1717
} from '@chakra-ui/react';
1818
import { JsonViewer } from '@textea/json-viewer';
19-
import { Barcode } from '@phosphor-icons/react';
19+
import { Barcode, DownloadSimple } from '@phosphor-icons/react';
2020
import { useTranslation } from 'react-i18next';
2121
import { Modal } from 'components/Modals/Modal';
2222
import { 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

Comments
 (0)