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,18 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { formatTotalTracearrBitrate, formatTracearrBitrate } from "./bitrate";
|
||||
|
||||
describe("Tracearr bitrate formatting", () => {
|
||||
test("sums raw Kbps before choosing the display unit", () => {
|
||||
expect(formatTotalTracearrBitrate([{ bitrate: 800 }, { bitrate: 1200 }])).toBe("2 Mb/s");
|
||||
});
|
||||
|
||||
test("formats Gb/s after aggregation", () => {
|
||||
expect(formatTotalTracearrBitrate([{ bitrate: 1_500_000 }, { bitrate: 500_000 }])).toBe("2 Gb/s");
|
||||
});
|
||||
|
||||
test("ignores missing and invalid bitrate values", () => {
|
||||
expect(formatTotalTracearrBitrate([{ bitrate: null }, { bitrate: Number.NaN }, { bitrate: 500 }])).toBe("500 Kb/s");
|
||||
expect(formatTracearrBitrate(0)).toBe("—");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { TracearrStream } from "@homarr/integrations/types";
|
||||
import { formatBitRate } from "@homarr/common";
|
||||
|
||||
export function formatTracearrBitrate(kbps: number): string {
|
||||
if (!Number.isFinite(kbps) || kbps <= 0) return "—";
|
||||
return formatBitRate(kbps * 1000);
|
||||
}
|
||||
|
||||
export function formatTotalTracearrBitrate(streams: readonly Pick<TracearrStream, "bitrate">[]): string {
|
||||
const totalKbps = streams.reduce((sum, { bitrate }) => {
|
||||
if (bitrate === null || !Number.isFinite(bitrate) || bitrate <= 0) return sum;
|
||||
return sum + bitrate;
|
||||
}, 0);
|
||||
return formatTracearrBitrate(totalKbps);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getAdvancedColumnWidth, getTracearrSectionVisibility } from "./component";
|
||||
import { attachTracearrSource } from "./source";
|
||||
|
||||
describe("Tracearr source ownership", () => {
|
||||
it("uses integration-scoped keys for overlapping upstream ids", () => {
|
||||
const first = attachTracearrSource([{ id: "same" }], {
|
||||
integrationId: "tracearr-a",
|
||||
integrationName: "Tracearr A",
|
||||
});
|
||||
const second = attachTracearrSource([{ id: "same" }], {
|
||||
integrationId: "tracearr-b",
|
||||
integrationName: "Tracearr B",
|
||||
});
|
||||
|
||||
expect([first[0]?.key, second[0]?.key]).toEqual(["tracearr-a:same", "tracearr-b:same"]);
|
||||
expect(second[0]?.integrationName).toBe("Tracearr B");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Tracearr advanced layout", () => {
|
||||
it("subtracts grid padding and the inter-column gap", () => {
|
||||
expect(getAdvancedColumnWidth(800, true)).toBe(376);
|
||||
expect(getAdvancedColumnWidth(801, true)).toBe(376.5);
|
||||
});
|
||||
|
||||
it("subtracts only grid padding in a single-column layout", () => {
|
||||
expect(getAdvancedColumnWidth(799, false)).toBe(767);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Tracearr advanced disclosure", () => {
|
||||
it("shows all sections even when compact presentation toggles are disabled", () => {
|
||||
expect(
|
||||
getTracearrSectionVisibility(
|
||||
{ showStats: false, showStreams: false, showViolations: false, showRecentActivity: false },
|
||||
true,
|
||||
),
|
||||
).toEqual({ stats: true, streams: true, violations: true, recentActivity: true });
|
||||
});
|
||||
});
|
||||
@@ -1,40 +1,70 @@
|
||||
"use client";
|
||||
|
||||
import { ScrollArea, Stack, Text } from "@mantine/core";
|
||||
import { Box, Group, ScrollArea, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import type { TracearrDashboardData } from "@homarr/integrations/types";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import { IntegrationErrorIndicator } from "../common/integration-error-indicator";
|
||||
import { getUsableWidgetQueryData } from "../common/query-state";
|
||||
import { NoIntegrationDataError } from "../errors/no-data-integration";
|
||||
import { formatTotalTracearrBitrate } from "./bitrate";
|
||||
import { RecentActivityList } from "./recent-activity-section";
|
||||
import { attachTracearrSource } from "./source";
|
||||
import { StatsBar } from "./stats-section";
|
||||
import { StreamsList } from "./streams-section";
|
||||
import { ViolationsList } from "./violations-section";
|
||||
|
||||
export default function TracearrWidget({ options, integrationIds, width }: WidgetComponentProps<"tracearr">) {
|
||||
const ADVANCED_GRID_BREAKPOINT = 800;
|
||||
const ADVANCED_GRID_GAP_PX = 16;
|
||||
const ADVANCED_GRID_PADDING_PX = 16;
|
||||
|
||||
type TracearrSectionOptions = Pick<
|
||||
WidgetComponentProps<"tracearr">["options"],
|
||||
"showStats" | "showStreams" | "showViolations" | "showRecentActivity"
|
||||
>;
|
||||
|
||||
export const getTracearrSectionVisibility = (options: TracearrSectionOptions, isAdvanced: boolean) => ({
|
||||
stats: isAdvanced || options.showStats,
|
||||
streams: isAdvanced || options.showStreams,
|
||||
violations: isAdvanced || options.showViolations,
|
||||
recentActivity: isAdvanced || options.showRecentActivity,
|
||||
});
|
||||
|
||||
export default function TracearrWidget({
|
||||
options,
|
||||
integrationIds,
|
||||
width,
|
||||
displayMode = "compact",
|
||||
}: WidgetComponentProps<"tracearr">) {
|
||||
if (integrationIds.length === 0) {
|
||||
throw new NoIntegrationDataError();
|
||||
}
|
||||
|
||||
return <TracearrContent integrationIds={integrationIds} options={options} width={width} />;
|
||||
return <TracearrContent integrationIds={integrationIds} options={options} width={width} displayMode={displayMode} />;
|
||||
}
|
||||
|
||||
interface TracearrContentProps {
|
||||
integrationIds: string[];
|
||||
options: WidgetComponentProps<"tracearr">["options"];
|
||||
width: number;
|
||||
displayMode: "compact" | "advanced";
|
||||
}
|
||||
|
||||
function TracearrContent({ integrationIds, options, width }: TracearrContentProps) {
|
||||
const t = useScopedI18n("widget.tracearr");
|
||||
const { data: dashboardData = [] } = clientApi.widget.tracearr.getDashboard.useQuery({ integrationIds });
|
||||
function TracearrContent({ integrationIds, options, width, displayMode }: TracearrContentProps) {
|
||||
const t = useI18n("widget.tracearr");
|
||||
const dashboardQuery = clientApi.widget.tracearr.getDashboard.useQuery({ integrationIds });
|
||||
const dashboardData = getUsableWidgetQueryData(dashboardQuery) ?? [];
|
||||
const successfulDashboards = dashboardData.flatMap((item) =>
|
||||
item.dashboard === null ? [] : [{ ...item, dashboard: item.dashboard }],
|
||||
);
|
||||
|
||||
// Merge data from all integrations
|
||||
const combined = dashboardData.reduce<TracearrDashboardData>(
|
||||
(acc, item) => {
|
||||
const { stats, streams, violations, recentActivity } = item.dashboard;
|
||||
const combinedData = successfulDashboards.reduce<TracearrDashboardData>(
|
||||
(acc, { dashboard }) => {
|
||||
const { stats, streams, violations, recentActivity } = dashboard;
|
||||
const vData = violations ?? { data: [], meta: { total: 0, page: 1, pageSize: 5 } };
|
||||
const aData = recentActivity ?? { data: [], meta: { total: 0, page: 1, pageSize: 5 } };
|
||||
|
||||
@@ -53,7 +83,7 @@ function TracearrContent({ integrationIds, options, width }: TracearrContentProp
|
||||
transcodes: acc.streams.summary.transcodes + streams.summary.transcodes,
|
||||
directStreams: acc.streams.summary.directStreams + streams.summary.directStreams,
|
||||
directPlays: acc.streams.summary.directPlays + streams.summary.directPlays,
|
||||
totalBitrate: streams.summary.totalBitrate,
|
||||
totalBitrate: "—",
|
||||
byServer: [...acc.streams.summary.byServer, ...streams.summary.byServer],
|
||||
},
|
||||
},
|
||||
@@ -85,23 +115,103 @@ function TracearrContent({ integrationIds, options, width }: TracearrContentProp
|
||||
recentActivity: null,
|
||||
},
|
||||
);
|
||||
const combined: TracearrDashboardData = {
|
||||
...combinedData,
|
||||
streams: {
|
||||
...combinedData.streams,
|
||||
summary: {
|
||||
...combinedData.streams.summary,
|
||||
totalBitrate: formatTotalTracearrBitrate(combinedData.streams.data),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const noSectionsEnabled =
|
||||
!options.showStats && !options.showStreams && !options.showRecentActivity && !options.showViolations;
|
||||
const isAdvanced = displayMode === "advanced";
|
||||
const sectionVisibility = getTracearrSectionVisibility(options, isAdvanced);
|
||||
const noSectionsEnabled = Object.values(sectionVisibility).every((isVisible) => !isVisible);
|
||||
|
||||
const sourcedStreams = successfulDashboards.flatMap(({ integrationId, integrationName, dashboard }) =>
|
||||
attachTracearrSource(dashboard.streams.data, { integrationId, integrationName }),
|
||||
);
|
||||
const sourcedViolations = successfulDashboards.flatMap(({ integrationId, integrationName, dashboard }) =>
|
||||
attachTracearrSource(dashboard.violations?.data ?? [], { integrationId, integrationName }),
|
||||
);
|
||||
const sourcedRecentActivity = successfulDashboards.flatMap(({ integrationId, integrationName, dashboard }) =>
|
||||
attachTracearrSource(dashboard.recentActivity?.data ?? [], { integrationId, integrationName }),
|
||||
);
|
||||
const showSource = isAdvanced || dashboardData.length > 1;
|
||||
|
||||
if (isAdvanced) {
|
||||
const isTwoColumn = width >= ADVANCED_GRID_BREAKPOINT;
|
||||
const columnWidth = getAdvancedColumnWidth(width, isTwoColumn);
|
||||
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%">
|
||||
<SimpleGrid
|
||||
cols={isTwoColumn ? 2 : 1}
|
||||
spacing={`${ADVANCED_GRID_GAP_PX}px`}
|
||||
p={`${ADVANCED_GRID_PADDING_PX}px`}
|
||||
>
|
||||
<Stack gap="sm">
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{successfulDashboards.map(({ integrationName }) => integrationName).join(" · ")}
|
||||
</Text>
|
||||
{sectionVisibility.stats && (
|
||||
<StatsBar stats={combined.stats} summary={combined.streams.summary} width={columnWidth} transparent />
|
||||
)}
|
||||
{sectionVisibility.streams && (
|
||||
<StreamsList streams={sourcedStreams} width={columnWidth} showSource={showSource} transparent />
|
||||
)}
|
||||
</Stack>
|
||||
<Stack gap="sm">
|
||||
{sectionVisibility.violations && (
|
||||
<ViolationsList violations={sourcedViolations} showSource={showSource} transparent />
|
||||
)}
|
||||
{sectionVisibility.recentActivity && (
|
||||
<RecentActivityList sessions={sourcedRecentActivity} showSource={showSource} transparent />
|
||||
)}
|
||||
</Stack>
|
||||
</SimpleGrid>
|
||||
</ScrollArea>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollArea h="100%">
|
||||
<Stack gap="xs" p="xs">
|
||||
{options.showStats && <StatsBar stats={combined.stats} summary={combined.streams.summary} width={width} />}
|
||||
{options.showStreams && <StreamsList streams={combined.streams.data} width={width} />}
|
||||
{options.showViolations && <ViolationsList violations={combined.violations?.data ?? []} />}
|
||||
{options.showRecentActivity && <RecentActivityList sessions={combined.recentActivity?.data ?? []} />}
|
||||
{noSectionsEnabled && (
|
||||
<Text c="dimmed" ta="center">
|
||||
{t("noSectionsEnabled")}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
<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="xs" p="xs">
|
||||
{showSource && (
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{successfulDashboards.map(({ integrationName }) => integrationName).join(" · ")}
|
||||
</Text>
|
||||
)}
|
||||
{sectionVisibility.stats && (
|
||||
<StatsBar stats={combined.stats} summary={combined.streams.summary} width={width} />
|
||||
)}
|
||||
{sectionVisibility.streams && <StreamsList streams={sourcedStreams} width={width} showSource={showSource} />}
|
||||
{sectionVisibility.violations && <ViolationsList violations={sourcedViolations} showSource={showSource} />}
|
||||
{sectionVisibility.recentActivity && (
|
||||
<RecentActivityList sessions={sourcedRecentActivity} showSource={showSource} />
|
||||
)}
|
||||
{noSectionsEnabled && (
|
||||
<Text c="dimmed" ta="center">
|
||||
{t("noSectionsEnabled")}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export const getAdvancedColumnWidth = (width: number, isTwoColumn: boolean) => {
|
||||
const contentWidth = Math.max(0, width - ADVANCED_GRID_PADDING_PX * 2);
|
||||
return isTwoColumn ? Math.max(0, (contentWidth - ADVANCED_GRID_GAP_PX) / 2) : contentWidth;
|
||||
};
|
||||
@@ -1,11 +1,14 @@
|
||||
import { IconActivityHeartbeat, IconServerOff } from "@tabler/icons-react";
|
||||
|
||||
import { getWidgetIntegrationConfig } from "@homarr/definitions";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("tracearr", {
|
||||
icon: IconActivityHeartbeat,
|
||||
refetchInterval: 5,
|
||||
supportsAdvancedFocus: true,
|
||||
refetchInterval: 10,
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
showStreams: factory.switch({
|
||||
@@ -23,7 +26,7 @@ export const { definition, componentLoader } = createWidgetDefinition("tracearr"
|
||||
}),
|
||||
}));
|
||||
},
|
||||
supportedIntegrations: ["tracearr"],
|
||||
...getWidgetIntegrationConfig("tracearr"),
|
||||
errors: {
|
||||
INTERNAL_SERVER_ERROR: {
|
||||
icon: IconServerOff,
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
import { Avatar, Badge, Group, Paper, Stack, Text } from "@mantine/core";
|
||||
|
||||
import type { TracearrHistorySession } from "@homarr/integrations/types";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useCurrentIntlLocale, useI18n } from "@homarr/translation/client";
|
||||
|
||||
export function RecentActivityList({ sessions }: { sessions: TracearrHistorySession[] }) {
|
||||
const t = useScopedI18n("widget.tracearr");
|
||||
import type { SourcedTracearrItem } from "./source";
|
||||
|
||||
type SourcedTracearrHistorySession = SourcedTracearrItem<TracearrHistorySession>;
|
||||
|
||||
export function RecentActivityList({
|
||||
sessions,
|
||||
showSource,
|
||||
transparent = false,
|
||||
}: {
|
||||
sessions: SourcedTracearrHistorySession[];
|
||||
showSource: boolean;
|
||||
transparent?: boolean;
|
||||
}) {
|
||||
const t = useI18n("widget.tracearr");
|
||||
const locale = useCurrentIntlLocale();
|
||||
|
||||
return (
|
||||
<Stack gap={4}>
|
||||
<Text size="xs" fw={600} c="dimmed" tt="uppercase">
|
||||
<Text size="xs" fw={600} c="dimmed" tt={transparent ? undefined : "uppercase"}>
|
||||
{t("recentActivity.title")}
|
||||
</Text>
|
||||
{sessions.length === 0 ? (
|
||||
@@ -24,7 +37,7 @@ export function RecentActivityList({ sessions }: { sessions: TracearrHistorySess
|
||||
: session.mediaTitle;
|
||||
|
||||
return (
|
||||
<Paper key={session.id} p="sm" radius="lg">
|
||||
<Paper key={session.key} p="sm" radius="lg" bg={transparent ? "transparent" : undefined}>
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Group gap="xs" wrap="nowrap" style={{ overflow: "hidden" }}>
|
||||
<Avatar src={session.user.avatarUrl} alt={session.user.username} radius="xl" size="sm" />
|
||||
@@ -34,6 +47,7 @@ export function RecentActivityList({ sessions }: { sessions: TracearrHistorySess
|
||||
</Text>
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{session.user.username} • {session.serverName}
|
||||
{showSource ? ` • ${session.integrationName}` : ""}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Group>
|
||||
@@ -42,7 +56,7 @@ export function RecentActivityList({ sessions }: { sessions: TracearrHistorySess
|
||||
{session.watched ? t("recentActivity.watched") : t("recentActivity.partial")}
|
||||
</Badge>
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{new Date(session.startedAt).toLocaleDateString()}
|
||||
{new Date(session.startedAt).toLocaleDateString(locale)}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Group>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
export interface TracearrSource {
|
||||
integrationId: string;
|
||||
integrationName: string;
|
||||
}
|
||||
|
||||
export type SourcedTracearrItem<T extends { id: string }> = T &
|
||||
TracearrSource & {
|
||||
key: string;
|
||||
};
|
||||
|
||||
export const attachTracearrSource = <T extends { id: string }>(
|
||||
items: readonly T[],
|
||||
source: TracearrSource,
|
||||
): SourcedTracearrItem<T>[] =>
|
||||
items.map((item) => ({
|
||||
...item,
|
||||
...source,
|
||||
key: `${source.integrationId}:${item.id}`,
|
||||
}));
|
||||
@@ -2,37 +2,65 @@ import { Group, Paper, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { IconDevices, IconNetwork, IconUsers, IconVideo } from "@tabler/icons-react";
|
||||
|
||||
import type { TracearrDashboardData } from "@homarr/integrations/types";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
export function StatsBar({
|
||||
stats,
|
||||
summary,
|
||||
width,
|
||||
transparent = false,
|
||||
}: {
|
||||
stats: TracearrDashboardData["stats"];
|
||||
summary: TracearrDashboardData["streams"]["summary"];
|
||||
width: number;
|
||||
transparent?: boolean;
|
||||
}) {
|
||||
const t = useScopedI18n("widget.tracearr");
|
||||
const t = useI18n("widget.tracearr");
|
||||
const cols = width > 400 ? 4 : width > 250 ? 2 : 1;
|
||||
|
||||
return (
|
||||
<SimpleGrid cols={cols} spacing="xs">
|
||||
<StatCard icon={<IconVideo size={16} />} label={t("stats.activeStreams")} value={stats.activeStreams} />
|
||||
<StatCard icon={<IconUsers size={16} />} label={t("stats.totalUsers")} value={stats.totalUsers} />
|
||||
<StatCard
|
||||
icon={<IconDevices size={16} />}
|
||||
icon={<IconVideo size="var(--mantine-font-size-md)" />}
|
||||
label={t("stats.activeStreams")}
|
||||
value={stats.activeStreams}
|
||||
transparent={transparent}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconUsers size="var(--mantine-font-size-md)" />}
|
||||
label={t("stats.totalUsers")}
|
||||
value={stats.totalUsers}
|
||||
transparent={transparent}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconDevices size="var(--mantine-font-size-md)" />}
|
||||
label={t("stats.transcodes")}
|
||||
value={`${summary.transcodes}/${summary.total}`}
|
||||
transparent={transparent}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconNetwork size="var(--mantine-font-size-md)" />}
|
||||
label={t("stats.bandwidth")}
|
||||
value={summary.totalBitrate}
|
||||
transparent={transparent}
|
||||
/>
|
||||
<StatCard icon={<IconNetwork size={16} />} label={t("stats.bandwidth")} value={summary.totalBitrate} />
|
||||
</SimpleGrid>
|
||||
);
|
||||
}
|
||||
|
||||
function StatCard({ icon, label, value }: { icon: React.ReactNode; label: string; value: string | number }) {
|
||||
function StatCard({
|
||||
icon,
|
||||
label,
|
||||
value,
|
||||
transparent,
|
||||
}: {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
value: string | number;
|
||||
transparent: boolean;
|
||||
}) {
|
||||
return (
|
||||
<Paper p="xs" radius="lg">
|
||||
<Paper p="xs" radius="lg" bg={transparent ? "transparent" : undefined}>
|
||||
<Group gap={4} wrap="nowrap">
|
||||
{icon}
|
||||
<Stack gap={0} style={{ overflow: "hidden" }}>
|
||||
|
||||
@@ -3,10 +3,24 @@ import { IconPlayerPause, IconPlayerPlay } from "@tabler/icons-react";
|
||||
|
||||
import { formatDuration } from "@homarr/common";
|
||||
import type { TracearrStream } from "@homarr/integrations/types";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
export function StreamsList({ streams, width }: { streams: TracearrStream[]; width: number }) {
|
||||
const t = useScopedI18n("widget.tracearr");
|
||||
import type { SourcedTracearrItem } from "./source";
|
||||
|
||||
type SourcedTracearrStream = SourcedTracearrItem<TracearrStream>;
|
||||
|
||||
export function StreamsList({
|
||||
streams,
|
||||
width,
|
||||
showSource,
|
||||
transparent = false,
|
||||
}: {
|
||||
streams: SourcedTracearrStream[];
|
||||
width: number;
|
||||
showSource: boolean;
|
||||
transparent?: boolean;
|
||||
}) {
|
||||
const t = useI18n("widget.tracearr");
|
||||
|
||||
if (streams.length === 0) {
|
||||
return (
|
||||
@@ -19,14 +33,30 @@ export function StreamsList({ streams, width }: { streams: TracearrStream[]; wid
|
||||
return (
|
||||
<Stack gap="xs">
|
||||
{streams.map((stream) => (
|
||||
<StreamCard key={stream.id} stream={stream} compact={width < 300} />
|
||||
<StreamCard
|
||||
key={stream.key}
|
||||
stream={stream}
|
||||
compact={width < 300}
|
||||
showSource={showSource}
|
||||
transparent={transparent}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
function StreamCard({ stream, compact }: { stream: TracearrStream; compact: boolean }) {
|
||||
const t = useScopedI18n("widget.tracearr");
|
||||
function StreamCard({
|
||||
stream,
|
||||
compact,
|
||||
showSource,
|
||||
transparent,
|
||||
}: {
|
||||
stream: SourcedTracearrStream;
|
||||
compact: boolean;
|
||||
showSource: boolean;
|
||||
transparent: boolean;
|
||||
}) {
|
||||
const t = useI18n("widget.tracearr");
|
||||
const progressPercent =
|
||||
stream.durationMs && stream.durationMs > 0 ? (stream.progressMs / stream.durationMs) * 100 : 0;
|
||||
|
||||
@@ -45,7 +75,12 @@ function StreamCard({ stream, compact }: { stream: TracearrStream; compact: bool
|
||||
: null;
|
||||
|
||||
return (
|
||||
<Paper p="xs" radius="lg" style={{ position: "relative", overflow: "hidden" }}>
|
||||
<Paper
|
||||
p="xs"
|
||||
radius="lg"
|
||||
bg={transparent ? "transparent" : undefined}
|
||||
style={{ position: "relative", overflow: "hidden" }}
|
||||
>
|
||||
{stream.posterUrl && (
|
||||
<Box
|
||||
style={{
|
||||
@@ -68,9 +103,9 @@ function StreamCard({ stream, compact }: { stream: TracearrStream; compact: bool
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Group gap="xs" wrap="nowrap" style={{ overflow: "hidden" }}>
|
||||
{stream.state === "playing" ? (
|
||||
<IconPlayerPlay size={14} color="var(--mantine-color-green-6)" />
|
||||
<IconPlayerPlay size="var(--mantine-font-size-sm)" color="var(--mantine-color-green-6)" />
|
||||
) : (
|
||||
<IconPlayerPause size={14} color="var(--mantine-color-yellow-6)" />
|
||||
<IconPlayerPause size="var(--mantine-font-size-sm)" color="var(--mantine-color-yellow-6)" />
|
||||
)}
|
||||
<Text size="sm" fw={600} lineClamp={1}>
|
||||
{stream.username}
|
||||
@@ -115,13 +150,13 @@ function StreamCard({ stream, compact }: { stream: TracearrStream; compact: bool
|
||||
</Group>
|
||||
)}
|
||||
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
{stream.device && (
|
||||
{(stream.device || showSource) && (
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{stream.player ?? stream.device}
|
||||
{[stream.player ?? stream.device, showSource ? stream.integrationName : null].filter(Boolean).join(" · ")}
|
||||
</Text>
|
||||
)}
|
||||
</Group>
|
||||
</Group>
|
||||
)}
|
||||
</Stack>
|
||||
</Paper>
|
||||
);
|
||||
|
||||
@@ -2,14 +2,27 @@ import { Avatar, Badge, Group, Paper, Stack, Text } from "@mantine/core";
|
||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
||||
|
||||
import type { TracearrViolation } from "@homarr/integrations/types";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useCurrentIntlLocale, useI18n } from "@homarr/translation/client";
|
||||
|
||||
export function ViolationsList({ violations }: { violations: TracearrViolation[] }) {
|
||||
const t = useScopedI18n("widget.tracearr");
|
||||
import type { SourcedTracearrItem } from "./source";
|
||||
|
||||
type SourcedTracearrViolation = SourcedTracearrItem<TracearrViolation>;
|
||||
|
||||
export function ViolationsList({
|
||||
violations,
|
||||
showSource,
|
||||
transparent = false,
|
||||
}: {
|
||||
violations: SourcedTracearrViolation[];
|
||||
showSource: boolean;
|
||||
transparent?: boolean;
|
||||
}) {
|
||||
const t = useI18n("widget.tracearr");
|
||||
const locale = useCurrentIntlLocale();
|
||||
|
||||
return (
|
||||
<Stack gap={4}>
|
||||
<Text size="xs" fw={600} c="dimmed" tt="uppercase">
|
||||
<Text size="xs" fw={600} c="dimmed" tt={transparent ? undefined : "uppercase"}>
|
||||
{t("violations.title")}
|
||||
</Text>
|
||||
{violations.length === 0 ? (
|
||||
@@ -19,11 +32,11 @@ export function ViolationsList({ violations }: { violations: TracearrViolation[]
|
||||
) : (
|
||||
<Stack gap="xs">
|
||||
{violations.map((violation) => (
|
||||
<Paper key={violation.id} p="xs" radius="lg">
|
||||
<Paper key={violation.key} p="xs" radius="lg" bg={transparent ? "transparent" : undefined}>
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Group gap="xs" wrap="nowrap" style={{ overflow: "hidden" }}>
|
||||
<IconAlertTriangle
|
||||
size={14}
|
||||
size="var(--mantine-font-size-sm)"
|
||||
color={
|
||||
violation.severity === "high"
|
||||
? "var(--mantine-color-red-6)"
|
||||
@@ -39,6 +52,7 @@ export function ViolationsList({ violations }: { violations: TracearrViolation[]
|
||||
</Text>
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{t("violations.rule")}: {violation.rule.name}
|
||||
{showSource ? ` · ${violation.integrationName}` : ""}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Group>
|
||||
@@ -53,7 +67,7 @@ export function ViolationsList({ violations }: { violations: TracearrViolation[]
|
||||
{violation.severity}
|
||||
</Badge>
|
||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||
{new Date(violation.createdAt).toLocaleDateString()}
|
||||
{new Date(violation.createdAt).toLocaleDateString(locale)}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Group>
|
||||
|
||||
Reference in new issue
Block a user