Fix filter args (#13718)

* Fix filter args in events

* Fix export arg

* Don'
t fail

* Fix filter buttons

* Fix right click

* Formatting
This commit is contained in:
Nicolas Mowen 2024-09-13 07:25:29 -06:00 committed by GitHub
parent 90c1cc3e3b
commit a1fd29b34b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 88 additions and 18 deletions

View File

@ -135,11 +135,13 @@ export function AnimatedEventCard({
<div <div
className="size-full cursor-pointer overflow-hidden rounded md:rounded-lg" className="size-full cursor-pointer overflow-hidden rounded md:rounded-lg"
onClick={onOpenReview} onClick={onOpenReview}
onAuxClick={() => onAuxClick={(e) => {
if (e.button === 1) {
window window
.open(`${baseUrl}review?id=${event.id}`, "_blank") .open(`${baseUrl}review?id=${event.id}`, "_blank")
?.focus() ?.focus();
} }
}}
> >
{!alertVideos ? ( {!alertVideos ? (
<img <img

View File

@ -159,7 +159,7 @@ export default function ExportCard({
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500" className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
onClick={() => onClick={() =>
shareOrCopy( shareOrCopy(
`${baseUrl}exports?id=${exportedRecording.id}`, `${baseUrl}export?id=${exportedRecording.id}`,
exportedRecording.name.replaceAll("_", " "), exportedRecording.name.replaceAll("_", " "),
) )
} }

View File

@ -1,6 +1,6 @@
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { CameraGroupConfig } from "@/types/frigateConfig"; import { CameraGroupConfig } from "@/types/frigateConfig";
import { useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuContent, DropdownMenuContent,
@ -53,6 +53,17 @@ export function CamerasFilterButton({
}`; }`;
}, [allCamerasSelected, currentCameras]); }, [allCamerasSelected, currentCameras]);
// ui
useEffect(() => {
setCurrentCameras(
selectedCameras === undefined ? [...allCameras] : selectedCameras,
);
setAllCamerasSelected(selectedCameras === undefined);
// only refresh when state changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedCameras]);
const trigger = ( const trigger = (
<Button <Button
className="flex items-center gap-2 capitalize" className="flex items-center gap-2 capitalize"

View File

@ -2,7 +2,7 @@ import { Button } from "../ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
import useSWR from "swr"; import useSWR from "swr";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import { useCallback, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { DropdownMenuSeparator } from "../ui/dropdown-menu"; import { DropdownMenuSeparator } from "../ui/dropdown-menu";
import { ReviewFilter, ReviewSeverity, ReviewSummary } from "@/types/review"; import { ReviewFilter, ReviewSeverity, ReviewSummary } from "@/types/review";
import { getEndOfDayTimestamp } from "@/utils/dateUtil"; import { getEndOfDayTimestamp } from "@/utils/dateUtil";
@ -321,6 +321,15 @@ function GeneralFilterButton({
selectedZones, selectedZones,
); );
// ui
useEffect(() => {
setCurrentLabels(selectedLabels);
setCurrentZones(selectedZones);
// only refresh when state changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedLabels, selectedZones]);
const trigger = ( const trigger = (
<Button <Button
size="sm" size="sm"

View File

@ -2,7 +2,7 @@ import { Button } from "../ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
import useSWR from "swr"; import useSWR from "swr";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import { useCallback, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { DropdownMenuSeparator } from "../ui/dropdown-menu"; import { DropdownMenuSeparator } from "../ui/dropdown-menu";
import { getEndOfDayTimestamp } from "@/utils/dateUtil"; import { getEndOfDayTimestamp } from "@/utils/dateUtil";
import { isMobile } from "react-device-detect"; import { isMobile } from "react-device-detect";
@ -261,6 +261,14 @@ function GeneralFilterButton({
return `${selectedLabels.length} Labels`; return `${selectedLabels.length} Labels`;
}, [selectedLabels]); }, [selectedLabels]);
// ui
useEffect(() => {
setCurrentLabels(selectedLabels);
// only refresh when state changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedLabels]);
const trigger = ( const trigger = (
<Button <Button
size="sm" size="sm"
@ -447,6 +455,14 @@ function ZoneFilterButton({
return `${selectedZones.length} Zones`; return `${selectedZones.length} Zones`;
}, [selectedZones]); }, [selectedZones]);
// ui
useEffect(() => {
setCurrentZones(selectedZones);
// only refresh when state changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedZones]);
const trigger = ( const trigger = (
<Button <Button
size="sm" size="sm"

View File

@ -226,9 +226,11 @@ export default function LivePlayer({
className, className,
)} )}
onClick={onClick} onClick={onClick}
onAuxClick={() => onAuxClick={(e) => {
window.open(`${baseUrl}#${cameraConfig.name}`, "_blank")?.focus() if (e.button === 1) {
window.open(`${baseUrl}#${cameraConfig.name}`, "_blank")?.focus();
} }
}}
> >
{((showStillWithoutActivity && !liveReady) || liveReady) && ( {((showStillWithoutActivity && !liveReady) || liveReady) && (
<> <>

View File

@ -177,9 +177,11 @@ export default function PreviewThumbnailPlayer({
onMouseOver={isMobile ? undefined : () => setIsHovered(true)} onMouseOver={isMobile ? undefined : () => setIsHovered(true)}
onMouseLeave={isMobile ? undefined : () => setIsHovered(false)} onMouseLeave={isMobile ? undefined : () => setIsHovered(false)}
onClick={handleOnClick} onClick={handleOnClick}
onAuxClick={() => onAuxClick={(e) => {
window.open(`${baseUrl}review?id=${review.id}`, "_blank")?.focus() if (e.button === 1) {
window.open(`${baseUrl}review?id=${review.id}`, "_blank")?.focus();
} }
}}
{...swipeHandlers} {...swipeHandlers}
> >
{playingBack && ( {playingBack && (

View File

@ -69,7 +69,11 @@ export function useApiFilterArgs<
filter[key] = value.includes(",") ? value.split(",") : [value]; filter[key] = value.includes(",") ? value.split(",") : [value];
} else { } else {
if (value != undefined) { if (value != undefined) {
try {
filter[key] = JSON.parse(value); filter[key] = JSON.parse(value);
} catch {
filter[key] = `${value}`;
}
} }
} }
}); });

View File

@ -1,5 +1,5 @@
import ActivityIndicator from "@/components/indicators/activity-indicator"; import ActivityIndicator from "@/components/indicators/activity-indicator";
import { useApiFilterArgs } from "@/hooks/use-api-filter"; import useApiFilter from "@/hooks/use-api-filter";
import { useCameraPreviews } from "@/hooks/use-camera-previews"; import { useCameraPreviews } from "@/hooks/use-camera-previews";
import { useTimezone } from "@/hooks/use-date-utils"; import { useTimezone } from "@/hooks/use-date-utils";
import { useOverlayState, useSearchEffect } from "@/hooks/use-overlay-state"; import { useOverlayState, useSearchEffect } from "@/hooks/use-overlay-state";
@ -71,7 +71,31 @@ export default function Events() {
// review filter // review filter
const [reviewFilter, setReviewFilter, reviewSearchParams] = const [reviewFilter, setReviewFilter, reviewSearchParams] =
useApiFilterArgs<ReviewFilter>(); useApiFilter<ReviewFilter>();
useSearchEffect("cameras", (cameras: string) => {
setReviewFilter({
...reviewFilter,
cameras: cameras.includes(",") ? cameras.split(",") : [cameras],
});
return true;
});
useSearchEffect("labels", (labels: string) => {
setReviewFilter({
...reviewFilter,
labels: labels.includes(",") ? labels.split(",") : [labels],
});
return true;
});
useSearchEffect("zones", (zones: string) => {
setReviewFilter({
...reviewFilter,
zones: zones.includes(",") ? zones.split(",") : [zones],
});
return true;
});
useSearchEffect("group", (reviewGroup) => { useSearchEffect("group", (reviewGroup) => {
if (config && reviewGroup && reviewGroup != "default") { if (config && reviewGroup && reviewGroup != "default") {