feat!: release v2 (#6545)

Co-authored-by: Artur <145776561+arturict@users.noreply.github.com>
Co-authored-by: arturict <arturict@users.noreply.github.com>
Co-authored-by: Thomas <thomas@ajnart.fr>
Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com>
Co-authored-by: Danura30082 <danura30082+github@gmail.com>
Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com>
Co-authored-by: ajnart <thomas@ajnart.fr>
Co-authored-by: ajnart <thomas@ajnart.dev>
Co-authored-by: chenjun <chenjun@foxmail.com>
Co-authored-by: Wikibear <wikibear@users.noreply.github.com>
Co-authored-by: Bergasha <bergasha@gmail.com>
Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com>
Co-authored-by: Lucas Araujo <lucas.lra@gmail.com>
Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com>
Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social>
Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com>
Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com>
Co-authored-by: thrawnx <tight.bulb9384@fastmail.com>
Co-authored-by: Chris <58918656+nordada@users.noreply.github.com>
Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com>
Co-authored-by: Yanis <naamaneyanis@gmail.com>
Co-authored-by: Wikibear <me@sej.de>
Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386 -139176

No files matched your search

@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest";
import { aggregateUptimeKumaDashboards } from "./aggregate";
describe("aggregateUptimeKumaDashboards", () => {
it("weights uptime by monitors instead of integrations", () => {
const combined = aggregateUptimeKumaDashboards([
{
totalMonitors: 1,
upCount: 1,
downCount: 0,
pausedCount: 0,
averageUptimePercent: 100,
monitors: [{ id: 1, name: "one", status: "up", uptimePercent24h: 100 }],
},
{
totalMonitors: 3,
upCount: 0,
downCount: 3,
pausedCount: 0,
averageUptimePercent: 0,
monitors: [
{ id: 2, name: "two", status: "down", uptimePercent24h: 0 },
{ id: 3, name: "three", status: "down", uptimePercent24h: 0 },
{ id: 4, name: "four", status: "down", uptimePercent24h: 0 },
],
},
]);
expect(combined.averageUptimePercent).toBe(25);
});
});
@@ -0,0 +1,30 @@
import type { UptimeKumaDashboardData } from "@homarr/integrations/types";
const emptyDashboard: UptimeKumaDashboardData = {
totalMonitors: 0,
upCount: 0,
downCount: 0,
pausedCount: 0,
averageUptimePercent: 0,
monitors: [],
};
export function aggregateUptimeKumaDashboards(dashboards: UptimeKumaDashboardData[]): UptimeKumaDashboardData {
const combined = dashboards.reduce<UptimeKumaDashboardData>(
(acc, dashboard) => ({
totalMonitors: acc.totalMonitors + dashboard.totalMonitors,
upCount: acc.upCount + dashboard.upCount,
downCount: acc.downCount + dashboard.downCount,
pausedCount: acc.pausedCount + dashboard.pausedCount,
averageUptimePercent: 0,
monitors: [...acc.monitors, ...dashboard.monitors],
}),
emptyDashboard,
);
const uptimeValues = combined.monitors
.map((monitor) => monitor.uptimePercent24h)
.filter((value): value is number => value !== null);
combined.averageUptimePercent =
uptimeValues.reduce((total, value) => total + value, 0) / Math.max(uptimeValues.length, 1);
return combined;
}
@@ -4,8 +4,8 @@
flex-direction: column;
height: 100%;
min-height: 0;
padding: clamp(6px, 3cqi, 14px);
gap: clamp(4px, 2cqi, 10px);
padding: clamp(6px, 3cqmin, 14px);
gap: clamp(4px, 2cqmin, 10px);
overflow: hidden;
}
@@ -13,10 +13,10 @@
display: flex;
align-items: center;
justify-content: space-between;
gap: clamp(8px, 3cqi, 18px);
gap: clamp(8px, 3cqmin, 18px);
flex-shrink: 0;
padding-bottom: clamp(4px, 2cqi, 10px);
border-bottom: 1px solid light-dark(var(--mantine-color-gray-2), var(--mantine-color-dark-4));
padding-bottom: clamp(4px, 2cqmin, 10px);
border-bottom: 1px solid rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45));
}
.heroExpanded {
@@ -36,25 +36,25 @@
}
.heroTextOnly .heroValue {
font-size: clamp(22px, 10cqi, 36px);
font-size: clamp(22px, 10cqmin, 36px);
}
.heroText {
display: flex;
flex-direction: column;
gap: clamp(2px, 1cqi, 4px);
gap: clamp(2px, 1cqmin, 4px);
min-width: 0;
flex: 1;
}
.heroLabel {
font-size: clamp(9px, 2.8cqi, 13px);
font-size: clamp(9px, 2.8cqmin, 13px);
color: var(--mantine-color-dimmed);
line-height: 1.2;
}
.heroValue {
font-size: clamp(18px, 8cqi, 32px);
font-size: clamp(18px, 8cqmin, 32px);
font-weight: 700;
line-height: 1.1;
}
@@ -67,7 +67,7 @@
display: grid;
flex: 1;
min-height: 0;
gap: clamp(4px, 2cqi, 10px);
gap: clamp(4px, 2cqmin, 10px);
grid-template-columns: repeat(var(--stat-cols, 2), minmax(0, 1fr));
grid-auto-rows: 1fr;
align-content: stretch;
@@ -80,10 +80,11 @@
justify-content: center;
min-height: 0;
min-width: 0;
gap: clamp(2px, 1.5cqi, 5px);
padding: clamp(4px, 2.5cqi, 10px);
gap: clamp(2px, 1.5cqmin, 5px);
padding: clamp(4px, 2.5cqmin, 10px);
border-radius: var(--mantine-radius-md);
background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-6));
border: 1px solid rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45));
background-color: transparent;
overflow: hidden;
}
@@ -92,14 +93,14 @@
}
.statValue {
font-size: clamp(14px, 5.5cqi, 24px);
font-size: clamp(14px, 5.5cqmin, 24px);
font-weight: 700;
line-height: 1.1;
text-align: center;
}
.statLabel {
font-size: clamp(8px, 2.5cqi, 12px);
font-size: clamp(8px, 2.5cqmin, 12px);
color: var(--mantine-color-dimmed);
line-height: 1.2;
text-align: center;
@@ -116,6 +117,6 @@
justify-content: center;
min-height: 0;
color: var(--mantine-color-dimmed);
font-size: clamp(11px, 3cqi, 14px);
font-size: clamp(11px, 3cqmin, 14px);
text-align: center;
}
+118 -40
View File
@@ -1,27 +1,21 @@
"use client";
import type { CSSProperties } from "react";
import { RingProgress, Text } from "@mantine/core";
import { Badge, Box, Group, RingProgress, ScrollArea, SimpleGrid, Stack, Text } from "@mantine/core";
import { IconArrowDown, IconArrowUp, IconClockPause, IconServer } from "@tabler/icons-react";
import { clientApi } from "@homarr/api/client";
import { formatNumber } from "@homarr/common";
import type { UptimeKumaDashboardData } from "@homarr/integrations/types";
import { useScopedI18n } from "@homarr/translation/client";
import { useI18n } from "@homarr/translation/client";
import { zoomCompensatedSize } from "@homarr/ui";
import { WidgetEmptyState } from "../common/empty-state";
import { IntegrationErrorIndicator } from "../common/integration-error-indicator";
import type { WidgetComponentProps } from "../definition";
import { getUsableWidgetQueryData } from "../common/query-state";
import { NoIntegrationDataError } from "../errors/no-data-integration";
import classes from "./component.module.css";
const emptyDashboard: UptimeKumaDashboardData = {
totalMonitors: 0,
upCount: 0,
downCount: 0,
pausedCount: 0,
averageUptimePercent: 0,
monitors: [],
};
import { aggregateUptimeKumaDashboards } from "./aggregate";
const statVisibilityByOption = {
showTotalMonitors: "totalMonitors",
@@ -85,58 +79,76 @@ const heroVariantByRing = {
false: classes.heroTextOnly,
} as const;
export default function UptimeKumaWidget({ integrationIds, options, width }: WidgetComponentProps<"uptimeKuma">) {
export default function UptimeKumaWidget({
integrationIds,
options,
width,
height,
displayMode = "compact",
}: WidgetComponentProps<"uptimeKuma">) {
if (integrationIds.length === 0) {
throw new NoIntegrationDataError();
}
return <UptimeKumaContent integrationIds={integrationIds} options={options} width={width} />;
return (
<UptimeKumaContent
integrationIds={integrationIds}
options={options}
width={width}
height={height}
displayMode={displayMode}
/>
);
}
interface UptimeKumaContentProps {
integrationIds: string[];
options: WidgetComponentProps<"uptimeKuma">["options"];
width: number;
height: number;
displayMode: "compact" | "advanced";
}
function UptimeKumaContent({ integrationIds, options, width }: UptimeKumaContentProps) {
const t = useScopedI18n("widget.uptimeKuma");
const { data: dashboardData } = clientApi.widget.uptimeKuma.getDashboard.useQuery({ integrationIds });
function UptimeKumaContent({ integrationIds, options, width, height, displayMode }: UptimeKumaContentProps) {
const t = useI18n("widget.uptimeKuma");
const dashboardQuery = clientApi.widget.uptimeKuma.getDashboard.useQuery({ integrationIds });
const dashboardData = getUsableWidgetQueryData(dashboardQuery);
if (!dashboardData) return <WidgetEmptyState />;
const combined = dashboardData.reduce<UptimeKumaDashboardData>(
(acc, item) => ({
totalMonitors: acc.totalMonitors + item.dashboard.totalMonitors,
upCount: acc.upCount + item.dashboard.upCount,
downCount: acc.downCount + item.dashboard.downCount,
pausedCount: acc.pausedCount + item.dashboard.pausedCount,
averageUptimePercent: acc.averageUptimePercent + item.dashboard.averageUptimePercent,
monitors: [...acc.monitors, ...item.dashboard.monitors],
}),
emptyDashboard,
const successfulDashboardData = dashboardData.flatMap((item) =>
item.dashboard === null ? [] : [{ ...item, dashboard: item.dashboard }],
);
const instanceCount = dashboardData.length;
const averageUptime = combined.averageUptimePercent / Math.max(instanceCount, 1);
const uptimeValue = clampPercent(averageUptime);
const combined = aggregateUptimeKumaDashboards(successfulDashboardData.map((item) => item.dashboard));
const monitors = successfulDashboardData.flatMap((result) =>
result.dashboard.monitors.map((monitor) => ({
...monitor,
key: `${result.integrationId}:${monitor.id}`,
integrationName: result.integrationName,
})),
);
const uptimeValue = clampPercent(combined.averageUptimePercent);
const uptimeColor = getUptimeColor(uptimeValue);
const ringSize = getRingSize(width);
const iconSize = getIconSize(width);
const visualScale = Math.min(width, height);
const ringSize = getRingSize(visualScale);
const iconSize = getIconSize(visualScale);
const gridCols = getGridCols(width);
const isAdvanced = displayMode === "advanced";
const visibleStatKeys = Object.entries(statVisibilityByOption)
.filter(([optionKey]) => options[optionKey as keyof typeof options])
const enabledStatKeys = Object.entries(statVisibilityByOption)
.filter(([optionKey]) => isAdvanced || options[optionKey as keyof typeof options])
.map(([, statKey]) => statKey);
const showHero = options.showAverageUptime;
const showHero = isAdvanced || options.showAverageUptime;
const showRing = isAdvanced || options.showUptimeRing;
const visibleStatKeys = enabledStatKeys;
const hasContent = showHero || visibleStatKeys.length > 0;
const heroLayoutClass =
heroLayoutBySecondaryStats[String(visibleStatKeys.length > 0) as keyof typeof heroLayoutBySecondaryStats];
const heroRingClass = heroVariantByRing[String(options.showUptimeRing) as keyof typeof heroVariantByRing];
const heroRingClass = heroVariantByRing[String(showRing) as keyof typeof heroVariantByRing];
return (
const summaryContent = (
<div className={classes.root}>
{showHero && (
<div className={`${classes.hero} ${heroLayoutClass} ${heroRingClass}`}>
@@ -144,7 +156,7 @@ function UptimeKumaContent({ integrationIds, options, width }: UptimeKumaContent
<span className={classes.heroLabel}>{t("averageUptime")}</span>
<span className={classes.heroValue}>{formatNumber(uptimeValue, 1)}%</span>
</div>
{options.showUptimeRing && (
{showRing && (
<RingProgress
className={classes.ring}
size={ringSize}
@@ -178,7 +190,7 @@ function UptimeKumaContent({ integrationIds, options, width }: UptimeKumaContent
<div key={statKey} className={classes.statTile}>
<Icon
className={classes.statIcon}
size={iconSize}
style={zoomCompensatedSize(iconSize)}
stroke={1.5}
color={`var(--mantine-color-${color}-6)`}
/>
@@ -191,8 +203,74 @@ function UptimeKumaContent({ integrationIds, options, width }: UptimeKumaContent
)}
</div>
);
if (displayMode === "compact") {
return (
<Box h="100%" pos="relative">
<Group pos="absolute" top={4} right={8} gap={0} style={{ zIndex: 2 }}>
<IntegrationErrorIndicator results={dashboardData} />
</Group>
{summaryContent}
</Box>
);
}
const monitorList = (
<Stack gap="xs">
{monitors
.toSorted((left, right) => statusOrder[left.status] - statusOrder[right.status])
.map((monitor) => (
<Group key={monitor.key} justify="space-between" wrap="nowrap" p="xs">
<Stack gap={0} style={{ minWidth: 0 }}>
<Text size="sm" fw={600} truncate>
{monitor.name}
</Text>
{(isAdvanced || successfulDashboardData.length > 1) && (
<Text size="xs" c="dimmed">
{monitor.integrationName}
</Text>
)}
</Stack>
<Badge color={monitor.status === "up" ? "green" : monitor.status === "down" ? "red" : "yellow"}>
{t(`status.${monitor.status}`)} ·{" "}
{monitor.uptimePercent24h === null ? "—" : `${formatNumber(monitor.uptimePercent24h, 1)}%`}
</Badge>
</Group>
))}
</Stack>
);
if (width < 760) {
return (
<Box h="100%" pos="relative">
<Group pos="absolute" top={4} right={8} gap={0} style={{ zIndex: 2 }}>
<IntegrationErrorIndicator results={dashboardData} />
</Group>
<ScrollArea h="100%">
<Stack gap="lg" p="md">
<Box h={Math.min(420, Math.max(180, Math.floor(height * 0.55)))}>{summaryContent}</Box>
{monitorList}
</Stack>
</ScrollArea>
</Box>
);
}
return (
<Box h="100%" pos="relative">
<Group pos="absolute" top={4} right={8} gap={0} style={{ zIndex: 2 }}>
<IntegrationErrorIndicator results={dashboardData} />
</Group>
<SimpleGrid cols={2} spacing="lg" h="100%" p="md" style={{ gridTemplateRows: "minmax(0, 1fr)" }}>
{summaryContent}
<ScrollArea h="100%">{monitorList}</ScrollArea>
</SimpleGrid>
</Box>
);
}
const statusOrder = { down: 0, paused: 1, up: 2 } as const;
function clampPercent(value: number): number {
return Math.min(100, Math.max(0, value));
}
+4 -1
View File
@@ -1,10 +1,13 @@
import { IconHeartbeat, IconServerOff } from "@tabler/icons-react";
import { getWidgetIntegrationConfig } from "@homarr/definitions";
import { createWidgetDefinition } from "../definition";
import { optionsBuilder } from "../options";
export const { definition, componentLoader } = createWidgetDefinition("uptimeKuma", {
icon: IconHeartbeat,
supportsAdvancedFocus: true,
createOptions() {
return optionsBuilder.from((factory) => ({
showAverageUptime: factory.switch({
@@ -33,7 +36,7 @@ export const { definition, componentLoader } = createWidgetDefinition("uptimeKum
}),
}));
},
supportedIntegrations: ["uptimeKuma"],
...getWidgetIntegrationConfig("uptimeKuma"),
errors: {
INTERNAL_SERVER_ERROR: {
icon: IconServerOff,