Revert "fix: address mobile dashboard review findings"
This reverts commit 1039bb18b3.
This commit is contained in:
1 parent
2f99f1f34b
commit
cd8773681f
12 files changed
+11
-103
No files matched your search
@@ -5,7 +5,6 @@ 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[];
|
||||
@@ -19,18 +18,12 @@ export const BeszelSystemsMobileSummary = ({
|
||||
statusFilter,
|
||||
}: BeszelSystemsMobileSummaryProps) => {
|
||||
const t = useI18n();
|
||||
const {
|
||||
data: results = [],
|
||||
error,
|
||||
isPending,
|
||||
isLoadingError,
|
||||
isRefetchError,
|
||||
} = clientApi.widget.beszel.getSystems.useQuery({ integrationIds });
|
||||
const { data: results = [], error, isPending } = clientApi.widget.beszel.getSystems.useQuery({ integrationIds });
|
||||
const systems = useBeszelFilteredSystems(results, statusFilter);
|
||||
const failedResults = results.filter((result) => "error" in result);
|
||||
|
||||
if (isPending) return <WidgetMobileLoading />;
|
||||
if (isLoadingError) throw error;
|
||||
if (error) throw error;
|
||||
if (results.length > 0 && failedResults.length === results.length) {
|
||||
throw new Error(String(failedResults[0]?.error ?? "Unable to connect to Beszel"));
|
||||
}
|
||||
@@ -45,7 +38,7 @@ export const BeszelSystemsMobileSummary = ({
|
||||
up,
|
||||
attention: systems.length - up,
|
||||
})}
|
||||
isStale={hasStaleIntegrationData(isRefetchError, failedResults)}
|
||||
isStale={failedResults.length > 0}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -1,2 +0,0 @@
|
||||
export const hasStaleIntegrationData = (isRefetchError: boolean, failedResults: readonly unknown[]) =>
|
||||
isRefetchError || failedResults.length > 0;
|
||||
@@ -28,14 +28,18 @@ export const toScopedStorageVolumeValue = (integrationId: string, value: string)
|
||||
return `${integrationId}:${volumeName}`;
|
||||
};
|
||||
|
||||
export const storageDeviceNamesMatch = (leftDeviceName: string, rightDeviceName: string): boolean => {
|
||||
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);
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -1,2 +0,0 @@
|
||||
export const formatDiskTemperature = (temperature: number | null | undefined, shouldShow: boolean) =>
|
||||
shouldShow && temperature != null ? `${temperature}°C` : undefined;
|
||||
@@ -1,20 +0,0 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
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`
|
||||
: "?";
|
||||
Reference in new issue
Block a user