frigate/web/src/components/overlay/detail/SaveAllPreviewPopover.tsx
Josh Hawkins bc65713ae4
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
Clone camera settings (#23339)
* add clone dialog

* i18n

* tweaks

* add to camera management pane

* add e2e test

* optional disable portal prop

* radio and checkbox tweaks

* tweak i18n

* add select all/select none

* fixes

* reset form only on open transition

* unselect all targets for existing camera

* fix test

* reorder sections for save and collapse to single put for new camera

* change source and allow cloning to multiple cameras

* tweak language

* fix overflowing text in save all popover

* tweaks

* fix per label object masks

* use grid for source and target

* language tweak
2026-05-28 17:44:06 -06:00

159 lines
5.2 KiB
TypeScript

import { useCallback, useState } from "react";
import { useTranslation } from "react-i18next";
import { LuInfo, LuX } from "react-icons/lu";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
export type SaveAllPreviewItem = {
scope: "global" | "camera";
cameraName?: string;
profileName?: string;
fieldPath: string;
value: unknown;
};
type SaveAllPreviewPopoverProps = {
items: SaveAllPreviewItem[];
className?: string;
align?: "start" | "center" | "end";
side?: "top" | "bottom" | "left" | "right";
disablePortal?: boolean;
};
export default function SaveAllPreviewPopover({
items,
className,
align = "end",
side = "bottom",
disablePortal = false,
}: SaveAllPreviewPopoverProps) {
const { t } = useTranslation(["views/settings", "common"]);
const [open, setOpen] = useState(false);
const resetLabel = t("saveAllPreview.value.reset", {
ns: "views/settings",
});
const formatValue = useCallback(
(value: unknown) => {
if (value === "") return resetLabel;
if (typeof value === "string") return value;
try {
return JSON.stringify(value, null, 2);
} catch {
return String(value);
}
},
[resetLabel],
);
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
type="button"
variant="ghost"
size="icon"
className={cn("size-8", className)}
aria-label={t("saveAllPreview.triggerLabel", {
ns: "views/settings",
})}
>
<LuInfo className="size-4" />
</Button>
</PopoverTrigger>
<PopoverContent
align={align}
side={side}
disablePortal={disablePortal}
className="w-[90vw] max-w-sm border bg-background p-4 shadow-lg"
onOpenAutoFocus={(event) => event.preventDefault()}
>
<div className="flex items-center justify-between gap-2">
<div className="text-sm font-semibold text-primary-variant">
{t("saveAllPreview.title", { ns: "views/settings" })}
</div>
<Button
type="button"
variant="ghost"
size="icon"
className="size-7"
onClick={() => setOpen(false)}
aria-label={t("button.close", { ns: "common" })}
>
<LuX className="size-4" />
</Button>
</div>
{items.length === 0 ? (
<div className="mt-3 text-xs text-muted-foreground">
{t("saveAllPreview.empty", { ns: "views/settings" })}
</div>
) : (
<div className="scrollbar-container mt-3 flex max-h-72 flex-col gap-2 overflow-y-auto pr-1">
{items.map((item) => {
const scopeLabel =
item.scope === "global"
? t("saveAllPreview.scope.global", {
ns: "views/settings",
})
: t("saveAllPreview.scope.camera", {
ns: "views/settings",
cameraName: item.cameraName,
});
return (
<div
key={`${item.scope}-${item.cameraName ?? "global"}-${
item.fieldPath
}`}
className="rounded-md border border-secondary bg-background_alt p-2"
>
<div className="grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs">
<span className="text-muted-foreground">
{t("saveAllPreview.scope.label", {
ns: "views/settings",
})}
</span>
<span className="min-w-0 truncate">{scopeLabel}</span>
{item.profileName && (
<>
<span className="text-muted-foreground">
{t("saveAllPreview.profile.label", {
ns: "views/settings",
})}
</span>
<span className="min-w-0 truncate font-medium">
{item.profileName}
</span>
</>
)}
<span className="text-muted-foreground">
{t("saveAllPreview.field.label", {
ns: "views/settings",
})}
</span>
<span className="min-w-0 break-all font-mono">
{item.fieldPath}
</span>
<span className="text-muted-foreground">
{t("saveAllPreview.value.label", {
ns: "views/settings",
})}
</span>
<span className="min-w-0 whitespace-pre-wrap break-all font-mono">
{formatValue(item.value)}
</span>
</div>
</div>
);
})}
</div>
)}
</PopoverContent>
</Popover>
);
}