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
@@ -1,16 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { Avatar, Badge, Card, Group, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { Avatar, Badge, Card, Group, ScrollArea, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { formatByteRate } from "@homarr/common";
|
||||
import { getIconUrl } from "@homarr/definitions";
|
||||
import { useByteFormatter } from "@homarr/settings";
|
||||
import { useCurrentIntlLocale, useI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
|
||||
export default function ArchiveTeamWarriorWidget({
|
||||
integrationIds,
|
||||
options,
|
||||
width,
|
||||
height,
|
||||
displayMode,
|
||||
}: WidgetComponentProps<"archiveTeamWarrior">) {
|
||||
const integrationId = integrationIds[0];
|
||||
|
||||
@@ -18,23 +22,50 @@ export default function ArchiveTeamWarriorWidget({
|
||||
return null;
|
||||
}
|
||||
|
||||
return <ArchiveTeamWarriorWidgetContent integrationId={integrationId} options={options} />;
|
||||
return (
|
||||
<ArchiveTeamWarriorWidgetContent
|
||||
integrationId={integrationId}
|
||||
options={options}
|
||||
width={width}
|
||||
height={height}
|
||||
isAdvanced={displayMode === "advanced"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const ArchiveTeamWarriorWidgetContent = ({
|
||||
integrationId,
|
||||
options,
|
||||
width,
|
||||
height,
|
||||
isAdvanced,
|
||||
}: {
|
||||
integrationId: string;
|
||||
options: WidgetComponentProps<"archiveTeamWarrior">["options"];
|
||||
width: number;
|
||||
height: number;
|
||||
isAdvanced: boolean;
|
||||
}) => {
|
||||
const t = useI18n("widget.archiveTeamWarrior");
|
||||
const tWidgetCommon = useI18n("widget.common");
|
||||
const locale = useCurrentIntlLocale();
|
||||
const { formatBytes, formatByteRate } = useByteFormatter();
|
||||
const [data] = clientApi.widget.archiveTeamWarrior.getStatus.useSuspenseQuery({ integrationId });
|
||||
|
||||
const status = data.status;
|
||||
const projectName = status.project?.title ?? status.selectedProject ?? "No project selected";
|
||||
const projectName = status.project?.title ?? status.selectedProject ?? t("noProjectSelected");
|
||||
const statusKey = getStatusKey(status.status);
|
||||
const layout = getArchiveCompactLayout(width, height, isAdvanced);
|
||||
const countMetrics = [
|
||||
{ label: t("metric.running"), value: status.counts.running },
|
||||
...(layout.showSecondaryCounts ? [{ label: t("metric.completed"), value: status.counts.completed }] : []),
|
||||
{ label: t("metric.failed"), value: status.counts.failed },
|
||||
...(layout.showSecondaryCounts ? [{ label: t("metric.canceled"), value: status.counts.canceled }] : []),
|
||||
];
|
||||
const formatBandwidth = (value?: number) => formatByteRate(Math.round(value ?? 0));
|
||||
|
||||
return (
|
||||
<Stack p="xs" gap="xs" h="100%">
|
||||
<Stack p="xs" gap={layout.gap} h="100%" style={{ overflow: "hidden" }}>
|
||||
<Group justify="space-between" align="center" wrap="nowrap">
|
||||
<Group gap="xs" wrap="nowrap" miw={0}>
|
||||
<Avatar size="sm" radius="md" src={getIconUrl("archiveTeamWarrior")} />
|
||||
@@ -43,45 +74,159 @@ const ArchiveTeamWarriorWidgetContent = ({
|
||||
</Text>
|
||||
</Group>
|
||||
|
||||
<Badge size="sm" color={status.status === "Running" ? "green" : "gray"}>
|
||||
{status.status}
|
||||
</Badge>
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Badge size="sm" color={getStatusColor(statusKey)}>
|
||||
{t(`status.${statusKey}`)}
|
||||
</Badge>
|
||||
</Group>
|
||||
</Group>
|
||||
|
||||
{options.showBroadcastMessage && status.broadcastMessage && (
|
||||
<Card withBorder p="xs">
|
||||
<Text size="xs" lineClamp={3}>
|
||||
{(isAdvanced || options.showBroadcastMessage) && status.broadcastMessage && layout.showBroadcast && (
|
||||
<Card withBorder p="xs" bg="transparent" style={{ borderColor: neutralSurfaceBorder }}>
|
||||
<Text size="xs" lineClamp={isAdvanced ? undefined : 3}>
|
||||
{status.broadcastMessage}
|
||||
</Text>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<SimpleGrid cols={2} spacing="xs">
|
||||
<Metric label="Running" value={status.counts.running} />
|
||||
<Metric label="Done" value={status.counts.completed} />
|
||||
<Metric label="Failed" value={status.counts.failed} />
|
||||
<Metric label="Canceled" value={status.counts.canceled} />
|
||||
<SimpleGrid cols={layout.metricColumns} spacing={layout.gap}>
|
||||
{countMetrics.map((metric) => (
|
||||
<Metric key={metric.label} {...metric} dense={layout.dense} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
|
||||
{status.bandwidth && (
|
||||
<SimpleGrid cols={2} spacing="xs">
|
||||
<Metric label="Download" value={formatBandwidth(status.bandwidth.receiving)} />
|
||||
<Metric label="Upload" value={formatBandwidth(status.bandwidth.sending)} />
|
||||
{status.bandwidth && layout.showBandwidth && (
|
||||
<SimpleGrid cols={2} spacing={layout.gap}>
|
||||
<Metric label={t("metric.download")} value={formatBandwidth(status.bandwidth.receiving)} dense />
|
||||
<Metric label={t("metric.upload")} value={formatBandwidth(status.bandwidth.sending)} dense />
|
||||
</SimpleGrid>
|
||||
)}
|
||||
{isAdvanced && (
|
||||
<>
|
||||
<Group justify="space-between" gap="xs">
|
||||
<Text size="xs" c="dimmed">
|
||||
{t("runnerStatus", { status: t(`status.${getStatusKey(status.runnerStatus ?? status.status)}`) })}
|
||||
</Text>
|
||||
<Text size="xs" c="dimmed">
|
||||
{tWidgetCommon("updatedAt", { date: new Date(status.updatedAt).toLocaleString(locale) })}
|
||||
</Text>
|
||||
</Group>
|
||||
<Group gap="xs" wrap="wrap">
|
||||
{status.project?.id && (
|
||||
<Badge size="xs" variant="light">
|
||||
{t("projectId", { id: status.project.id })}
|
||||
</Badge>
|
||||
)}
|
||||
{status.bandwidth?.received !== undefined && (
|
||||
<Text size="xs" c="dimmed">
|
||||
{t("sessionReceived", { value: formatBytes(Math.round(status.bandwidth.received)) })}
|
||||
</Text>
|
||||
)}
|
||||
{status.bandwidth?.sent !== undefined && (
|
||||
<Text size="xs" c="dimmed">
|
||||
{t("sessionSent", { value: formatBytes(Math.round(status.bandwidth.sent)) })}
|
||||
</Text>
|
||||
)}
|
||||
{status.bandwidth?.session_id && (
|
||||
<Text size="xs" c="dimmed">
|
||||
{t("sessionId", { id: status.bandwidth.session_id })}
|
||||
</Text>
|
||||
)}
|
||||
</Group>
|
||||
<ScrollArea style={{ flex: 1 }}>
|
||||
<Stack gap={4}>
|
||||
{status.items.length === 0 && (
|
||||
<Text size="sm" c="dimmed" ta="center" py="md">
|
||||
{t("emptyItems")}
|
||||
</Text>
|
||||
)}
|
||||
{status.items.map((item) => {
|
||||
const itemStatusKey = getStatusKey(item.status);
|
||||
return (
|
||||
<Card key={item.id} withBorder p="xs" bg="transparent" style={{ borderColor: neutralSurfaceBorder }}>
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Stack gap={0} miw={0}>
|
||||
<Text size="sm" fw={600} lineClamp={1}>
|
||||
{item.name}
|
||||
</Text>
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{item.project ?? projectName}
|
||||
</Text>
|
||||
{item.startTime !== undefined && (
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{t("startedAt", { date: new Date(item.startTime * 1000).toLocaleString(locale) })}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
<Badge size="xs" color={getStatusColor(itemStatusKey)}>
|
||||
{t(`status.${itemStatusKey}`)}
|
||||
</Badge>
|
||||
</Group>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
const Metric = ({ label, value }: { label: string; value: number | string }) => (
|
||||
const Metric = ({ label, value, dense = false }: { label: string; value: number | string; dense?: boolean }) => (
|
||||
<Stack gap={0} miw={0}>
|
||||
<Text size="md" fw={700} lineClamp={1}>
|
||||
<Text size={dense ? "sm" : "md"} fw={700} lineClamp={1} title={String(value)}>
|
||||
{value}
|
||||
</Text>
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
<Text size="xs" c="dimmed" lineClamp={1} title={label}>
|
||||
{label}
|
||||
</Text>
|
||||
</Stack>
|
||||
);
|
||||
|
||||
const formatBandwidth = (value?: number) => formatByteRate(Math.round(value ?? 0));
|
||||
export const getArchiveCompactLayout = (width: number, height: number, isAdvanced = false) => {
|
||||
const dense = !isAdvanced && (width < 240 || height < 160);
|
||||
const showSecondaryCounts = isAdvanced || (width >= 200 && height >= 120);
|
||||
const metricCount = showSecondaryCounts ? 4 : 2;
|
||||
|
||||
return {
|
||||
dense,
|
||||
gap: dense ? 4 : "xs",
|
||||
metricColumns: height < 160 ? metricCount : Math.min(metricCount, width >= 260 ? 4 : 2),
|
||||
showBandwidth: isAdvanced || height >= 190,
|
||||
showBroadcast: isAdvanced || height >= 240,
|
||||
showSecondaryCounts,
|
||||
} as const;
|
||||
};
|
||||
|
||||
const neutralSurfaceBorder = "rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45))";
|
||||
|
||||
type WarriorStatusKey = "running" | "completed" | "failed" | "canceled" | "stopped" | "idle" | "unknown";
|
||||
|
||||
const getStatusKey = (status?: string | null): WarriorStatusKey => {
|
||||
switch (status?.trim().toLowerCase()) {
|
||||
case "running":
|
||||
return "running";
|
||||
case "done":
|
||||
case "completed":
|
||||
return "completed";
|
||||
case "failed":
|
||||
return "failed";
|
||||
case "canceled":
|
||||
case "cancelled":
|
||||
return "canceled";
|
||||
case "stopped":
|
||||
return "stopped";
|
||||
case "idle":
|
||||
return "idle";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
};
|
||||
|
||||
const getStatusColor = (status: WarriorStatusKey): string => {
|
||||
if (status === "running") return "green";
|
||||
if (status === "failed") return "red";
|
||||
if (status === "canceled" || status === "stopped") return "yellow";
|
||||
return "gray";
|
||||
};
|
||||
@@ -1,10 +1,14 @@
|
||||
import { IconArchive } from "@tabler/icons-react";
|
||||
|
||||
import { getWidgetIntegrationConfig } from "@homarr/definitions";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("archiveTeamWarrior", {
|
||||
icon: IconArchive,
|
||||
supportsAdvancedFocus: true,
|
||||
...getWidgetIntegrationConfig("archiveTeamWarrior"),
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
showBroadcastMessage: factory.switch({
|
||||
@@ -12,5 +16,4 @@ export const { definition, componentLoader } = createWidgetDefinition("archiveTe
|
||||
}),
|
||||
}));
|
||||
},
|
||||
supportedIntegrations: ["archiveTeamWarrior"],
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getArchiveCompactLayout } from "./component";
|
||||
|
||||
describe("archive team warrior compact layout", () => {
|
||||
test("keeps only primary counters in a minimum-size widget", () => {
|
||||
expect(getArchiveCompactLayout(180, 100)).toMatchObject({
|
||||
metricColumns: 2,
|
||||
showBandwidth: false,
|
||||
showBroadcast: false,
|
||||
showSecondaryCounts: false,
|
||||
});
|
||||
});
|
||||
|
||||
test("adds secondary information as height becomes available", () => {
|
||||
expect(getArchiveCompactLayout(320, 260)).toMatchObject({
|
||||
metricColumns: 4,
|
||||
showBandwidth: true,
|
||||
showBroadcast: true,
|
||||
showSecondaryCounts: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("keeps all display sections available in advanced mode", () => {
|
||||
expect(getArchiveCompactLayout(180, 100, true)).toMatchObject({
|
||||
showBandwidth: true,
|
||||
showBroadcast: true,
|
||||
showSecondaryCounts: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user