refactor: add friendly zone names to timeline entries and clean up unused code

This commit is contained in:
ZhaiSoul 2025-11-06 14:47:27 +00:00
parent 06e2fc0aa0
commit e6b448732d
3 changed files with 34 additions and 28 deletions

View File

@ -50,22 +50,23 @@ export function ObjectPath({
if (!imgRef.current || !positions) return []; if (!imgRef.current || !positions) return [];
const imgRect = imgRef.current.getBoundingClientRect(); const imgRect = imgRef.current.getBoundingClientRect();
return positions.map((pos) => { return positions.map((pos) => {
if (config && pos.lifecycle_item?.data?.zones) {
pos.lifecycle_item = {
...pos.lifecycle_item,
data: {
...pos.lifecycle_item.data,
zones_friendly_names: pos.lifecycle_item.data.zones.map((zone) => {
return resolveZoneName(config, zone);
}),
},
};
}
return { return {
x: pos.x * imgRect.width, x: pos.x * imgRect.width,
y: pos.y * imgRect.height, y: pos.y * imgRect.height,
timestamp: pos.timestamp, timestamp: pos.timestamp,
lifecycle_item: pos.lifecycle_item, lifecycle_item: pos.lifecycle_item?.data?.zones
? {
...pos.lifecycle_item,
data: {
...pos.lifecycle_item?.data,
zones_friendly_names: pos.lifecycle_item?.data.zones.map(
(zone) => {
return resolveZoneName(config, zone);
},
),
},
}
: pos.lifecycle_item,
}; };
}); });
}, [imgRef, positions, config]); }, [imgRef, positions, config]);

View File

@ -269,6 +269,10 @@ export function PolygonCanvas({
const updatedPolygons = [...polygons]; const updatedPolygons = [...polygons];
const activePolygon = updatedPolygons[activePolygonIndex]; const activePolygon = updatedPolygons[activePolygonIndex];
if (!activePolygon) {
return;
}
// add default points order for already completed polygons // add default points order for already completed polygons
if (!activePolygon.pointsOrder && activePolygon.isFinished) { if (!activePolygon.pointsOrder && activePolygon.isFinished) {
updatedPolygons[activePolygonIndex] = { updatedPolygons[activePolygonIndex] = {

View File

@ -655,16 +655,6 @@ function LifecycleItem({
const { t } = useTranslation("views/events"); const { t } = useTranslation("views/events");
const { data: config } = useSWR<FrigateConfig>("config"); const { data: config } = useSWR<FrigateConfig>("config");
item = {
...item,
data: {
...item.data,
zones_friendly_names: item?.data?.zones?.map((zone) => {
return resolveZoneName(config, zone);
}),
},
};
const aspectRatio = useMemo(() => { const aspectRatio = useMemo(() => {
if (!config || !item?.camera) { if (!config || !item?.camera) {
return 16 / 9; return 16 / 9;
@ -806,17 +796,28 @@ function ObjectTimeline({
}, },
]); ]);
const { data: config } = useSWR<FrigateConfig>("config");
const timeline = useMemo(() => { const timeline = useMemo(() => {
if (!fullTimeline) { if (!fullTimeline) {
return fullTimeline; return fullTimeline;
} }
return fullTimeline.filter( return fullTimeline
(t) => .filter(
t.timestamp >= review.start_time && (t) =>
(review.end_time == undefined || t.timestamp <= review.end_time), t.timestamp >= review.start_time &&
); (review.end_time == undefined || t.timestamp <= review.end_time),
}, [fullTimeline, review]); )
.map((event) => ({
...event,
data: {
...event.data,
zones_friendly_names: event.data?.zones?.map((zone) =>
resolveZoneName(config, zone),
),
},
}));
}, [config, fullTimeline, review]);
if (isValidating && (!timeline || timeline.length === 0)) { if (isValidating && (!timeline || timeline.length === 0)) {
return <ActivityIndicator className="ml-2 size-3" />; return <ActivityIndicator className="ml-2 size-3" />;