Fix camera filtering logic (#12457)

* Fix camera filtering logic

* Cleanup

* Simplify and consider birdseye only group in logic

* Don't add filter when group is birdseye only
This commit is contained in:
Nicolas Mowen 2024-07-15 09:34:41 -06:00 committed by GitHub
parent 5066fa369d
commit 82d2910039
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View File

@ -71,8 +71,10 @@ export default function Events() {
useSearchEffect("group", (reviewGroup) => {
if (config && reviewGroup) {
const group = config.camera_groups[reviewGroup];
const isBirdseyeOnly =
group.cameras.length == 1 && group.cameras[0] == "birdseye";
if (group) {
if (group && !isBirdseyeOnly) {
setReviewFilter({
...reviewFilter,
cameras: group.cameras,

View File

@ -113,7 +113,7 @@ function Live() {
) : (
<LiveDashboardView
cameras={cameras}
cameraGroup={cameraGroup}
cameraGroup={cameraGroup ?? "default"}
includeBirdseye={includesBirdseye}
onSelectCamera={setSelectedCameraName}
fullscreen={fullscreen}

View File

@ -34,7 +34,7 @@ import { useResizeObserver } from "@/hooks/resize-observer";
type LiveDashboardViewProps = {
cameras: CameraConfig[];
cameraGroup?: string;
cameraGroup: string;
includeBirdseye: boolean;
onSelectCamera: (camera: string) => void;
fullscreen: boolean;
@ -64,12 +64,31 @@ export default function LiveDashboardView({
// recent events
const eventUpdate = useFrigateReviews();
const alertCameras = useMemo(() => {
if (!config || cameraGroup == "default") {
return null;
}
if (includeBirdseye && cameras.length == 0) {
return Object.values(config.cameras)
.filter((cam) => cam.birdseye.enabled)
.map((cam) => cam.name)
.join(",");
}
return cameras
.map((cam) => cam.name)
.filter((cam) => config.camera_groups[cameraGroup].cameras.includes(cam))
.join(",");
}, [cameras, cameraGroup, config, includeBirdseye]);
const { data: allEvents, mutate: updateEvents } = useSWR<ReviewSegment[]>([
"review",
{
limit: 10,
severity: "alert",
cameras: cameraGroup && cameras.filter((cam) => cam.name).join(","),
cameras: alertCameras,
},
]);