fix(widgets): restore compact v1 surfaces (#6710)
This commit is contained in:
1 parent
1b2f1bd720
commit
643ecf3df7
105 files changed
+1603
-1285
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { aggregateUptimeKumaDashboards } from "./aggregate";
|
||||
import { getCompactStatLimit, getCompactStatPriority } from "./component";
|
||||
|
||||
describe("aggregateUptimeKumaDashboards", () => {
|
||||
it("weights uptime by monitors instead of integrations", () => {
|
||||
@@ -30,26 +29,3 @@ describe("aggregateUptimeKumaDashboards", () => {
|
||||
expect(combined.averageUptimePercent).toBe(25);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getCompactStatLimit", () => {
|
||||
it("reserves compact height for the uptime summary", () => {
|
||||
expect(getCompactStatLimit(150, true, 4)).toBe(0);
|
||||
expect(getCompactStatLimit(220, true, 4)).toBe(2);
|
||||
});
|
||||
|
||||
it("uses the space for metrics when the summary is disabled", () => {
|
||||
expect(getCompactStatLimit(100, false, 4)).toBe(2);
|
||||
expect(getCompactStatLimit(240, false, 4)).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getCompactStatPriority", () => {
|
||||
it("puts active failures before healthy totals", () => {
|
||||
expect(getCompactStatPriority("downCount", 2)).toBeLessThan(getCompactStatPriority("totalMonitors", 10));
|
||||
expect(getCompactStatPriority("pausedCount", 1)).toBeLessThan(getCompactStatPriority("upCount", 8));
|
||||
});
|
||||
|
||||
it("moves zero-value problem states behind healthy totals", () => {
|
||||
expect(getCompactStatPriority("downCount", 0)).toBeGreaterThan(getCompactStatPriority("upCount", 8));
|
||||
});
|
||||
});
|
||||
@@ -79,25 +79,6 @@ const heroVariantByRing = {
|
||||
false: classes.heroTextOnly,
|
||||
} as const;
|
||||
|
||||
export function getCompactStatLimit(height: number, showHero: boolean, statCount: number): number {
|
||||
if (showHero) {
|
||||
if (height < 180) return 0;
|
||||
if (height < 260) return Math.min(2, statCount);
|
||||
if (height < 340) return Math.min(4, statCount);
|
||||
} else {
|
||||
if (height < 130) return Math.min(2, statCount);
|
||||
if (height < 220) return Math.min(4, statCount);
|
||||
}
|
||||
return statCount;
|
||||
}
|
||||
|
||||
export function getCompactStatPriority(statKey: keyof typeof statIcons, value: number): number {
|
||||
if (statKey === "downCount") return value > 0 ? 0 : 4;
|
||||
if (statKey === "pausedCount") return value > 0 ? 1 : 5;
|
||||
if (statKey === "totalMonitors") return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
export default function UptimeKumaWidget({
|
||||
integrationIds,
|
||||
options,
|
||||
@@ -158,16 +139,8 @@ function UptimeKumaContent({ integrationIds, options, width, height, displayMode
|
||||
.map(([, statKey]) => statKey);
|
||||
|
||||
const showHero = isAdvanced || options.showAverageUptime;
|
||||
const showRing = isAdvanced || (options.showUptimeRing && width >= 170 && height >= 110);
|
||||
const prioritizedStatKeys = isAdvanced
|
||||
? enabledStatKeys
|
||||
: enabledStatKeys.toSorted(
|
||||
(left, right) => getCompactStatPriority(left, combined[left]) - getCompactStatPriority(right, combined[right]),
|
||||
);
|
||||
const visibleStatKeys = prioritizedStatKeys.slice(
|
||||
0,
|
||||
isAdvanced ? prioritizedStatKeys.length : getCompactStatLimit(height, showHero, prioritizedStatKeys.length),
|
||||
);
|
||||
const showRing = isAdvanced || options.showUptimeRing;
|
||||
const visibleStatKeys = enabledStatKeys;
|
||||
const hasContent = showHero || visibleStatKeys.length > 0;
|
||||
|
||||
const heroLayoutClass =
|
||||
@@ -227,24 +200,6 @@ function UptimeKumaContent({ integrationIds, options, width, height, displayMode
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{displayMode === "compact" && height >= 300 && combined.downCount > 0 && (
|
||||
<Stack gap={2} px="sm">
|
||||
{monitors
|
||||
.filter((monitor) => monitor.status === "down")
|
||||
.slice(0, 3)
|
||||
.map((monitor) => (
|
||||
<Group key={monitor.key} justify="space-between" wrap="nowrap">
|
||||
<Text size="xs" truncate>
|
||||
{monitor.name}
|
||||
</Text>
|
||||
<Badge size="xs" color="red">
|
||||
{t("status.down")} ·{" "}
|
||||
{monitor.uptimePercent24h === null ? "—" : `${formatNumber(monitor.uptimePercent24h, 1)}%`}
|
||||
</Badge>
|
||||
</Group>
|
||||
))}
|
||||
</Stack>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user