diff --git a/internal/site/src/components/systems-table/systems-table-columns.tsx b/internal/site/src/components/systems-table/systems-table-columns.tsx index 1c004d8b4..744493d4b 100644 --- a/internal/site/src/components/systems-table/systems-table-columns.tsx +++ b/internal/site/src/components/systems-table/systems-table-columns.tsx @@ -38,7 +38,7 @@ import { secondsToUptimeString, } from "@/lib/utils" import { batteryStateTranslations } from "@/lib/i18n" -import { connectedWiFi, strongestWiFi, strongestWiFiSignal } from "@/lib/wifi" +import { connectedWiFi, strongestWiFi, strongestWiFiSignal, wifiSignalState } from "@/lib/wifi" import type { SystemRecord, WiFi } from "@/types" import { SystemDialog } from "../add-system" import AlertButton from "../alerts/alert-button" @@ -363,7 +363,6 @@ export function SystemsTableColumns(viewMode: "table" | "grid"): ColumnDef (wifi.r === undefined ? "—" : `${wifi.r} dBm`) return ( @@ -373,9 +372,7 @@ export function SystemsTableColumns(viewMode: "table" | "grid"): ColumnDef {displayedConnections.map(([id, wifi]) => ( - - {signal(wifi)} - + ))} {viewMode === "table" && connections.length > 1 && ( +{connections.length - 1} @@ -389,8 +386,8 @@ export function SystemsTableColumns(viewMode: "table" | "grid"): ColumnDef {id} -
- {signal(wifi)} +
+ {wifi.s && {wifi.s}}
@@ -702,6 +699,22 @@ function DiskCellWithMultiple(info: CellContext) { ) } +function WiFiSignal({ wifi, className }: { wifi: WiFi; className?: ClassValue }) { + const state = wifi.r === undefined ? undefined : wifiSignalState(wifi.r) + return ( + + + {wifi.r === undefined ? "—" : `${wifi.r} dBm`} + + ) +} + export function IndicatorDot({ system, className }: { system: SystemRecord; className?: ClassValue }) { className ||= STATUS_COLORS[system.status as keyof typeof STATUS_COLORS] || "" return ( diff --git a/internal/site/src/lib/wifi.test.ts b/internal/site/src/lib/wifi.test.ts index e3e721f75..ce652c2a1 100644 --- a/internal/site/src/lib/wifi.test.ts +++ b/internal/site/src/lib/wifi.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test" -import { connectedWiFi, strongestWiFiSignal, wifiColor } from "./wifi" +import { MeterState } from "@/lib/enums" +import { connectedWiFi, strongestWiFiSignal, wifiColor, wifiSignalState } from "./wifi" import type { SystemInfo } from "@/types" const system = (wf?: SystemInfo["wf"], status: "up" | "down" = "up") => ({ status, info: { wf } as SystemInfo }) @@ -26,3 +27,11 @@ test("strongestWiFiSignal returns the strongest current native RSSI", () => { expect(strongestWiFiSignal(system({ wlan0: {} }))).toBeUndefined() expect(strongestWiFiSignal(system({ wlan0: { r: -48 } }, "down"))).toBeUndefined() }) + +test("wifiSignalState thresholds", () => { + expect(wifiSignalState(-40)).toBe(MeterState.Good) + expect(wifiSignalState(-65)).toBe(MeterState.Good) + expect(wifiSignalState(-66)).toBe(MeterState.Warn) + expect(wifiSignalState(-75)).toBe(MeterState.Warn) + expect(wifiSignalState(-76)).toBe(MeterState.Crit) +}) diff --git a/internal/site/src/lib/wifi.ts b/internal/site/src/lib/wifi.ts index ca156490f..8e03fea0a 100644 --- a/internal/site/src/lib/wifi.ts +++ b/internal/site/src/lib/wifi.ts @@ -1,3 +1,4 @@ +import { MeterState } from "@/lib/enums" import type { SystemRecord, WiFi } from "@/types" // Current system info is independent of the selected historical chart window. @@ -21,6 +22,11 @@ export function strongestWiFiSignal(system: Pick= -65 ? MeterState.Good : rssi >= -75 ? MeterState.Warn : MeterState.Crit +} + export function wifiColor(id: string): string { let hash = 0 for (const char of id) hash = (Math.imul(hash, 31) + char.charCodeAt(0)) | 0