From 8c8258165c58b3b6f8d3a9271422578dd2c6d023 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Fri, 27 Mar 2026 08:44:07 -0500 Subject: [PATCH] add review labels widget --- .../widgets/ReviewLabelSwitchesWidget.tsx | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 web/src/components/config-form/theme/widgets/ReviewLabelSwitchesWidget.tsx diff --git a/web/src/components/config-form/theme/widgets/ReviewLabelSwitchesWidget.tsx b/web/src/components/config-form/theme/widgets/ReviewLabelSwitchesWidget.tsx new file mode 100644 index 000000000..c19eaaf9d --- /dev/null +++ b/web/src/components/config-form/theme/widgets/ReviewLabelSwitchesWidget.tsx @@ -0,0 +1,78 @@ +// Review Label Switches Widget - For selecting review alert/detection labels via switches. +// Combines object labels (from objects.track) and audio labels (from audio.listen) +// since review labels can include both types. +import type { WidgetProps } from "@rjsf/utils"; +import { SwitchesWidget } from "./SwitchesWidget"; +import type { FormContext } from "./SwitchesWidget"; +import { getTranslatedLabel } from "@/utils/i18n"; +import type { FrigateConfig } from "@/types/frigateConfig"; +import type { JsonObject } from "@/types/configForm"; + +function getReviewLabels(context: FormContext): string[] { + const labels = new Set(); + const fullConfig = context.fullConfig as FrigateConfig | undefined; + const fullCameraConfig = context.fullCameraConfig; + + // Object labels from tracked objects (camera-level, falling back to global) + const trackLabels = + fullCameraConfig?.objects?.track ?? fullConfig?.objects?.track; + if (Array.isArray(trackLabels)) { + trackLabels.forEach((label: string) => labels.add(label)); + } + + // Audio labels from listen config (camera-level, falling back to global) + const audioLabels = + fullCameraConfig?.audio?.listen ?? fullConfig?.audio?.listen; + if (Array.isArray(audioLabels)) { + audioLabels.forEach((label: string) => labels.add(label)); + } + + // Include any labels already in the review form data (alerts + detections) + // so that previously saved labels remain visible even if tracking config changed + if (context.formData && typeof context.formData === "object") { + const formData = context.formData as JsonObject; + for (const section of ["alerts", "detections"] as const) { + const sectionData = formData[section]; + if (sectionData && typeof sectionData === "object") { + const sectionLabels = (sectionData as JsonObject).labels; + if (Array.isArray(sectionLabels)) { + sectionLabels.forEach((label) => { + if (typeof label === "string") { + labels.add(label); + } + }); + } + } + } + } + + return [...labels].sort(); +} + +function getReviewLabelDisplayName( + label: string, + context?: FormContext, +): string { + const fullCameraConfig = context?.fullCameraConfig; + const fullConfig = context?.fullConfig as FrigateConfig | undefined; + const audioLabels = + fullCameraConfig?.audio?.listen ?? fullConfig?.audio?.listen; + const isAudio = Array.isArray(audioLabels) && audioLabels.includes(label); + return getTranslatedLabel(label, isAudio ? "audio" : "object"); +} + +export function ReviewLabelSwitchesWidget(props: WidgetProps) { + return ( + + ); +}