refactor profilesview and add dots/border colors when overridden

This commit is contained in:
Josh Hawkins 2026-03-11 15:51:29 -05:00
parent 33e4dddb3e
commit 5ec1b1841c
7 changed files with 473 additions and 176 deletions

View File

@ -16,6 +16,12 @@
"maintenance": "Maintenance - Frigate", "maintenance": "Maintenance - Frigate",
"profiles": "Profiles - Frigate" "profiles": "Profiles - Frigate"
}, },
"button": {
"overriddenGlobal": "Overridden (Global)",
"overriddenGlobalTooltip": "This camera overrides global configuration settings in this section",
"overriddenBaseConfig": "Overridden (Base Config)",
"overriddenBaseConfigTooltip": "The {{profile}} profile overrides configuration settings in this section"
},
"menu": { "menu": {
"general": "General", "general": "General",
"globalConfig": "Global configuration", "globalConfig": "Global configuration",
@ -1453,6 +1459,8 @@
"deactivated": "Profile deactivated", "deactivated": "Profile deactivated",
"noProfiles": "No profiles defined. Add a profile from any camera section.", "noProfiles": "No profiles defined. Add a profile from any camera section.",
"noOverrides": "No overrides", "noOverrides": "No overrides",
"cameraCount_one": "{{count}} camera",
"cameraCount_other": "{{count}} cameras",
"baseConfig": "Base Config", "baseConfig": "Base Config",
"addProfile": "Add Profile", "addProfile": "Add Profile",
"newProfile": "New Profile", "newProfile": "New Profile",

View File

@ -28,6 +28,11 @@ import { useConfigOverride } from "@/hooks/use-config-override";
import { useSectionSchema } from "@/hooks/use-config-schema"; import { useSectionSchema } from "@/hooks/use-config-schema";
import type { FrigateConfig } from "@/types/frigateConfig"; import type { FrigateConfig } from "@/types/frigateConfig";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { LuChevronDown, LuChevronRight } from "react-icons/lu"; import { LuChevronDown, LuChevronRight } from "react-icons/lu";
import Heading from "@/components/ui/heading"; import Heading from "@/components/ui/heading";
@ -127,6 +132,7 @@ export interface BaseSectionProps {
onStatusChange?: (status: { onStatusChange?: (status: {
hasChanges: boolean; hasChanges: boolean;
isOverridden: boolean; isOverridden: boolean;
overrideSource?: "global" | "profile";
hasValidationErrors: boolean; hasValidationErrors: boolean;
}) => void; }) => void;
/** Pending form data keyed by "sectionKey" or "cameraName::sectionKey" */ /** Pending form data keyed by "sectionKey" or "cameraName::sectionKey" */
@ -139,6 +145,8 @@ export interface BaseSectionProps {
) => void; ) => void;
/** When set, editing this profile's overrides instead of the base config */ /** When set, editing this profile's overrides instead of the base config */
profileName?: string; profileName?: string;
/** Border color class for profile override badge (e.g., "border-amber-500") */
profileBorderColor?: string;
} }
export interface CreateSectionOptions { export interface CreateSectionOptions {
@ -170,6 +178,7 @@ export function ConfigSection({
pendingDataBySection, pendingDataBySection,
onPendingDataChange, onPendingDataChange,
profileName, profileName,
profileBorderColor,
}: ConfigSectionProps) { }: ConfigSectionProps) {
// For replay level, treat as camera-level config access // For replay level, treat as camera-level config access
const effectiveLevel = level === "replay" ? "camera" : level; const effectiveLevel = level === "replay" ? "camera" : level;
@ -267,7 +276,7 @@ export function ConfigSection({
[sectionPath, level, sectionSchema], [sectionPath, level, sectionSchema],
); );
// Get override status // Get override status (camera vs global)
const { isOverridden, globalValue, cameraValue } = useConfigOverride({ const { isOverridden, globalValue, cameraValue } = useConfigOverride({
config, config,
cameraName: effectiveLevel === "camera" ? cameraName : undefined, cameraName: effectiveLevel === "camera" ? cameraName : undefined,
@ -275,6 +284,16 @@ export function ConfigSection({
compareFields: sectionConfig.overrideFields, compareFields: sectionConfig.overrideFields,
}); });
// Check if the active profile overrides the base config for this section
const profileOverridesSection = useMemo(() => {
if (!profileName || !cameraName || !config) return false;
const profileData = config.cameras?.[cameraName]?.profiles?.[profileName];
return !!profileData?.[sectionPath as keyof typeof profileData];
}, [profileName, cameraName, config, sectionPath]);
const overrideSource: "global" | "profile" | undefined =
profileOverridesSection ? "profile" : isOverridden ? "global" : undefined;
// Get current form data // Get current form data
// When editing a profile, show base camera config deep-merged with profile overrides // When editing a profile, show base camera config deep-merged with profile overrides
const rawSectionValue = useMemo(() => { const rawSectionValue = useMemo(() => {
@ -409,8 +428,20 @@ export function ConfigSection({
}, [formData, pendingData, extraHasChanges]); }, [formData, pendingData, extraHasChanges]);
useEffect(() => { useEffect(() => {
onStatusChange?.({ hasChanges, isOverridden, hasValidationErrors }); onStatusChange?.({
}, [hasChanges, isOverridden, hasValidationErrors, onStatusChange]); hasChanges,
isOverridden: profileOverridesSection || isOverridden,
overrideSource,
hasValidationErrors,
});
}, [
hasChanges,
isOverridden,
profileOverridesSection,
overrideSource,
hasValidationErrors,
onStatusChange,
]);
// Handle form data change // Handle form data change
const handleChange = useCallback( const handleChange = useCallback(
@ -991,13 +1022,32 @@ export function ConfigSection({
<Heading as="h4">{title}</Heading> <Heading as="h4">{title}</Heading>
{showOverrideIndicator && {showOverrideIndicator &&
effectiveLevel === "camera" && effectiveLevel === "camera" &&
isOverridden && ( (profileOverridesSection || isOverridden) && (
<Tooltip>
<TooltipTrigger asChild>
<Badge variant="secondary" className="text-xs"> <Badge variant="secondary" className="text-xs">
{t("button.overridden", { {overrideSource === "profile"
? t("button.overriddenBaseConfig", {
ns: "common", ns: "common",
defaultValue: "Overridden", defaultValue: "Overridden (Base Config)",
})
: t("button.overriddenGlobal", {
ns: "views/settings",
defaultValue: "Overridden (Global)",
})} })}
</Badge> </Badge>
</TooltipTrigger>
<TooltipContent>
{overrideSource === "profile"
? t("button.overriddenBaseConfigTooltip", {
ns: "common",
profile: profileName,
})
: t("button.overriddenGlobalTooltip", {
ns: "views/settings",
})}
</TooltipContent>
</Tooltip>
)} )}
{hasChanges && ( {hasChanges && (
<Badge variant="outline" className="text-xs"> <Badge variant="outline" className="text-xs">
@ -1035,16 +1085,40 @@ export function ConfigSection({
<Heading as="h4">{title}</Heading> <Heading as="h4">{title}</Heading>
{showOverrideIndicator && {showOverrideIndicator &&
effectiveLevel === "camera" && effectiveLevel === "camera" &&
isOverridden && ( (profileOverridesSection || isOverridden) && (
<Tooltip>
<TooltipTrigger asChild>
<Badge <Badge
variant="secondary" variant="secondary"
className="cursor-default border-2 border-selected text-xs text-primary-variant" className={cn(
"cursor-default border-2 text-xs text-primary-variant",
overrideSource === "profile" && profileBorderColor
? profileBorderColor
: "border-selected",
)}
> >
{t("button.overridden", { {overrideSource === "profile"
? t("button.overriddenBaseConfig", {
ns: "common", ns: "common",
defaultValue: "Overridden", defaultValue: "Overridden (Base Config)",
})
: t("button.overriddenGlobal", {
ns: "views/settings",
defaultValue: "Overridden (Global)",
})} })}
</Badge> </Badge>
</TooltipTrigger>
<TooltipContent>
{overrideSource === "profile"
? t("button.overriddenBaseConfigTooltip", {
ns: "common",
profile: profileName,
})
: t("button.overriddenGlobalTooltip", {
ns: "views/settings",
})}
</TooltipContent>
</Tooltip>
)} )}
{hasChanges && ( {hasChanges && (
<Badge <Badge

View File

@ -1309,12 +1309,29 @@ export default function Settings() {
[], [],
); );
// The active profile being edited for the selected camera
const activeEditingProfile = selectedCamera
? (editingProfile[selectedCamera] ?? null)
: null;
// Profile color for the active editing profile
const activeProfileColor = useMemo(
() =>
activeEditingProfile
? getProfileColor(activeEditingProfile, allProfileNames)
: undefined,
[activeEditingProfile, allProfileNames],
);
// Initialize override status for all camera sections // Initialize override status for all camera sections
useEffect(() => { useEffect(() => {
if (!selectedCamera || !cameraOverrides) return; if (!selectedCamera || !cameraOverrides) return;
const overrideMap: Partial< const overrideMap: Partial<
Record<SettingsType, Pick<SectionStatus, "hasChanges" | "isOverridden">> Record<
SettingsType,
Pick<SectionStatus, "hasChanges" | "isOverridden" | "overrideSource">
>
> = {}; > = {};
// Build a set of menu keys that have pending changes for this camera // Build a set of menu keys that have pending changes for this camera
@ -1327,13 +1344,29 @@ export default function Settings() {
} }
} }
// Get profile data if a profile is being edited
const profileData = activeEditingProfile
? config?.cameras?.[selectedCamera]?.profiles?.[activeEditingProfile]
: undefined;
// Set override status for all camera sections using the shared mapping // Set override status for all camera sections using the shared mapping
Object.entries(CAMERA_SECTION_MAPPING).forEach( Object.entries(CAMERA_SECTION_MAPPING).forEach(
([sectionKey, settingsKey]) => { ([sectionKey, settingsKey]) => {
const isOverridden = cameraOverrides.includes(sectionKey); const globalOverridden = cameraOverrides.includes(sectionKey);
// Check if the active profile overrides this section
const profileOverrides = profileData
? !!profileData[sectionKey as keyof typeof profileData]
: false;
overrideMap[settingsKey] = { overrideMap[settingsKey] = {
hasChanges: pendingMenuKeys.has(settingsKey), hasChanges: pendingMenuKeys.has(settingsKey),
isOverridden, isOverridden: profileOverrides || globalOverridden,
overrideSource: profileOverrides
? "profile"
: globalOverridden
? "global"
: undefined,
}; };
}, },
); );
@ -1346,6 +1379,7 @@ export default function Settings() {
merged[key as SettingsType] = { merged[key as SettingsType] = {
hasChanges: status.hasChanges, hasChanges: status.hasChanges,
isOverridden: status.isOverridden, isOverridden: status.isOverridden,
overrideSource: status.overrideSource,
hasValidationErrors: existingStatus?.hasValidationErrors ?? false, hasValidationErrors: existingStatus?.hasValidationErrors ?? false,
}; };
}); });
@ -1356,6 +1390,8 @@ export default function Settings() {
cameraOverrides, cameraOverrides,
pendingDataBySection, pendingDataBySection,
pendingKeyToMenuKey, pendingKeyToMenuKey,
activeEditingProfile,
config,
]); ]);
const renderMenuItemLabel = useCallback( const renderMenuItemLabel = useCallback(
@ -1365,13 +1401,20 @@ export default function Settings() {
CAMERA_SECTION_KEYS.has(key) && status?.isOverridden; CAMERA_SECTION_KEYS.has(key) && status?.isOverridden;
const showUnsavedDot = status?.hasChanges; const showUnsavedDot = status?.hasChanges;
const dotColor =
status?.overrideSource === "profile" && activeProfileColor
? activeProfileColor.dot
: "bg-selected";
return ( return (
<div className="flex w-full items-center justify-between pr-4 md:pr-0"> <div className="flex w-full items-center justify-between pr-4 md:pr-0">
<div>{t("menu." + key)}</div> <div>{t("menu." + key)}</div>
{(showOverrideDot || showUnsavedDot) && ( {(showOverrideDot || showUnsavedDot) && (
<div className="ml-2 flex items-center gap-2"> <div className="ml-2 flex items-center gap-2">
{showOverrideDot && ( {showOverrideDot && (
<span className="inline-block size-2 rounded-full bg-selected" /> <span
className={cn("inline-block size-2 rounded-full", dotColor)}
/>
)} )}
{showUnsavedDot && ( {showUnsavedDot && (
<span className="inline-block size-2 rounded-full bg-danger" /> <span className="inline-block size-2 rounded-full bg-danger" />
@ -1381,7 +1424,7 @@ export default function Settings() {
</div> </div>
); );
}, },
[sectionStatusByKey, t], [sectionStatusByKey, t, activeProfileColor],
); );
if (isMobile) { if (isMobile) {

View File

@ -2,6 +2,7 @@ export type ProfileColor = {
bg: string; bg: string;
text: string; text: string;
dot: string; dot: string;
border: string;
bgMuted: string; bgMuted: string;
}; };

View File

@ -5,48 +5,56 @@ const PROFILE_COLORS: ProfileColor[] = [
bg: "bg-amber-500", bg: "bg-amber-500",
text: "text-amber-500", text: "text-amber-500",
dot: "bg-amber-500", dot: "bg-amber-500",
border: "border-amber-500",
bgMuted: "bg-amber-500/20", bgMuted: "bg-amber-500/20",
}, },
{ {
bg: "bg-purple-500", bg: "bg-purple-500",
text: "text-purple-500", text: "text-purple-500",
dot: "bg-purple-500", dot: "bg-purple-500",
border: "border-purple-500",
bgMuted: "bg-purple-500/20", bgMuted: "bg-purple-500/20",
}, },
{ {
bg: "bg-rose-500", bg: "bg-rose-500",
text: "text-rose-500", text: "text-rose-500",
dot: "bg-rose-500", dot: "bg-rose-500",
border: "border-rose-500",
bgMuted: "bg-rose-500/20", bgMuted: "bg-rose-500/20",
}, },
{ {
bg: "bg-cyan-500", bg: "bg-cyan-500",
text: "text-cyan-500", text: "text-cyan-500",
dot: "bg-cyan-500", dot: "bg-cyan-500",
border: "border-cyan-500",
bgMuted: "bg-cyan-500/20", bgMuted: "bg-cyan-500/20",
}, },
{ {
bg: "bg-orange-500", bg: "bg-orange-500",
text: "text-orange-500", text: "text-orange-500",
dot: "bg-orange-500", dot: "bg-orange-500",
border: "border-orange-500",
bgMuted: "bg-orange-500/20", bgMuted: "bg-orange-500/20",
}, },
{ {
bg: "bg-teal-500", bg: "bg-teal-500",
text: "text-teal-500", text: "text-teal-500",
dot: "bg-teal-500", dot: "bg-teal-500",
border: "border-teal-500",
bgMuted: "bg-teal-500/20", bgMuted: "bg-teal-500/20",
}, },
{ {
bg: "bg-emerald-500", bg: "bg-emerald-500",
text: "text-emerald-500", text: "text-emerald-500",
dot: "bg-emerald-500", dot: "bg-emerald-500",
border: "border-emerald-500",
bgMuted: "bg-emerald-500/20", bgMuted: "bg-emerald-500/20",
}, },
{ {
bg: "bg-blue-500", bg: "bg-blue-500",
text: "text-blue-500", text: "text-blue-500",
dot: "bg-blue-500", dot: "bg-blue-500",
border: "border-blue-500",
bgMuted: "bg-blue-500/20", bgMuted: "bg-blue-500/20",
}, },
]; ];

View File

@ -3,7 +3,8 @@ import { useTranslation } from "react-i18next";
import useSWR from "swr"; import useSWR from "swr";
import axios from "axios"; import axios from "axios";
import { toast } from "sonner"; import { toast } from "sonner";
import { Camera, Trash2 } from "lucide-react"; import { Trash2 } from "lucide-react";
import { LuChevronDown, LuChevronRight, LuPlus } from "react-icons/lu";
import type { FrigateConfig } from "@/types/frigateConfig"; import type { FrigateConfig } from "@/types/frigateConfig";
import type { ProfileState } from "@/types/profile"; import type { ProfileState } from "@/types/profile";
import { getProfileColor } from "@/utils/profileColors"; import { getProfileColor } from "@/utils/profileColors";
@ -13,6 +14,7 @@ import { cn } from "@/lib/utils";
import Heading from "@/components/ui/heading"; import Heading from "@/components/ui/heading";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
import { import {
Select, Select,
SelectContent, SelectContent,
@ -20,6 +22,18 @@ import {
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@/components/ui/select"; } from "@/components/ui/select";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { import {
AlertDialog, AlertDialog,
AlertDialogAction, AlertDialogAction,
@ -32,6 +46,7 @@ import {
} from "@/components/ui/alert-dialog"; } from "@/components/ui/alert-dialog";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import ActivityIndicator from "@/components/indicators/activity-indicator";
type ProfilesApiResponse = { type ProfilesApiResponse = {
profiles: string[]; profiles: string[];
@ -59,6 +74,12 @@ export default function ProfilesView({
const [activating, setActivating] = useState(false); const [activating, setActivating] = useState(false);
const [deleteProfile, setDeleteProfile] = useState<string | null>(null); const [deleteProfile, setDeleteProfile] = useState<string | null>(null);
const [deleting, setDeleting] = useState(false); const [deleting, setDeleting] = useState(false);
const [expandedProfiles, setExpandedProfiles] = useState<Set<string>>(
new Set(),
);
const [addDialogOpen, setAddDialogOpen] = useState(false);
const [newProfileName, setNewProfileName] = useState("");
const [nameError, setNameError] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
document.title = t("documentTitle.profiles", { document.title = t("documentTitle.profiles", {
@ -105,13 +126,33 @@ export default function ProfilesView({
return data; return data;
}, [config, allProfileNames]); }, [config, allProfileNames]);
const cameraCount = useMemo(() => { const validateName = useCallback(
if (!config) return 0; (name: string): string | null => {
return Object.keys(profileOverviewData).reduce((max, profile) => { if (!name.trim()) return null;
const count = Object.keys(profileOverviewData[profile] ?? {}).length; if (!/^[a-z0-9_]+$/.test(name)) {
return Math.max(max, count); return t("profiles.nameInvalid", { ns: "views/settings" });
}, 0); }
}, [config, profileOverviewData]); if (allProfileNames.includes(name)) {
return t("profiles.nameDuplicate", { ns: "views/settings" });
}
return null;
},
[allProfileNames, t],
);
const handleAddSubmit = useCallback(() => {
const name = newProfileName.trim();
if (!name) return;
const error = validateName(name);
if (error) {
setNameError(error);
return;
}
profileState?.onAddProfile(name);
setAddDialogOpen(false);
setNewProfileName("");
setNameError(null);
}, [newProfileName, validateName, profileState]);
const handleActivateProfile = useCallback( const handleActivateProfile = useCallback(
async (profile: string | null) => { async (profile: string | null) => {
@ -215,6 +256,18 @@ export default function ProfilesView({
t, t,
]); ]);
const toggleExpanded = useCallback((profile: string) => {
setExpandedProfiles((prev) => {
const next = new Set(prev);
if (next.has(profile)) {
next.delete(profile);
} else {
next.add(profile);
}
return next;
});
}, []);
if (!config || !profilesData) { if (!config || !profilesData) {
return null; return null;
} }
@ -244,19 +297,20 @@ export default function ProfilesView({
</div> </div>
)} )}
{profilesUIEnabled && ( {profilesUIEnabled && !hasProfiles && (
<p className="mb-5 max-w-xl text-sm text-primary-variant"> <p className="mb-5 max-w-xl text-sm text-primary-variant">
{t("profiles.enabledDescription", { ns: "views/settings" })} {t("profiles.enabledDescription", { ns: "views/settings" })}
</p> </p>
)} )}
{/* Active Profile Section — only when profiles exist */} {/* Active Profile + Add Profile bar */}
{(hasProfiles || profilesUIEnabled) && (
<div className="my-4 flex items-center justify-between rounded-lg border border-border/70 bg-card/30 p-4">
{hasProfiles && ( {hasProfiles && (
<div className="mb-6 rounded-lg border border-border/70 bg-card/30 p-4">
<div className="mb-3 text-sm font-semibold text-primary-variant">
{t("profiles.activeProfile", { ns: "views/settings" })}
</div>
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<span className="text-sm font-semibold text-primary-variant">
{t("profiles.activeProfile", { ns: "views/settings" })}
</span>
<Select <Select
value={activeProfile ?? "__none__"} value={activeProfile ?? "__none__"}
onValueChange={(v) => onValueChange={(v) =>
@ -264,7 +318,7 @@ export default function ProfilesView({
} }
disabled={activating} disabled={activating}
> >
<SelectTrigger className="w-[200px]"> <SelectTrigger className="">
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
@ -289,22 +343,21 @@ export default function ProfilesView({
})} })}
</SelectContent> </SelectContent>
</Select> </Select>
{activeProfile && ( {activating && <ActivityIndicator className="w-auto" size={18} />}
<Badge
className={cn(
"cursor-default",
getProfileColor(activeProfile, allProfileNames).bg,
"text-white",
)}
>
{t("profiles.active", { ns: "views/settings" })}
</Badge>
)}
</div> </div>
)}
<Button
variant="default"
size="sm"
onClick={() => setAddDialogOpen(true)}
>
<LuPlus className="mr-1.5 size-4" />
{t("profiles.addProfile", { ns: "views/settings" })}
</Button>
</div> </div>
)} )}
{/* Profile Cards */} {/* Profile List */}
{!hasProfiles ? ( {!hasProfiles ? (
profilesUIEnabled ? ( profilesUIEnabled ? (
<p className="text-sm text-muted-foreground"> <p className="text-sm text-muted-foreground">
@ -314,28 +367,39 @@ export default function ProfilesView({
<div /> <div />
) )
) : ( ) : (
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-2">
{allProfileNames.map((profile) => { {allProfileNames.map((profile) => {
const color = getProfileColor(profile, allProfileNames); const color = getProfileColor(profile, allProfileNames);
const isActive = activeProfile === profile; const isActive = activeProfile === profile;
const cameraData = profileOverviewData[profile] ?? {}; const cameraData = profileOverviewData[profile] ?? {};
const cameras = Object.keys(cameraData).sort(); const cameras = Object.keys(cameraData).sort();
const isExpanded = expandedProfiles.has(profile);
return ( return (
<div <Collapsible
key={profile} key={profile}
open={isExpanded}
onOpenChange={() => toggleExpanded(profile)}
>
<div
className={cn( className={cn(
"rounded-lg border p-4", "rounded-lg border",
isActive isActive
? "border-selected bg-selected/5" ? "border-selected bg-selected/5"
: "border-border/70 bg-card/30", : "border-border/70",
)} )}
> >
<div className="mb-3 flex items-center justify-between"> <CollapsibleTrigger asChild>
<div className="flex items-center gap-2"> <div className="flex cursor-pointer items-center justify-between px-4 py-3 hover:bg-secondary/30">
<div className="flex items-center gap-3">
{isExpanded ? (
<LuChevronDown className="size-4 text-muted-foreground" />
) : (
<LuChevronRight className="size-4 text-muted-foreground" />
)}
<span <span
className={cn( className={cn(
"h-2.5 w-2.5 shrink-0 rounded-full", "size-2.5 shrink-0 rounded-full",
color.dot, color.dot,
)} )}
/> />
@ -349,69 +413,125 @@ export default function ProfilesView({
</Badge> </Badge>
)} )}
</div> </div>
<div className="flex items-center gap-3">
<span className="text-sm text-muted-foreground">
{cameras.length > 0
? t("profiles.cameraCount", {
ns: "views/settings",
count: cameras.length,
})
: t("profiles.noOverrides", {
ns: "views/settings",
})}
</span>
<Button <Button
variant="ghost" variant="ghost"
size="icon" size="icon"
className="h-7 w-7 text-muted-foreground hover:text-destructive" className="size-7 text-muted-foreground hover:text-destructive"
onClick={() => setDeleteProfile(profile)} onClick={(e) => {
e.stopPropagation();
setDeleteProfile(profile);
}}
> >
<Trash2 className="h-4 w-4" /> <Trash2 className="size-4" />
</Button> </Button>
</div> </div>
</div>
{cameras.length === 0 ? ( </CollapsibleTrigger>
<p className="text-xs text-muted-foreground"> <CollapsibleContent>
{t("profiles.noOverrides", { ns: "views/settings" })} {cameras.length > 0 ? (
</p> <div className="mx-4 mb-3 ml-11 border-l border-border/50 pl-4">
) : (
<div
className={cn(
"grid gap-2",
cameraCount <= 3
? "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3"
: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",
)}
>
{cameras.map((camera) => { {cameras.map((camera) => {
const sections = cameraData[camera]; const sections = cameraData[camera];
return ( return (
<div <div
key={camera} key={camera}
className="flex items-start gap-2 rounded-md bg-secondary/40 px-3 py-2" className="flex items-baseline gap-3 py-1.5"
> >
<Camera className="mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" /> <span className="min-w-[120px] shrink-0 truncate text-sm font-medium">
<div className="min-w-0">
<div className="truncate text-xs font-medium">
{resolveCameraName(config, camera)} {resolveCameraName(config, camera)}
</div> </span>
<div className="mt-1 flex flex-wrap gap-1"> <span className="text-sm text-muted-foreground">
{sections.map((section) => ( {sections
<span .map((section) =>
key={section} t(`configForm.sections.${section}`, {
className={cn(
"rounded px-1.5 py-0.5 text-[10px] leading-tight text-white",
color.bg,
)}
>
{t(`configForm.sections.${section}`, {
ns: "views/settings", ns: "views/settings",
defaultValue: section, defaultValue: section,
})} }),
)
.join(", ")}
</span> </span>
))}
</div>
</div>
</div> </div>
); );
})} })}
</div> </div>
)} ) : (
<div className="mx-4 mb-3 ml-11 text-sm text-muted-foreground">
{t("profiles.noOverrides", { ns: "views/settings" })}
</div> </div>
)}
</CollapsibleContent>
</div>
</Collapsible>
); );
})} })}
</div> </div>
)} )}
{/* Add Profile Dialog */}
<Dialog
open={addDialogOpen}
onOpenChange={(open) => {
setAddDialogOpen(open);
if (!open) {
setNewProfileName("");
setNameError(null);
}
}}
>
<DialogContent className="sm:max-w-[360px]">
<DialogHeader>
<DialogTitle>
{t("profiles.newProfile", { ns: "views/settings" })}
</DialogTitle>
</DialogHeader>
<div className="space-y-2 py-2">
<Input
placeholder={t("profiles.profileNamePlaceholder", {
ns: "views/settings",
})}
value={newProfileName}
onChange={(e) => {
setNewProfileName(e.target.value);
setNameError(validateName(e.target.value));
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
handleAddSubmit();
}
}}
autoFocus
/>
{nameError && (
<p className="text-xs text-destructive">{nameError}</p>
)}
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setAddDialogOpen(false)}>
{t("button.cancel", { ns: "common" })}
</Button>
<Button
variant="select"
onClick={handleAddSubmit}
disabled={!newProfileName.trim() || !!nameError}
>
{t("button.add", { ns: "common" })}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
{/* Delete Profile Confirmation */} {/* Delete Profile Confirmation */}
<AlertDialog <AlertDialog
open={!!deleteProfile} open={!!deleteProfile}

View File

@ -4,9 +4,16 @@ import type { SectionConfig } from "@/components/config-form/sections";
import { ConfigSectionTemplate } from "@/components/config-form/sections"; import { ConfigSectionTemplate } from "@/components/config-form/sections";
import type { PolygonType } from "@/types/canvas"; import type { PolygonType } from "@/types/canvas";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import type { ConfigSectionData } from "@/types/configForm"; import type { ConfigSectionData } from "@/types/configForm";
import type { ProfileState } from "@/types/profile"; import type { ProfileState } from "@/types/profile";
import { getSectionConfig } from "@/utils/configUtil"; import { getSectionConfig } from "@/utils/configUtil";
import { getProfileColor } from "@/utils/profileColors";
import { cn } from "@/lib/utils";
import { useDocDomain } from "@/hooks/use-doc-domain"; import { useDocDomain } from "@/hooks/use-doc-domain";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { LuExternalLink } from "react-icons/lu"; import { LuExternalLink } from "react-icons/lu";
@ -35,6 +42,8 @@ export type SettingsPageProps = {
export type SectionStatus = { export type SectionStatus = {
hasChanges: boolean; hasChanges: boolean;
isOverridden: boolean; isOverridden: boolean;
/** Where the override comes from: "global" = camera overrides global, "profile" = profile overrides base */
overrideSource?: "global" | "profile";
hasValidationErrors: boolean; hasValidationErrors: boolean;
}; };
@ -87,6 +96,14 @@ export function SingleSectionPage({
? (profileState?.editingProfile[selectedCamera] ?? null) ? (profileState?.editingProfile[selectedCamera] ?? null)
: null; : null;
const profileColor = useMemo(
() =>
currentEditingProfile && profileState?.allProfileNames
? getProfileColor(currentEditingProfile, profileState.allProfileNames)
: undefined,
[currentEditingProfile, profileState?.allProfileNames],
);
const handleSectionStatusChange = useCallback( const handleSectionStatusChange = useCallback(
(status: SectionStatus) => { (status: SectionStatus) => {
setSectionStatus(status); setSectionStatus(status);
@ -136,15 +153,40 @@ export function SingleSectionPage({
{level === "camera" && {level === "camera" &&
showOverrideIndicator && showOverrideIndicator &&
sectionStatus.isOverridden && ( sectionStatus.isOverridden && (
<Tooltip>
<TooltipTrigger asChild>
<Badge <Badge
variant="secondary" variant="secondary"
className="cursor-default border-2 border-selected text-xs text-primary-variant" className={cn(
"cursor-default border-2 text-xs text-primary-variant",
sectionStatus.overrideSource === "profile" &&
profileColor
? profileColor.border
: "border-selected",
)}
> >
{t("button.overridden", { {sectionStatus.overrideSource === "profile"
ns: "common", ? t("button.overriddenBaseConfig", {
defaultValue: "Overridden", ns: "views/settings",
defaultValue: "Overridden (Base Config)",
})
: t("button.overriddenGlobal", {
ns: "views/settings",
defaultValue: "Overridden (Global)",
})} })}
</Badge> </Badge>
</TooltipTrigger>
<TooltipContent>
{sectionStatus.overrideSource === "profile"
? t("button.overriddenBaseConfigTooltip", {
ns: "common",
profile: currentEditingProfile,
})
: t("button.overriddenGlobalTooltip", {
ns: "views/settings",
})}
</TooltipContent>
</Tooltip>
)} )}
{sectionStatus.hasChanges && ( {sectionStatus.hasChanges && (
<Badge <Badge
@ -170,6 +212,7 @@ export function SingleSectionPage({
requiresRestart={requiresRestart} requiresRestart={requiresRestart}
onStatusChange={handleSectionStatusChange} onStatusChange={handleSectionStatusChange}
profileName={currentEditingProfile ?? undefined} profileName={currentEditingProfile ?? undefined}
profileBorderColor={profileColor?.border}
/> />
</div> </div>
); );