mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-09-19 17:51:34 +02:00
Fixes (#19406)
* Fix api filter hook cameras, labels, sub labels, plates, and zones could be parsed as numeric values rather than strings, which would break the explore filter. This change adds an optional param to the useApiFilterArgs hook to always parse keys as string[] * fix notifications register button from being incorrectly disabled
This commit is contained in:
parent
5fc030c3f6
commit
b6b3178e3d
@ -47,9 +47,9 @@ export default function useApiFilter<
|
||||
return [filter, setFilter, searchParams];
|
||||
}
|
||||
|
||||
export function useApiFilterArgs<
|
||||
F extends FilterType,
|
||||
>(): useApiFilterReturn<F> {
|
||||
export function useApiFilterArgs<F extends FilterType>(
|
||||
arrayKeys: string[],
|
||||
): useApiFilterReturn<F> {
|
||||
const [rawParams, setRawParams] = useSearchParams();
|
||||
|
||||
const setFilter = useCallback(
|
||||
@ -64,7 +64,13 @@ export function useApiFilterArgs<
|
||||
|
||||
const filter: { [key: string]: unknown } = {};
|
||||
|
||||
// always treat these keys as string[], not as a number or event id
|
||||
const arrayKeySet = new Set(arrayKeys);
|
||||
|
||||
rawParams.forEach((value, key) => {
|
||||
if (arrayKeySet.has(key)) {
|
||||
filter[key] = value.includes(",") ? value.split(",") : [value];
|
||||
} else {
|
||||
const isValidNumber = /^-?\d+(\.\d+)?(?!.)/.test(value);
|
||||
const isValidEventID = /^\d+\.\d+-[a-zA-Z0-9]+$/.test(value);
|
||||
|
||||
@ -84,10 +90,11 @@ export function useApiFilterArgs<
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return filter as F;
|
||||
}, [rawParams]);
|
||||
}, [rawParams, arrayKeys]);
|
||||
|
||||
const searchParams = useMemo(() => {
|
||||
if (filter == undefined || Object.keys(filter).length == 0) {
|
||||
|
@ -58,7 +58,13 @@ export default function Explore() {
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
const [searchFilter, setSearchFilter, searchSearchParams] =
|
||||
useApiFilterArgs<SearchFilter>();
|
||||
useApiFilterArgs<SearchFilter>([
|
||||
"cameras",
|
||||
"labels",
|
||||
"sub_labels",
|
||||
"recognized_license_plate",
|
||||
"zones",
|
||||
]);
|
||||
|
||||
const searchTerm = useMemo(
|
||||
() => searchSearchParams?.["query"] || "",
|
||||
|
@ -523,7 +523,9 @@ export default function NotificationView({
|
||||
aria-label={t("notification.registerDevice")}
|
||||
disabled={
|
||||
(!config?.notifications.enabled &&
|
||||
notificationCameras.length === 0) ||
|
||||
notificationCameras.length === 0 &&
|
||||
!form.watch("allEnabled") &&
|
||||
form.watch("cameras").length === 0) ||
|
||||
publicKey == undefined
|
||||
}
|
||||
onClick={() => {
|
||||
|
Loading…
Reference in New Issue
Block a user