fix: address mobile dashboard review findings
This commit is contained in:
1 parent
c1efaabd36
commit
b4404113c4
11 files changed
+101
-5
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user