mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-14 02:52:11 +03:00
Improve handling of label types
This commit is contained in:
parent
88c2376fe4
commit
5b9b138035
@ -150,7 +150,7 @@ export default function SearchThumbnail({
|
|||||||
.filter(
|
.filter(
|
||||||
(item) => item !== undefined && !item.includes("-verified"),
|
(item) => item !== undefined && !item.includes("-verified"),
|
||||||
)
|
)
|
||||||
.map((text) => getTranslatedLabel(text))
|
.map((text) => getTranslatedLabel(text, searchResult.data.type))
|
||||||
.sort()
|
.sort()
|
||||||
.join(", ")
|
.join(", ")
|
||||||
.replaceAll("-verified", "")}
|
.replaceAll("-verified", "")}
|
||||||
|
|||||||
@ -29,6 +29,8 @@ export type SearchSortType =
|
|||||||
| "score_desc"
|
| "score_desc"
|
||||||
| "relevance";
|
| "relevance";
|
||||||
|
|
||||||
|
export type EventType = "object" | "audio" | "manual";
|
||||||
|
|
||||||
export type SearchResult = {
|
export type SearchResult = {
|
||||||
id: string;
|
id: string;
|
||||||
camera: string;
|
camera: string;
|
||||||
@ -54,7 +56,7 @@ export type SearchResult = {
|
|||||||
box: number[];
|
box: number[];
|
||||||
area: number;
|
area: number;
|
||||||
ratio: number;
|
ratio: number;
|
||||||
type: "object" | "audio" | "manual";
|
type: EventType;
|
||||||
description?: string;
|
description?: string;
|
||||||
average_estimated_speed: number;
|
average_estimated_speed: number;
|
||||||
velocity_angle: number;
|
velocity_angle: number;
|
||||||
|
|||||||
@ -1,10 +1,18 @@
|
|||||||
import i18n, { t } from "i18next";
|
import i18n, { t } from "i18next";
|
||||||
import { initReactI18next } from "react-i18next";
|
import { initReactI18next } from "react-i18next";
|
||||||
import HttpBackend from "i18next-http-backend";
|
import HttpBackend from "i18next-http-backend";
|
||||||
|
import { EventType } from "@/types/search";
|
||||||
|
|
||||||
export const getTranslatedLabel = (label: string) => {
|
export const getTranslatedLabel = (
|
||||||
|
label: string,
|
||||||
|
type: EventType = "object",
|
||||||
|
) => {
|
||||||
if (!label) return "";
|
if (!label) return "";
|
||||||
|
|
||||||
|
if (type === "manual") {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
const normalize = (s: string) =>
|
const normalize = (s: string) =>
|
||||||
s
|
s
|
||||||
.trim()
|
.trim()
|
||||||
@ -15,8 +23,9 @@ export const getTranslatedLabel = (label: string) => {
|
|||||||
|
|
||||||
const key = normalize(label);
|
const key = normalize(label);
|
||||||
|
|
||||||
if (i18n.exists(key, { ns: "objects" })) return t(key, { ns: "objects" });
|
if (type === "audio") {
|
||||||
if (i18n.exists(key, { ns: "audio" })) return t(key, { ns: "audio" });
|
return t(`audio.${key}`, { ns: "audio" });
|
||||||
|
}
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
return t(key, { ns: "objects" });
|
return t(key, { ns: "objects" });
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import {
|
|||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
||||||
import { SearchResult } from "@/types/search";
|
import { EventType, SearchResult } from "@/types/search";
|
||||||
import ImageLoadingIndicator from "@/components/indicators/ImageLoadingIndicator";
|
import ImageLoadingIndicator from "@/components/indicators/ImageLoadingIndicator";
|
||||||
import useImageLoaded from "@/hooks/use-image-loaded";
|
import useImageLoaded from "@/hooks/use-image-loaded";
|
||||||
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
||||||
@ -110,7 +110,8 @@ export default function ExploreView({
|
|||||||
key={label}
|
key={label}
|
||||||
searchResults={filteredEvents}
|
searchResults={filteredEvents}
|
||||||
isValidating={isValidating}
|
isValidating={isValidating}
|
||||||
objectType={label}
|
label={label}
|
||||||
|
labelType={filteredEvents[0]?.data?.type || "object"}
|
||||||
setSearchDetail={setSearchDetail}
|
setSearchDetail={setSearchDetail}
|
||||||
mutate={mutate}
|
mutate={mutate}
|
||||||
setSimilaritySearch={setSimilaritySearch}
|
setSimilaritySearch={setSimilaritySearch}
|
||||||
@ -122,7 +123,8 @@ export default function ExploreView({
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ThumbnailRowType = {
|
type ThumbnailRowType = {
|
||||||
objectType: string;
|
label: string;
|
||||||
|
labelType: EventType;
|
||||||
searchResults?: SearchResult[];
|
searchResults?: SearchResult[];
|
||||||
isValidating: boolean;
|
isValidating: boolean;
|
||||||
setSearchDetail: (search: SearchResult | undefined) => void;
|
setSearchDetail: (search: SearchResult | undefined) => void;
|
||||||
@ -132,7 +134,8 @@ type ThumbnailRowType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function ThumbnailRow({
|
function ThumbnailRow({
|
||||||
objectType,
|
label,
|
||||||
|
labelType,
|
||||||
searchResults,
|
searchResults,
|
||||||
isValidating,
|
isValidating,
|
||||||
setSearchDetail,
|
setSearchDetail,
|
||||||
@ -153,7 +156,7 @@ function ThumbnailRow({
|
|||||||
return (
|
return (
|
||||||
<div className="rounded-lg bg-background_alt p-2 md:px-4">
|
<div className="rounded-lg bg-background_alt p-2 md:px-4">
|
||||||
<div className="flex flex-row items-center text-lg smart-capitalize">
|
<div className="flex flex-row items-center text-lg smart-capitalize">
|
||||||
{getTranslatedLabel(objectType)}
|
{getTranslatedLabel(label, labelType)}
|
||||||
{searchResults && (
|
{searchResults && (
|
||||||
<span className="ml-3 text-sm text-secondary-foreground">
|
<span className="ml-3 text-sm text-secondary-foreground">
|
||||||
{t("trackedObjectsCount", {
|
{t("trackedObjectsCount", {
|
||||||
|
|||||||
@ -100,7 +100,12 @@ export default function CameraSettingsView({
|
|||||||
const alertsLabels = useMemo(() => {
|
const alertsLabels = useMemo(() => {
|
||||||
return cameraConfig?.review.alerts.labels
|
return cameraConfig?.review.alerts.labels
|
||||||
? cameraConfig.review.alerts.labels
|
? cameraConfig.review.alerts.labels
|
||||||
.map((label) => getTranslatedLabel(label))
|
.map((label) =>
|
||||||
|
getTranslatedLabel(
|
||||||
|
label,
|
||||||
|
cameraConfig?.audio?.listen?.includes(label) ? "audio" : "object",
|
||||||
|
),
|
||||||
|
)
|
||||||
.join(", ")
|
.join(", ")
|
||||||
: "";
|
: "";
|
||||||
}, [cameraConfig]);
|
}, [cameraConfig]);
|
||||||
@ -108,7 +113,12 @@ export default function CameraSettingsView({
|
|||||||
const detectionsLabels = useMemo(() => {
|
const detectionsLabels = useMemo(() => {
|
||||||
return cameraConfig?.review.detections.labels
|
return cameraConfig?.review.detections.labels
|
||||||
? cameraConfig.review.detections.labels
|
? cameraConfig.review.detections.labels
|
||||||
.map((label) => getTranslatedLabel(label))
|
.map((label) =>
|
||||||
|
getTranslatedLabel(
|
||||||
|
label,
|
||||||
|
cameraConfig?.audio?.listen?.includes(label) ? "audio" : "object",
|
||||||
|
),
|
||||||
|
)
|
||||||
.join(", ")
|
.join(", ")
|
||||||
: "";
|
: "";
|
||||||
}, [cameraConfig]);
|
}, [cameraConfig]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user