import { Center, createStyles, Grid, Stack, Text, Title } from '@mantine/core'; import { IconUnlink } from '@tabler/icons'; import { useQuery } from '@tanstack/react-query'; import axios from 'axios'; import { useTranslation } from 'next-i18next'; import { useConfigContext } from '../../config/provider'; import { defineWidget } from '../helper'; import { IWidget } from '../widgets'; import { DashDotInfo } from './DashDotCompactNetwork'; import { DashDotGraph } from './DashDotGraph'; const definition = defineWidget({ id: 'dashdot', icon: 'https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/dashdot.png', options: { url: { type: 'text', defaultValue: '', }, usePercentages: { type: 'switch', defaultValue: false, }, columns: { type: 'number', defaultValue: 2, }, graphHeight: { type: 'number', defaultValue: 115, inputProps: { step: 5, stepHoldDelay: 500, stepHoldInterval: 100, }, }, graphsOrder: { type: 'draggable-list', defaultValue: [ { key: 'storage', subValues: { enabled: true, compactView: true, span: 2, multiView: false, }, }, { key: 'network', subValues: { enabled: true, compactView: true, span: 2, }, }, { key: 'cpu', subValues: { enabled: true, multiView: false, span: 1, }, }, { key: 'ram', subValues: { enabled: true, span: 1, }, }, { key: 'gpu', subValues: { enabled: false, span: 1, }, }, ], items: { cpu: { enabled: { type: 'switch', }, span: { type: 'number', }, multiView: { type: 'switch', }, }, storage: { enabled: { type: 'switch', }, span: { type: 'number', }, compactView: { type: 'switch', }, multiView: { type: 'switch', }, }, ram: { enabled: { type: 'switch', }, span: { type: 'number', }, }, network: { enabled: { type: 'switch', }, span: { type: 'number', }, compactView: { type: 'switch', }, }, gpu: { enabled: { type: 'switch', }, span: { type: 'number', }, }, }, }, }, gridstack: { minWidth: 2, minHeight: 2, maxWidth: 12, maxHeight: 14, }, component: DashDotTile, }); export type IDashDotTile = IWidget<(typeof definition)['id'], typeof definition>; interface DashDotTileProps { widget: IDashDotTile; } function DashDotTile({ widget }: DashDotTileProps) { const { classes } = useDashDotTileStyles(); const { t } = useTranslation('modules/dashdot'); const dashDotUrl = widget.properties.url; const locationProtocol = window.location.protocol; const detectedProtocolDowngrade = locationProtocol === 'https:' && dashDotUrl.toLowerCase().startsWith('http:'); const { data: info } = useDashDotInfo({ dashDotUrl, enabled: !detectedProtocolDowngrade, }); if (detectedProtocolDowngrade) { return (
{t('card.errors.noInformation')}
} {info && (