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

@@ -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")}