fix: address mobile dashboard review findings

This commit is contained in:
ajnart committed 2026-07-28 19:39:12 +02:00
1 parent fa3d0375c5
commit 1039bb18b3
21 files changed
+175 -45

No files matched your search

@@ -13,6 +13,7 @@ import { useScopedI18n } from "@homarr/translation/client";
import type { WidgetComponentProps } from "../definition";
import { BeszelIntegrationErrorIndicator } from "../beszel/_shared/error-indicator";
import { hasStaleIntegrationData } from "../beszel/_shared/query-status";
import { WidgetMobileLoading, WidgetMobileSummary } from "../common/mobile-summary";
const alertIconMap: Record<string, LucideIcon> = {
@@ -43,7 +44,13 @@ export default function BeszelAlertsWidget({
() => ({ integrationIds, includeHistory: options.showHistory, maxHistoryItems: options.maxHistoryItems }),
[integrationIds, options.showHistory, options.maxHistoryItems],
);
const { data: results = [], error: alertsError, isPending } = clientApi.widget.beszel.getAlerts.useQuery(alertsInput);
const {
data: results = [],
error: alertsError,
isPending,
isLoadingError: alertsLoadingError,
isRefetchError: alertsRefetchError,
} = clientApi.widget.beszel.getAlerts.useQuery(alertsInput);
const systemNameMap = useMemo(() => {
const map: Record<string, string> = {};
@@ -72,7 +79,7 @@ export default function BeszelAlertsWidget({
const failedResults = results.filter((result) => "error" in result);
if (alertsError) throw alertsError;
if (alertsLoadingError) throw alertsError;
if (results.length > 0 && failedResults.length === results.length) {
throw new Error(String(failedResults[0]?.error ?? "Unable to connect to Beszel"));
}
@@ -93,7 +100,7 @@ export default function BeszelAlertsWidget({
value={triggeredAlerts.length}
label={t("status.triggered")}
description={`${alerts.length} ${t("name")}`}
isStale={failedResults.length > 0}
isStale={hasStaleIntegrationData(alertsRefetchError, failedResults)}
/>
);
}
@@ -101,7 +108,7 @@ export default function BeszelAlertsWidget({
return (
<Box h="100%" pos="relative">
<Box pos="absolute" top={4} right={8} style={{ zIndex: 1 }}>
<BeszelIntegrationErrorIndicator results={results} />
<BeszelIntegrationErrorIndicator results={results} isStale={alertsRefetchError} />
</Box>
<ScrollArea h="100%" style={{ pointerEvents: isEditMode ? "none" : undefined }}>
<Stack gap="sm" p="sm">
@@ -390,11 +390,13 @@ function BeszelSystemGridContent({
data: results = [],
error: systemsError,
isPending,
isLoadingError: systemsLoadingError,
isRefetchError: systemsRefetchError,
} = clientApi.widget.beszel.getSystems.useQuery({ integrationIds });
const filteredSystems = useBeszelFilteredSystems(results, options.statusFilter);
if (systemsError) throw systemsError;
if (systemsLoadingError) throw systemsError;
if (isPending) {
return (
@@ -407,7 +409,7 @@ function BeszelSystemGridContent({
if (filteredSystems.length === 0) {
return (
<Box h="100%" pos="relative" style={{ pointerEvents: isEditMode ? "none" : undefined }}>
<BeszelIntegrationErrorIndicator results={results} />
<BeszelIntegrationErrorIndicator results={results} isStale={systemsRefetchError} />
<Center h="100%">
<Stack align="center" gap="xs">
<IconServerOff size={28} opacity={0.5} />
@@ -431,7 +433,7 @@ function BeszelSystemGridContent({
return (
<Box h="100%" pos="relative" style={{ pointerEvents: isEditMode ? "none" : undefined }}>
<BeszelIntegrationErrorIndicator results={results} />
<BeszelIntegrationErrorIndicator results={results} isStale={systemsRefetchError} />
<Box
h="100%"
style={{
@@ -47,6 +47,8 @@ function BeszelSystemStatsContent({
data: systemsResult = [],
isPending: systemsPending,
error: systemsError,
isLoadingError: systemsLoadingError,
isRefetchError: systemsRefetchError,
} = clientApi.widget.beszel.getSystems.useQuery({ integrationIds });
const systems = useMemo(
@@ -78,7 +80,7 @@ function BeszelSystemStatsContent({
[setOptions, isReadOnly, hasChangeAccess, boardId, itemId, saveItemOptions],
);
if (systemsError) throw systemsError;
if (systemsLoadingError) throw systemsError;
if (systemsPending)
return (
<Center h="100%">
@@ -89,7 +91,7 @@ function BeszelSystemStatsContent({
if (systems.length === 0) {
return (
<Box h="100%" pos="relative">
<BeszelIntegrationErrorIndicator results={systemsResult} />
<BeszelIntegrationErrorIndicator results={systemsResult} isStale={systemsRefetchError} />
<Center h="100%">
<Stack align="center" gap="xs">
<IconServerOff size={28} opacity={0.5} />
@@ -125,7 +127,7 @@ function BeszelSystemStatsContent({
return (
<Box h="100%" pos="relative">
<Box pos="absolute" top={4} right={8} style={{ zIndex: 1 }}>
<BeszelIntegrationErrorIndicator results={systemsResult} />
<BeszelIntegrationErrorIndicator results={systemsResult} isStale={systemsRefetchError} />
</Box>
<ScrollArea
h="100%"
@@ -99,6 +99,8 @@ function BeszelSystemTableContent({
data: results = [],
error: systemsError,
isPending,
isLoadingError: systemsLoadingError,
isRefetchError: systemsRefetchError,
} = clientApi.widget.beszel.getSystems.useQuery({ integrationIds });
const size = getSizeConfig(width);
@@ -302,7 +304,7 @@ function BeszelSystemTableContent({
openModal({ integrationId, systemId: record.id }, { title: record.name });
};
if (systemsError) throw systemsError;
if (systemsLoadingError) throw systemsError;
if (isPending) {
return (
@@ -315,7 +317,7 @@ function BeszelSystemTableContent({
return (
<div style={{ position: "relative", height: "100%" }}>
<div style={{ position: "absolute", top: 4, right: 8, zIndex: 1 }}>
<BeszelIntegrationErrorIndicator results={results} />
<BeszelIntegrationErrorIndicator results={results} isStale={systemsRefetchError} />
</div>
<DataTable
style={{ pointerEvents: isEditMode ? "none" : undefined }}
@@ -3,6 +3,8 @@
import { Tooltip } from "@mantine/core";
import { IconAlertTriangle } from "@tabler/icons-react";
import { useI18n } from "@homarr/translation/client";
interface IntegrationResult {
integrationId: string;
integrationName?: string;
@@ -11,15 +13,25 @@ interface IntegrationResult {
interface BeszelIntegrationErrorIndicatorProps {
results: IntegrationResult[];
isStale?: boolean;
}
export function BeszelIntegrationErrorIndicator({ results }: BeszelIntegrationErrorIndicatorProps) {
export function BeszelIntegrationErrorIndicator({ results, isStale = false }: BeszelIntegrationErrorIndicatorProps) {
const t = useI18n();
const failed = results.filter((r) => "error" in r && r.error);
if (failed.length === 0) return null;
const label = failed.map((r) => r.integrationName ?? r.integrationId).join(", ");
if (failed.length === 0 && !isStale) return null;
const label =
failed.length > 0
? failed.map((r) => r.integrationName ?? r.integrationId).join(", ")
: t("board.mobile.dataWarning");
return (
<Tooltip label={label} position="left" withArrow>
<IconAlertTriangle size={14} color="var(--mantine-color-orange-6)" style={{ cursor: "help", flexShrink: 0 }} />
<IconAlertTriangle
size={14}
color="var(--mantine-color-orange-6)"
style={{ cursor: "help", flexShrink: 0 }}
aria-label={label}
/>
</Tooltip>
);
}
@@ -5,6 +5,7 @@ import { useI18n } from "@homarr/translation/client";
import { WidgetMobileLoading, WidgetMobileSummary } from "../../common/mobile-summary";
import { useBeszelFilteredSystems } from "./hooks";
import { hasStaleIntegrationData } from "./query-status";
interface BeszelSystemsMobileSummaryProps {
integrationIds: string[];
@@ -18,12 +19,18 @@ export const BeszelSystemsMobileSummary = ({
statusFilter,
}: BeszelSystemsMobileSummaryProps) => {
const t = useI18n();
const { data: results = [], error, isPending } = clientApi.widget.beszel.getSystems.useQuery({ integrationIds });
const {
data: results = [],
error,
isPending,
isLoadingError,
isRefetchError,
} = clientApi.widget.beszel.getSystems.useQuery({ integrationIds });
const systems = useBeszelFilteredSystems(results, statusFilter);
const failedResults = results.filter((result) => "error" in result);
if (isPending) return <WidgetMobileLoading />;
if (error) throw error;
if (isLoadingError) throw error;
if (results.length > 0 && failedResults.length === results.length) {
throw new Error(String(failedResults[0]?.error ?? "Unable to connect to Beszel"));
}
@@ -38,7 +45,7 @@ export const BeszelSystemsMobileSummary = ({
up,
attention: systems.length - up,
})}
isStale={failedResults.length > 0}
isStale={hasStaleIntegrationData(isRefetchError, failedResults)}
/>
);
};
@@ -0,0 +1,11 @@
import { describe, expect, test } from "vitest";
import { hasStaleIntegrationData } from "./query-status";
describe("Beszel query status", () => {
test("marks cached data stale after outer or per-integration failures", () => {
expect(hasStaleIntegrationData(true, [])).toBe(true);
expect(hasStaleIntegrationData(false, [{ error: "offline" }])).toBe(true);
expect(hasStaleIntegrationData(false, [])).toBe(false);
});
});
@@ -0,0 +1,2 @@
export const hasStaleIntegrationData = (isRefetchError: boolean, failedResults: readonly unknown[]) =>
isRefetchError || failedResults.length > 0;
@@ -1,7 +1,7 @@
"use client";
import { useMemo } from "react";
import { Button, Center, Group, SimpleGrid, Skeleton, Stack, Text } from "@mantine/core";
import { Box, Button, Center, Group, SimpleGrid, Skeleton, Stack, Text } from "@mantine/core";
import { IconPlugConnectedX, IconServerOff } from "@tabler/icons-react";
import { clientApi } from "@homarr/api/client";
@@ -19,6 +19,7 @@ import {
useSystemChartData,
} from "./chart";
import { chartAxisFormatters, formatByteRate, formatGB, formatPercent, formatStorageBytes } from "./format";
import { BeszelIntegrationErrorIndicator } from "./error-indicator";
import { makeTooltipProps } from "./tooltip";
import { useLiveStats } from "./use-live-stats";
@@ -74,7 +75,12 @@ export function BeszelStatsView({
const showDocker = visibility.dockerCpu || visibility.dockerMemory || visibility.dockerNetwork;
const isLive = timePeriod === "1m";
const { data: historicalData, error: historicalError } = clientApi.widget.beszel.getSystemStats.useQuery(
const {
data: historicalData,
error: historicalError,
isLoadingError: historicalLoadingError,
isRefetchError: historicalRefetchError,
} = clientApi.widget.beszel.getSystemStats.useQuery(
{ integrationIds, systemId, timePeriod, includeDocker: showDocker },
{ refetchInterval: isLive ? false : 5_000, enabled: !isLive && systemId !== "" },
);
@@ -175,7 +181,7 @@ export function BeszelStatsView({
timePeriod,
);
if (historicalError) throw historicalError;
if (!isLive && historicalLoadingError) throw historicalError;
if (isLive && liveError) {
return (
@@ -220,7 +226,10 @@ export function BeszelStatsView({
}
return (
<SimpleGrid cols={columns} spacing="md">
<SimpleGrid cols={columns} spacing="md" pos="relative">
<Box pos="absolute" top={0} right={0} style={{ zIndex: 1 }}>
<BeszelIntegrationErrorIndicator results={[]} isStale={historicalRefetchError} />
</Box>
{visibility.cpu && cpuData.length > 0 && (
<BeszelChartPanel
title={t("chart.cpu.title")}
@@ -3,6 +3,7 @@ import { describe, expect, test } from "vitest";
import {
filterStorageVolumes,
normalizeStorageDeviceName,
storageDeviceNamesMatch,
toScopedStorageVolumeValue,
} from "./filter-storage-volumes";
import { matchFileSystemAndSmart } from "./health-monitoring/system-health";
@@ -30,6 +31,14 @@ describe("normalizeStorageDeviceName", () => {
});
});
describe("storageDeviceNamesMatch", () => {
test("matches partitions to their base SMART device without merging unrelated devices", () => {
expect(storageDeviceNamesMatch("/dev/sda1", "/dev/sda")).toBe(true);
expect(storageDeviceNamesMatch("/dev/nvme0n1p2", "/dev/nvme0n1")).toBe(true);
expect(storageDeviceNamesMatch("/dev/md0", "/dev/md1")).toBe(false);
});
});
describe("toScopedStorageVolumeValue", () => {
test("scopes unscoped volume names to the query integration", () => {
expect(toScopedStorageVolumeValue("nas-a", "volume_1")).toBe("nas-a:volume_1");
@@ -28,18 +28,14 @@ export const toScopedStorageVolumeValue = (integrationId: string, value: string)
return `${integrationId}:${volumeName}`;
};
const storageDeviceNamesMatch = (leftDeviceName: string, rightDeviceName: string): boolean => {
export const storageDeviceNamesMatch = (leftDeviceName: string, rightDeviceName: string): boolean => {
return (
leftDeviceName === rightDeviceName ||
normalizeStorageDeviceName(leftDeviceName) === normalizeStorageDeviceName(rightDeviceName)
);
};
const matchesVisibleStorageVolume = (
visibleVolume: string,
integrationId: string,
deviceName: string,
): boolean => {
const matchesVisibleStorageVolume = (visibleVolume: string, integrationId: string, deviceName: string): boolean => {
const separatorIndex = visibleVolume.indexOf(":");
if (separatorIndex === -1) {
return storageDeviceNamesMatch(visibleVolume, deviceName);
@@ -10,9 +10,10 @@ import { useI18n } from "@homarr/translation/client";
import { WidgetEmptyState } from "../common/empty-state";
import { WidgetMobileLoading, WidgetMobileSummary } from "../common/mobile-summary";
import type { WidgetComponentProps } from "../definition";
import { filterStorageVolumes } from "../filter-storage-volumes";
import { NoIntegrationDataError } from "../errors/no-data-integration";
import { filterStorageVolumes, storageDeviceNamesMatch } from "../filter-storage-volumes";
import type { WidgetComponentProps } from "../definition";
import { formatDiskTemperature } from "./mobile-summary";
type DisplayMode = WidgetComponentProps<"systemDisks">["options"]["displayMode"];
@@ -81,6 +82,7 @@ const SystemDiskCard = ({
}, [displayText, healthy]);
const unhealthyLabel = t("widget.systemDisks.status.unhealthy");
const temperatureLabel = formatDiskTemperature(temperature, true);
return (
<Tooltip
@@ -105,7 +107,7 @@ const SystemDiskCard = ({
{!healthy && <span style={{ marginLeft: 5 }}>{unhealthyLabel}</span>}
</p>
</div>
<div>{temperature ? <p style={{ margin: 0 }}>{temperature}°C</p> : null}</div>
<div>{temperatureLabel ? <p style={{ margin: 0 }}>{temperatureLabel}</p> : null}</div>
</Group>
<Box
bg={healthy ? "green" : "red"}
@@ -155,10 +157,9 @@ export default function SystemResources({
const disk = fileSystem.toSorted((diskA, diskB) => diskB.percentage - diskA.percentage)[0];
if (!disk) return <WidgetEmptyState />;
const smartItem = smart.find((item) => item.deviceName === disk.deviceName);
const smartItem = smart.find((item) => storageDeviceNamesMatch(item.deviceName, disk.deviceName));
const isHealthy = smartItem?.healthy ?? true;
const temperature =
options.showTemperatureIfAvailable && smartItem?.temperature ? `${smartItem.temperature}°C` : undefined;
const temperature = formatDiskTemperature(smartItem?.temperature, options.showTemperatureIfAvailable);
return (
<WidgetMobileSummary
@@ -173,7 +174,7 @@ export default function SystemResources({
return (
<Stack gap="xs" p="xs" h="100%">
{fileSystem.map((item) => {
const smartItem = smart.find((smartEntry) => smartEntry.deviceName === item.deviceName);
const smartItem = smart.find((smartEntry) => storageDeviceNamesMatch(smartEntry.deviceName, item.deviceName));
return (
<SystemDiskCard
@@ -0,0 +1,15 @@
import { describe, expect, test } from "vitest";
import { formatDiskTemperature } from "./mobile-summary";
describe("formatDiskTemperature", () => {
test("preserves a valid zero-degree reading", () => {
expect(formatDiskTemperature(0, true)).toBe("0°C");
});
test("omits unavailable or disabled readings", () => {
expect(formatDiskTemperature(null, true)).toBeUndefined();
expect(formatDiskTemperature(undefined, true)).toBeUndefined();
expect(formatDiskTemperature(20, false)).toBeUndefined();
});
});
@@ -0,0 +1,2 @@
export const formatDiskTemperature = (temperature: number | null | undefined, shouldShow: boolean) =>
shouldShow && temperature != null ? `${temperature}°C` : undefined;
+1 -7
View File
@@ -14,6 +14,7 @@ import { WidgetEmptyState } from "../common/empty-state";
import type { WidgetComponentProps } from "../definition";
import { AnimatedWeatherIcon } from "./animated-icon";
import { WeatherDescription } from "./icon";
import { getPreferredUnit } from "./temperature";
export default function WeatherWidget({ isEditMode, options }: WidgetComponentProps<"weather">) {
const input = {
@@ -247,10 +248,3 @@ function Forecast({ weather, options }: WeatherProps) {
</Group>
);
}
const getPreferredUnit = (value?: number, isFahrenheit = false, disableTemperatureDecimals = false): string =>
value
? isFahrenheit
? `${(value * (9 / 5) + 32).toFixed(disableTemperatureDecimals ? 0 : 1)}°F`
: `${value.toFixed(disableTemperatureDecimals ? 0 : 1)}°C`
: "?";
@@ -0,0 +1,20 @@
import { describe, expect, test } from "vitest";
import { getPreferredUnit } from "./temperature";
describe("getPreferredUnit", () => {
test("preserves zero in Celsius and Fahrenheit", () => {
expect(getPreferredUnit(0)).toBe("0.0°C");
expect(getPreferredUnit(0, true)).toBe("32.0°F");
});
test("only uses the unavailable placeholder for missing values", () => {
expect(getPreferredUnit(undefined)).toBe("?");
});
test("respects the decimal preference", () => {
expect(getPreferredUnit(0, false, true)).toBe("0°C");
expect(getPreferredUnit(0, true, true)).toBe("32°F");
expect(getPreferredUnit(12.6, false, true)).toBe("13°C");
});
});
@@ -0,0 +1,6 @@
export const getPreferredUnit = (value?: number, isFahrenheit = false, disableTemperatureDecimals = false): string =>
value !== undefined
? isFahrenheit
? `${(value * (9 / 5) + 32).toFixed(disableTemperatureDecimals ? 0 : 1)}°F`
: `${value.toFixed(disableTemperatureDecimals ? 0 : 1)}°C`
: "?";