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
@@ -29,12 +29,24 @@
|
||||
gap: clamp(2px, 1.5cqi, 5px);
|
||||
padding: clamp(4px, 2.5cqi, 10px);
|
||||
border-radius: var(--mantine-radius-md);
|
||||
background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-6));
|
||||
background-color: transparent;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.grid[data-short] .statTile {
|
||||
flex-direction: row;
|
||||
gap: 3px;
|
||||
padding: 3px 4px;
|
||||
}
|
||||
|
||||
.grid[data-short] .statLabel {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.statTileWarning {
|
||||
background-color: light-dark(var(--mantine-color-orange-0), var(--mantine-color-dark-5));
|
||||
background-color: rgb(
|
||||
from light-dark(var(--mantine-color-orange-0), var(--mantine-color-dark-5)) r g b / var(--opacity, 1)
|
||||
);
|
||||
}
|
||||
|
||||
.statIcon {
|
||||
@@ -59,6 +71,8 @@
|
||||
color: var(--mantine-primary-color-filled);
|
||||
line-height: 1.1;
|
||||
text-align: center;
|
||||
max-width: 100%;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.statValueWarning {
|
||||
|
||||
@@ -2,30 +2,49 @@
|
||||
|
||||
import type { CSSProperties } from "react";
|
||||
import { Text } from "@mantine/core";
|
||||
import { IconAlertTriangle, IconDeviceTv, IconMovie, IconPlugConnected } from "@tabler/icons-react";
|
||||
import { IconAlertTriangle, IconBell, IconDeviceTv, IconMovie, IconPlugConnected } from "@tabler/icons-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { getIntegrationName } from "@homarr/definitions";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { zoomCompensatedSize } from "@homarr/ui";
|
||||
|
||||
import { WidgetEmptyState } from "../common/empty-state";
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import classes from "./component.module.css";
|
||||
|
||||
const statVisibilityByOption = {
|
||||
showMissingEpisodes: "episodes",
|
||||
showMissingMovies: "movies",
|
||||
showProviderIssues: "providers",
|
||||
showHealthIssues: "status",
|
||||
} as const;
|
||||
const compactStatOptions = [
|
||||
{ option: "showMissingEpisodes", stat: "episodes" },
|
||||
{ option: "showMissingMovies", stat: "movies" },
|
||||
{ option: "showProviderIssues", stat: "providers" },
|
||||
{ option: "showHealthIssues", stat: "status" },
|
||||
] as const;
|
||||
|
||||
const allStatKeys = [
|
||||
"episodes",
|
||||
"movies",
|
||||
"providers",
|
||||
"status",
|
||||
"sonarrSignalr",
|
||||
"radarrSignalr",
|
||||
"announcements",
|
||||
] as const;
|
||||
|
||||
type BazarrStatKey = (typeof allStatKeys)[number];
|
||||
type BazarrVisibilityOptions = Record<(typeof compactStatOptions)[number]["option"], boolean>;
|
||||
|
||||
const statIcons = {
|
||||
episodes: IconDeviceTv,
|
||||
movies: IconMovie,
|
||||
providers: IconPlugConnected,
|
||||
status: IconAlertTriangle,
|
||||
sonarrSignalr: IconPlugConnected,
|
||||
radarrSignalr: IconPlugConnected,
|
||||
announcements: IconBell,
|
||||
} as const;
|
||||
|
||||
const gridColsByWidth = [
|
||||
{ minWidth: 640, cols: 4 },
|
||||
{ minWidth: 380, cols: 2 },
|
||||
{ minWidth: 0, cols: 1 },
|
||||
] as const;
|
||||
@@ -36,13 +55,20 @@ const iconSizeByWidth = [
|
||||
{ minWidth: 0, size: 16 },
|
||||
] as const;
|
||||
|
||||
export default function BazarrWidget({ integrationIds, options, width }: WidgetComponentProps<"bazarr">) {
|
||||
const t = useScopedI18n("widget.bazarr");
|
||||
const { data: badges } = clientApi.widget.bazarr.getBadges.useQuery(
|
||||
export default function BazarrWidget({
|
||||
integrationIds,
|
||||
options,
|
||||
width,
|
||||
height,
|
||||
displayMode,
|
||||
}: WidgetComponentProps<"bazarr">) {
|
||||
const t = useI18n("widget.bazarr");
|
||||
const { data: badges, error } = clientApi.widget.bazarr.getBadges.useQuery(
|
||||
{ integrationId: integrationIds[0] ?? "" },
|
||||
{ enabled: Boolean(integrationIds[0]) },
|
||||
);
|
||||
|
||||
if (error && !badges) throw error;
|
||||
if (!badges) return <WidgetEmptyState />;
|
||||
|
||||
const statValues = {
|
||||
@@ -50,14 +76,15 @@ export default function BazarrWidget({ integrationIds, options, width }: WidgetC
|
||||
movies: badges.movies,
|
||||
providers: badges.providers,
|
||||
status: badges.status,
|
||||
} as const;
|
||||
sonarrSignalr: badges.sonarr_signalr,
|
||||
radarrSignalr: badges.radarr_signalr,
|
||||
announcements: badges.announcements,
|
||||
} satisfies Record<BazarrStatKey, number | string>;
|
||||
|
||||
const visibleStatKeys = Object.entries(statVisibilityByOption)
|
||||
.filter(([optionKey]) => options[optionKey as keyof typeof options])
|
||||
.map(([, statKey]) => statKey);
|
||||
const visibleStatKeys = getVisibleBazarrStatKeys(options, displayMode);
|
||||
|
||||
const gridCols = getGridCols(width);
|
||||
const iconSize = getIconSize(width);
|
||||
const gridCols = getGridCols(width, height, visibleStatKeys.length);
|
||||
const iconSize = getIconSize(Math.min(width, height));
|
||||
|
||||
if (visibleStatKeys.length === 0) {
|
||||
return (
|
||||
@@ -73,17 +100,36 @@ export default function BazarrWidget({ integrationIds, options, width }: WidgetC
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<div className={classes.grid} style={{ "--stat-cols": gridCols } as CSSProperties}>
|
||||
<div
|
||||
className={classes.grid}
|
||||
data-short={height < 120 || undefined}
|
||||
style={{ "--stat-cols": gridCols } as CSSProperties}
|
||||
>
|
||||
{visibleStatKeys.map((statKey) => {
|
||||
const Icon = statIcons[statKey];
|
||||
const value = statValues[statKey];
|
||||
const isWarning = (statKey === "providers" || statKey === "status") && value > 0;
|
||||
let label: string;
|
||||
if (statKey === "sonarrSignalr") {
|
||||
label = `${getIntegrationName("sonarr")} SignalR`;
|
||||
} else if (statKey === "radarrSignalr") {
|
||||
label = `${getIntegrationName("radarr")} SignalR`;
|
||||
} else {
|
||||
label = t(statKey);
|
||||
}
|
||||
const isWarning =
|
||||
typeof value === "number" &&
|
||||
(statKey === "providers" || statKey === "status" || statKey === "announcements") &&
|
||||
value > 0;
|
||||
|
||||
return (
|
||||
<div key={statKey} className={`${classes.statTile} ${isWarning ? classes.statTileWarning : ""}`}>
|
||||
<Icon className={classes.statIcon} size={iconSize} stroke={1.5} />
|
||||
<span className={`${classes.statValue} ${isWarning ? classes.statValueWarning : ""}`}>{value}</span>
|
||||
<span className={classes.statLabel}>{t(statKey)}</span>
|
||||
<Icon className={classes.statIcon} style={zoomCompensatedSize(iconSize)} stroke={1.5} />
|
||||
<span className={`${classes.statValue} ${isWarning ? classes.statValueWarning : ""}`}>
|
||||
{typeof value === "string" && value.trim() === "" ? "—" : value}
|
||||
</span>
|
||||
<span className={classes.statLabel} title={label}>
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -92,12 +138,25 @@ export default function BazarrWidget({ integrationIds, options, width }: WidgetC
|
||||
);
|
||||
}
|
||||
|
||||
function getGridCols(width: number): number {
|
||||
const match = gridColsByWidth.find(({ minWidth }) => width >= minWidth);
|
||||
return match?.cols ?? 1;
|
||||
export const getVisibleBazarrStatKeys = (
|
||||
options: BazarrVisibilityOptions,
|
||||
displayMode?: "compact" | "advanced",
|
||||
): BazarrStatKey[] => {
|
||||
if (displayMode === "advanced") return [...allStatKeys];
|
||||
return compactStatOptions.filter(({ option }) => options[option]).map(({ stat }) => stat);
|
||||
};
|
||||
|
||||
export function getGridCols(width: number, height: number, itemCount: number): number {
|
||||
if (itemCount <= 1) return 1;
|
||||
|
||||
const preferredColumns = gridColsByWidth.find(({ minWidth }) => width >= minWidth)?.cols ?? 1;
|
||||
const maxColumnsByWidth = Math.max(1, Math.floor(width / 100));
|
||||
const maxRowsByHeight = Math.max(1, Math.floor(height / 72));
|
||||
const columnsNeededToFit = Math.ceil(itemCount / maxRowsByHeight);
|
||||
return Math.min(itemCount, maxColumnsByWidth, Math.max(preferredColumns, columnsNeededToFit));
|
||||
}
|
||||
|
||||
function getIconSize(width: number): number {
|
||||
export function getIconSize(width: number): number {
|
||||
const match = iconSizeByWidth.find(({ minWidth }) => width >= minWidth);
|
||||
return match?.size ?? 16;
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { IconBadgeCc, IconServerOff } from "@tabler/icons-react";
|
||||
|
||||
import { getWidgetIntegrationConfig } from "@homarr/definitions";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("bazarr", {
|
||||
supportsAdvancedFocus: true,
|
||||
icon: IconBadgeCc,
|
||||
supportedIntegrations: ["bazarr"],
|
||||
integrationsRequired: true,
|
||||
...getWidgetIntegrationConfig("bazarr"),
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
showMissingEpisodes: factory.switch({
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getGridCols, getIconSize, getVisibleBazarrStatKeys } from "./component";
|
||||
|
||||
describe("Bazarr responsive layout", () => {
|
||||
test("uses two columns for a short widget so all stats remain visible", () => {
|
||||
expect(getGridCols(220, 100, 4)).toBe(2);
|
||||
});
|
||||
|
||||
test("uses four columns in a wide advanced surface", () => {
|
||||
expect(getGridCols(800, 400, 4)).toBe(4);
|
||||
});
|
||||
|
||||
test("sizes icons from the constrained dimension", () => {
|
||||
expect(getIconSize(180)).toBe(16);
|
||||
expect(getIconSize(340)).toBe(22);
|
||||
});
|
||||
|
||||
test("advanced mode includes hidden summaries and all fetched status fields", () => {
|
||||
expect(
|
||||
getVisibleBazarrStatKeys(
|
||||
{
|
||||
showMissingEpisodes: false,
|
||||
showMissingMovies: false,
|
||||
showProviderIssues: false,
|
||||
showHealthIssues: false,
|
||||
},
|
||||
"advanced",
|
||||
),
|
||||
).toEqual(["episodes", "movies", "providers", "status", "sonarrSignalr", "radarrSignalr", "announcements"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user