frigate/web/src/views/settings/SingleSectionPage.tsx

130 lines
4.0 KiB
TypeScript
Raw Normal View History

import { useState } from "react";
2026-01-31 21:35:23 +03:00
import { useTranslation } from "react-i18next";
import type { SectionConfig } from "@/components/config-form/sections";
import { ConfigSectionTemplate } from "@/components/config-form/sections";
2026-01-31 21:35:23 +03:00
import type { PolygonType } from "@/types/canvas";
import { Badge } from "@/components/ui/badge";
import type { ConfigSectionData } from "@/types/configForm";
2026-01-31 21:35:23 +03:00
export type SettingsPageProps = {
selectedCamera?: string;
setUnsavedChanges?: React.Dispatch<React.SetStateAction<boolean>>;
selectedZoneMask?: PolygonType[];
onSectionStatusChange?: (
sectionKey: string,
level: "global" | "camera",
status: SectionStatus,
) => void;
pendingDataBySection?: Record<string, unknown>;
onPendingDataChange?: (
sectionKey: string,
cameraName: string | undefined,
data: ConfigSectionData | null,
) => void;
};
export type SectionStatus = {
hasChanges: boolean;
isOverridden: boolean;
2026-01-31 21:35:23 +03:00
};
export type SingleSectionPageOptions = {
sectionKey: string;
level: "global" | "camera";
sectionConfig?: SectionConfig;
requiresRestart?: boolean;
showOverrideIndicator?: boolean;
};
2026-02-01 21:44:54 +03:00
export type SingleSectionPageProps = SettingsPageProps &
SingleSectionPageOptions;
export function SingleSectionPage({
2026-01-31 21:35:23 +03:00
sectionKey,
level,
sectionConfig,
requiresRestart,
showOverrideIndicator = true,
2026-02-01 21:44:54 +03:00
selectedCamera,
setUnsavedChanges,
pendingDataBySection,
onPendingDataChange,
2026-02-01 21:44:54 +03:00
}: SingleSectionPageProps) {
const sectionNamespace =
level === "camera" ? "config/cameras" : "config/global";
const { t, i18n } = useTranslation([
sectionNamespace,
"views/settings",
"common",
]);
const [sectionStatus, setSectionStatus] = useState<SectionStatus>({
hasChanges: false,
isOverridden: false,
});
2026-02-01 21:44:54 +03:00
if (level === "camera" && !selectedCamera) {
2026-01-31 21:35:23 +03:00
return (
2026-02-01 21:44:54 +03:00
<div className="flex h-full items-center justify-center text-muted-foreground">
{t("configForm.camera.noCameras", { ns: "views/settings" })}
2026-01-31 21:35:23 +03:00
</div>
);
2026-02-01 21:44:54 +03:00
}
return (
<div className="flex size-full flex-col lg:pr-2">
<div className="mb-5 flex items-center justify-between gap-4">
<div className="flex flex-col">
<div className="text-xl">
{t(`${sectionKey}.label`, { ns: sectionNamespace })}
</div>
{i18n.exists(`${sectionKey}.description`, {
ns: sectionNamespace,
}) && (
<div className="my-1 text-sm text-muted-foreground">
{t(`${sectionKey}.description`, { ns: sectionNamespace })}
</div>
)}
</div>
<div className="flex flex-col items-end gap-2 md:flex-row md:items-center">
<div className="flex flex-wrap items-center justify-end gap-2">
{level === "camera" &&
showOverrideIndicator &&
sectionStatus.isOverridden && (
<Badge
variant="secondary"
className="border-2 border-selected text-xs text-primary-variant"
>
{t("overridden", {
ns: "common",
defaultValue: "Overridden",
})}
</Badge>
)}
{sectionStatus.hasChanges && (
<Badge
variant="secondary"
className="bg-danger text-xs text-white"
>
{t("modified", { ns: "common", defaultValue: "Modified" })}
</Badge>
)}
</div>
</div>
2026-02-01 21:44:54 +03:00
</div>
<ConfigSectionTemplate
sectionKey={sectionKey}
level={level}
cameraName={level === "camera" ? selectedCamera : undefined}
showOverrideIndicator={showOverrideIndicator}
onSave={() => setUnsavedChanges?.(false)}
showTitle={false}
sectionConfig={sectionConfig}
pendingDataBySection={pendingDataBySection}
onPendingDataChange={onPendingDataChange}
2026-02-01 21:44:54 +03:00
requiresRestart={requiresRestart}
onStatusChange={setSectionStatus}
2026-02-01 21:44:54 +03:00
/>
</div>
);
2026-01-31 21:35:23 +03:00
}