From 4b0c69e6a3882ff78450570b9930f667bb321355 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Wed, 10 Jun 2026 18:13:38 +0200 Subject: [PATCH] fix(beszel): resolve lint errors in widget and API files Remove unused BeszelStatsData import from beszel router. Replace non-null assertions with safe fallbacks across beszel widget files (format.ts, chart.tsx, system-grid, system-stats). --- packages/api/src/router/widgets/beszel.ts | 2 +- .../src/beszel-system-grid/component.tsx | 33 +++++++++---------- .../src/beszel-system-stats/component.tsx | 2 +- packages/widgets/src/beszel/_shared/chart.tsx | 3 +- packages/widgets/src/beszel/_shared/format.ts | 4 +-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/api/src/router/widgets/beszel.ts b/packages/api/src/router/widgets/beszel.ts index ccf5a8852..d3b895d88 100644 --- a/packages/api/src/router/widgets/beszel.ts +++ b/packages/api/src/router/widgets/beszel.ts @@ -6,7 +6,7 @@ import { beszelStatsRequestHandler, beszelSystemsRequestHandler, } from "@homarr/request-handler/beszel"; -import type { BeszelAlertsData, BeszelStatsData, BeszelSystemRow } from "@homarr/request-handler/beszel"; +import type { BeszelAlertsData, BeszelSystemRow } from "@homarr/request-handler/beszel"; import { createManyIntegrationMiddleware } from "../../middlewares/integration"; import { createTRPCRouter, publicProcedure } from "../../trpc"; diff --git a/packages/widgets/src/beszel-system-grid/component.tsx b/packages/widgets/src/beszel-system-grid/component.tsx index 83efb69b6..f0a7c1ee0 100644 --- a/packages/widgets/src/beszel-system-grid/component.tsx +++ b/packages/widgets/src/beszel-system-grid/component.tsx @@ -37,22 +37,21 @@ interface SizeConfig { gap: number; } +const defaultSizeConfig: SizeConfig = { + iconSize: 10, + fontSize: "10px", + progressSize: "xs", + labelMiw: 40, + valueMiw: 30, + rowHeight: 18, + cardPadding: 4, + badgeHeight: 20, + badgeSize: "xs", + gap: 2, +}; + const sizeThresholds: [number, SizeConfig][] = [ - [ - 0, - { - iconSize: 10, - fontSize: "10px", - progressSize: "xs", - labelMiw: 40, - valueMiw: 30, - rowHeight: 18, - cardPadding: 4, - badgeHeight: 20, - badgeSize: "xs", - gap: 2, - }, - ], + [0, defaultSizeConfig], [ 160, { @@ -87,7 +86,7 @@ const sizeThresholds: [number, SizeConfig][] = [ const getSizeConfig = (cellWidth: number, cellHeight: number): SizeConfig => { const basis = Math.min(cellWidth, cellHeight); - let config = sizeThresholds[0]![1]; + let config = defaultSizeConfig; for (const [threshold, cfg] of sizeThresholds) { if (basis >= threshold) config = cfg; } @@ -254,7 +253,7 @@ const metricRenderers = [ key: "showBattery", render: (s: BeszelSystemRow, t: SystemCardProps["t"], sz: SizeConfig) => { const batteryIcons = [Battery, BatteryCharging] as const; - const Icon = batteryIcons[Math.min(1, s.battery?.[1] ?? 0)]!; + const Icon = batteryIcons[Math.min(1, s.battery?.[1] ?? 0)] ?? Battery; return ( ({ name, - color: containerColors[i % containerColors.length]!, + color: containerColors[i % containerColors.length] as string, })); const cols = width > 600 ? 2 : 1; diff --git a/packages/widgets/src/beszel/_shared/chart.tsx b/packages/widgets/src/beszel/_shared/chart.tsx index a654f126f..6100a7d37 100644 --- a/packages/widgets/src/beszel/_shared/chart.tsx +++ b/packages/widgets/src/beszel/_shared/chart.tsx @@ -97,7 +97,8 @@ export const useDockerChartData = ( ) => useMemo(() => { if (!containerStats?.length) return []; - const extract = defaultContainerExtractors[metric]!; + const extract = defaultContainerExtractors[metric]; + if (!extract) return []; return [...containerStats].toReversed().map((record) => { const point: Record = { time: formatTime(record.created) }; for (const name of containerNames) { diff --git a/packages/widgets/src/beszel/_shared/format.ts b/packages/widgets/src/beszel/_shared/format.ts index 8b3a0b29b..8e84c74e4 100644 --- a/packages/widgets/src/beszel/_shared/format.ts +++ b/packages/widgets/src/beszel/_shared/format.ts @@ -13,14 +13,14 @@ const formatScaled = (value: number, units: readonly string[], zeroLabel: string const i = Math.max(0, Math.min(Math.floor(Math.log(Math.abs(value)) / Math.log(1024)), units.length - 1)); const scaled = value / 1024 ** i; const decimals = scaled < 10 ? 2 : 1; - return `${scaled.toFixed(decimals)} ${units[i]!}`; + return `${scaled.toFixed(decimals)} ${units[i] ?? ""}`; }; const formatScaledCompact = (value: number, units: readonly string[], zeroLabel: string): string => { if (!value || !Number.isFinite(value)) return zeroLabel; const i = Math.max(0, Math.min(Math.floor(Math.log(Math.abs(value)) / Math.log(1024)), units.length - 1)); const scaled = value / 1024 ** i; - return `${scaled < 10 ? scaled.toFixed(1) : Math.round(scaled)}${units[i]!}`; + return `${scaled < 10 ? scaled.toFixed(1) : Math.round(scaled)}${units[i] ?? ""}`; }; export const formatByteRate = (value: number): string => formatScaled(value, rateUnits, "0 B/s");