Review timeline improvements (#10102)

* make event bars clickable

* outline and scroll when segment is clicked

* match outline colors to event type

* hover thumbnails

* make event bars clickable

* outline and scroll when segment is clicked

* match outline colors to event type

* hover thumbnails

* fix merge from rebase

* remove minimap opacity classes

* live player outline colors

* safelist shadow classes
This commit is contained in:
Josh Hawkins 2024-02-27 13:41:26 -06:00 committed by GitHub
parent 8663fbba01
commit 622e9741c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 203 additions and 73 deletions

View File

@ -126,7 +126,7 @@ export default function LivePlayer({
<div <div
className={`relative flex justify-center w-full outline ${ className={`relative flex justify-center w-full outline ${
activeTracking activeTracking
? "outline-destructive outline-1 rounded-2xl shadow-[0_0_6px_1px] shadow-destructive" ? "outline-severity_alert outline-1 rounded-2xl shadow-[0_0_6px_1px] shadow-severity_alert"
: "outline-0" : "outline-0"
} transition-all duration-500 ${className}`} } transition-all duration-500 ${className}`}
> >

View File

@ -10,6 +10,7 @@ import {
import EventSegment from "./EventSegment"; import EventSegment from "./EventSegment";
import { useEventUtils } from "@/hooks/use-event-utils"; import { useEventUtils } from "@/hooks/use-event-utils";
import { ReviewSegment, ReviewSeverity } from "@/types/review"; import { ReviewSegment, ReviewSeverity } from "@/types/review";
import { TooltipProvider } from "../ui/tooltip";
export type EventReviewTimelineProps = { export type EventReviewTimelineProps = {
segmentDuration: number; segmentDuration: number;
@ -102,7 +103,7 @@ export function EventReviewTimeline({
return ( return (
<EventSegment <EventSegment
key={segmentTime} key={segmentTime + severityType}
events={events} events={events}
segmentDuration={segmentDuration} segmentDuration={segmentDuration}
segmentTime={segmentTime} segmentTime={segmentTime}
@ -111,6 +112,7 @@ export function EventReviewTimeline({
minimapStartTime={minimapStartTime} minimapStartTime={minimapStartTime}
minimapEndTime={minimapEndTime} minimapEndTime={minimapEndTime}
severityType={severityType} severityType={severityType}
contentRef={contentRef}
/> />
); );
}); });
@ -122,6 +124,7 @@ export function EventReviewTimeline({
showMinimap, showMinimap,
minimapStartTime, minimapStartTime,
minimapEndTime, minimapEndTime,
events,
]); ]);
const segments = useMemo( const segments = useMemo(
@ -210,6 +213,7 @@ export function EventReviewTimeline({
]); ]);
return ( return (
<TooltipProvider skipDelayDuration={3000}>
<div <div
ref={timelineRef} ref={timelineRef}
className={`relative w-[120px] md:w-[100px] h-full overflow-y-scroll no-scrollbar bg-secondary ${ className={`relative w-[120px] md:w-[100px] h-full overflow-y-scroll no-scrollbar bg-secondary ${
@ -218,7 +222,10 @@ export function EventReviewTimeline({
> >
<div className="flex flex-col">{segments}</div> <div className="flex flex-col">{segments}</div>
{showHandlebar && ( {showHandlebar && (
<div className={`absolute left-0 top-0 z-20 w-full `} role="scrollbar"> <div
className={`absolute left-0 top-0 z-20 w-full `}
role="scrollbar"
>
<div className={`flex items-center justify-center `}> <div className={`flex items-center justify-center `}>
<div <div
ref={scrollTimeRef} ref={scrollTimeRef}
@ -243,6 +250,7 @@ export function EventReviewTimeline({
</div> </div>
)} )}
</div> </div>
</TooltipProvider>
); );
} }

View File

@ -1,7 +1,16 @@
import { useApiHost } from "@/api";
import { useEventUtils } from "@/hooks/use-event-utils"; import { useEventUtils } from "@/hooks/use-event-utils";
import { useSegmentUtils } from "@/hooks/use-segment-utils"; import { useSegmentUtils } from "@/hooks/use-segment-utils";
import { ReviewSegment, ReviewSeverity } from "@/types/review"; import { ReviewSegment, ReviewSeverity } from "@/types/review";
import React, { useEffect, useMemo, useRef } from "react"; import React, {
RefObject,
useCallback,
useEffect,
useMemo,
useRef,
} from "react";
import { Tooltip, TooltipContent } from "../ui/tooltip";
import { TooltipTrigger } from "@radix-ui/react-tooltip";
type EventSegmentProps = { type EventSegmentProps = {
events: ReviewSegment[]; events: ReviewSegment[];
@ -12,6 +21,7 @@ type EventSegmentProps = {
minimapStartTime?: number; minimapStartTime?: number;
minimapEndTime?: number; minimapEndTime?: number;
severityType: ReviewSeverity; severityType: ReviewSeverity;
contentRef: RefObject<HTMLDivElement>;
}; };
type MinimapSegmentProps = { type MinimapSegmentProps = {
@ -131,12 +141,15 @@ export function EventSegment({
minimapStartTime, minimapStartTime,
minimapEndTime, minimapEndTime,
severityType, severityType,
contentRef,
}: EventSegmentProps) { }: EventSegmentProps) {
const { const {
getSeverity, getSeverity,
getReviewed, getReviewed,
displaySeverityType, displaySeverityType,
shouldShowRoundedCorners, shouldShowRoundedCorners,
getEventStart,
getEventThumbnail,
} = useSegmentUtils(segmentDuration, events, severityType); } = useSegmentUtils(segmentDuration, events, severityType);
const { alignDateToTimeline } = useEventUtils(events, segmentDuration); const { alignDateToTimeline } = useEventUtils(events, segmentDuration);
@ -145,15 +158,35 @@ export function EventSegment({
() => getSeverity(segmentTime, displaySeverityType), () => getSeverity(segmentTime, displaySeverityType),
[getSeverity, segmentTime] [getSeverity, segmentTime]
); );
const reviewed = useMemo( const reviewed = useMemo(
() => getReviewed(segmentTime), () => getReviewed(segmentTime),
[getReviewed, segmentTime] [getReviewed, segmentTime]
); );
const { roundTop, roundBottom } = useMemo(
const {
roundTopPrimary,
roundBottomPrimary,
roundTopSecondary,
roundBottomSecondary,
} = useMemo(
() => shouldShowRoundedCorners(segmentTime), () => shouldShowRoundedCorners(segmentTime),
[shouldShowRoundedCorners, segmentTime] [shouldShowRoundedCorners, segmentTime]
); );
const startTimestamp = useMemo(() => {
const eventStart = getEventStart(segmentTime);
if (eventStart) {
return alignDateToTimeline(eventStart);
}
}, [getEventStart, segmentTime]);
const apiHost = useApiHost();
const eventThumbnail = useMemo(() => {
return getEventThumbnail(segmentTime);
}, [getEventThumbnail, segmentTime]);
const timestamp = useMemo(() => new Date(segmentTime * 1000), [segmentTime]); const timestamp = useMemo(() => new Date(segmentTime * 1000), [segmentTime]);
const segmentKey = useMemo(() => segmentTime, [segmentTime]); const segmentKey = useMemo(() => segmentTime, [segmentTime]);
@ -204,13 +237,7 @@ export function EventSegment({
}, [showMinimap, isFirstSegmentInMinimap, events, segmentDuration]); }, [showMinimap, isFirstSegmentInMinimap, events, segmentDuration]);
const segmentClasses = `flex flex-row ${ const segmentClasses = `flex flex-row ${
showMinimap showMinimap ? (isInMinimapRange ? "bg-muted" : "bg-background") : ""
? isInMinimapRange
? "bg-card"
: isLastSegmentInMinimap
? ""
: "opacity-70"
: ""
} ${ } ${
isFirstSegmentInMinimap || isLastSegmentInMinimap isFirstSegmentInMinimap || isLastSegmentInMinimap
? "relative h-2 border-b border-gray-500" ? "relative h-2 border-b border-gray-500"
@ -229,6 +256,29 @@ export function EventSegment({
: "from-severity_alert-dimmed to-severity_alert", : "from-severity_alert-dimmed to-severity_alert",
}; };
const segmentClick = useCallback(() => {
if (contentRef.current && startTimestamp) {
const element = contentRef.current.querySelector(
`[data-segment-start="${startTimestamp - segmentDuration}"]`
);
if (element instanceof HTMLElement) {
debounceScrollIntoView(element);
element.classList.add(
`outline-severity_${severityType}`,
`shadow-severity_${severityType}`
);
element.classList.add("outline-4", "shadow-[0_0_6px_1px]");
element.classList.remove("outline-0", "shadow-none");
// Remove the classes after a short timeout
setTimeout(() => {
element.classList.remove("outline-4", "shadow-[0_0_6px_1px]");
element.classList.add("outline-0", "shadow-none");
}, 3000);
}
}
}, [startTimestamp]);
return ( return (
<div key={segmentKey} className={segmentClasses}> <div key={segmentKey} className={segmentClasses}>
<MinimapBounds <MinimapBounds
@ -257,20 +307,31 @@ export function EventSegment({
{severity.map((severityValue, index) => ( {severity.map((severityValue, index) => (
<React.Fragment key={index}> <React.Fragment key={index}>
{severityValue === displaySeverityType && ( {severityValue === displaySeverityType && (
<Tooltip delayDuration={300}>
<div <div
className="mr-3 w-[8px] h-2 flex justify-left items-end" className="mr-3 w-[8px] h-2 flex justify-left items-end"
data-severity={severityValue} data-severity={severityValue}
> >
<TooltipTrigger asChild>
<div <div
key={`${segmentKey}_${index}_primary_data`} key={`${segmentKey}_${index}_primary_data`}
className={` className={`
w-full h-2 bg-gradient-to-r w-full h-2 bg-gradient-to-r
${roundBottom ? "rounded-bl-full rounded-br-full" : ""} ${roundBottomPrimary ? "rounded-bl-full rounded-br-full" : ""}
${roundTop ? "rounded-tl-full rounded-tr-full" : ""} ${roundTopPrimary ? "rounded-tl-full rounded-tr-full" : ""}
${severityColors[severityValue]} ${severityColors[severityValue]}
`} `}
onClick={segmentClick}
></div> ></div>
</TooltipTrigger>
<TooltipContent className="rounded-2xl" side="left">
<img
className="rounded-lg"
src={`${apiHost}${eventThumbnail.replace("/media/frigate/", "")}`}
/>
</TooltipContent>
</div> </div>
</Tooltip>
)} )}
{severityValue !== displaySeverityType && ( {severityValue !== displaySeverityType && (
@ -279,8 +340,8 @@ export function EventSegment({
key={`${segmentKey}_${index}_secondary_data`} key={`${segmentKey}_${index}_secondary_data`}
className={` className={`
w-1 h-2 bg-gradient-to-r w-1 h-2 bg-gradient-to-r
${roundBottom ? "rounded-bl-full rounded-br-full" : ""} ${roundBottomSecondary ? "rounded-bl-full rounded-br-full" : ""}
${roundTop ? "rounded-tl-full rounded-tr-full" : ""} ${roundTopSecondary ? "rounded-tl-full rounded-tr-full" : ""}
${severityColors[severityValue]} ${severityColors[severityValue]}
`} `}
></div> ></div>

View File

@ -84,7 +84,14 @@ export const useSegmentUtils = (
); );
const shouldShowRoundedCorners = useCallback( const shouldShowRoundedCorners = useCallback(
(segmentTime: number): { roundTop: boolean; roundBottom: boolean } => { (
segmentTime: number
): {
roundTopPrimary: boolean;
roundBottomPrimary: boolean;
roundTopSecondary: boolean;
roundBottomSecondary: boolean;
} => {
const prevSegmentTime = segmentTime - segmentDuration; const prevSegmentTime = segmentTime - segmentDuration;
const nextSegmentTime = segmentTime + segmentDuration; const nextSegmentTime = segmentTime + segmentDuration;
@ -134,28 +141,61 @@ export const useSegmentUtils = (
); );
}); });
let roundTop = false; let roundTopPrimary = false;
let roundBottom = false; let roundBottomPrimary = false;
let roundTopSecondary = false;
let roundBottomSecondary = false;
if (hasOverlappingSeverityEvent) { if (hasOverlappingSeverityEvent) {
roundBottom = !hasPrevSeverityEvent; roundBottomPrimary = !hasPrevSeverityEvent;
roundTop = !hasNextSeverityEvent; roundTopPrimary = !hasNextSeverityEvent;
} else if (hasOverlappingOtherEvent) { }
roundBottom = !hasPrevOtherEvent;
roundTop = !hasNextOtherEvent; if (hasOverlappingOtherEvent) {
} else { roundBottomSecondary = !hasPrevOtherEvent;
roundTop = !hasNextSeverityEvent || !hasNextOtherEvent; roundTopSecondary = !hasNextOtherEvent;
roundBottom = !hasPrevSeverityEvent || !hasPrevOtherEvent;
} }
return { return {
roundTop, roundTopPrimary,
roundBottom, roundBottomPrimary,
roundTopSecondary,
roundBottomSecondary,
}; };
}, },
[events, getSegmentStart, getSegmentEnd, segmentDuration, severityType] [events, getSegmentStart, getSegmentEnd, segmentDuration, severityType]
); );
const getEventStart = useCallback(
(time: number): number => {
const matchingEvent = events.find((event) => {
return (
time >= getSegmentStart(event.start_time) &&
time < getSegmentEnd(event.end_time) &&
event.severity == severityType
);
});
return matchingEvent?.start_time ?? 0;
},
[events, getSegmentStart, getSegmentEnd, severityType]
);
const getEventThumbnail = useCallback(
(time: number): string => {
const matchingEvent = events.find((event) => {
return (
time >= getSegmentStart(event.start_time) &&
time < getSegmentEnd(event.end_time) &&
event.severity == severityType
);
});
return matchingEvent?.thumb_path ?? "";
},
[events, getSegmentStart, getSegmentEnd, severityType]
);
return { return {
getSegmentStart, getSegmentStart,
getSegmentEnd, getSegmentEnd,
@ -163,5 +203,7 @@ export const useSegmentUtils = (
displaySeverityType, displaySeverityType,
getReviewed, getReviewed,
shouldShowRoundedCorners, shouldShowRoundedCorners,
getEventStart,
getEventThumbnail
}; };
}; };

View File

@ -4,6 +4,7 @@ import PreviewThumbnailPlayer from "@/components/player/PreviewThumbnailPlayer";
import EventReviewTimeline from "@/components/timeline/EventReviewTimeline"; import EventReviewTimeline from "@/components/timeline/EventReviewTimeline";
import ActivityIndicator from "@/components/ui/activity-indicator"; import ActivityIndicator from "@/components/ui/activity-indicator";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { useEventUtils } from "@/hooks/use-event-utils";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import { ReviewFilter, ReviewSegment, ReviewSeverity } from "@/types/review"; import { ReviewFilter, ReviewSegment, ReviewSeverity } from "@/types/review";
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@ -43,6 +44,7 @@ export default function DesktopEventView({
}: DesktopEventViewProps) { }: DesktopEventViewProps) {
const { data: config } = useSWR<FrigateConfig>("config"); const { data: config } = useSWR<FrigateConfig>("config");
const contentRef = useRef<HTMLDivElement | null>(null); const contentRef = useRef<HTMLDivElement | null>(null);
const segmentDuration = 60;
// review paging // review paging
@ -78,6 +80,11 @@ export default function DesktopEventView({
}; };
}, [reviewPages]); }, [reviewPages]);
const { alignDateToTimeline } = useEventUtils(
reviewItems.all,
segmentDuration
);
const currentItems = useMemo(() => { const currentItems = useMemo(() => {
const current = reviewItems[severity]; const current = reviewItems[severity];
@ -245,7 +252,10 @@ export default function DesktopEventView({
</div> </div>
)} )}
<div className="w-full mr-4 md:grid md:grid-cols-3 3xl:grid-cols-4 gap-4"> <div
className="w-full mx-2 my-2 md:grid md:grid-cols-3 3xl:grid-cols-4 gap-4"
ref={contentRef}
>
{currentItems ? ( {currentItems ? (
currentItems.map((value, segIdx) => { currentItems.map((value, segIdx) => {
const lastRow = segIdx == reviewItems[severity].length - 1; const lastRow = segIdx == reviewItems[severity].length - 1;
@ -263,6 +273,10 @@ export default function DesktopEventView({
key={value.id} key={value.id}
ref={lastRow ? lastReviewRef : minimapRef} ref={lastRow ? lastReviewRef : minimapRef}
data-start={value.start_time} data-start={value.start_time}
data-segment-start={
alignDateToTimeline(value.start_time) - segmentDuration
}
className="outline outline-offset-1 outline-0 rounded-lg shadow-none transition-all duration-500"
> >
<div className="aspect-video rounded-lg overflow-hidden"> <div className="aspect-video rounded-lg overflow-hidden">
<PreviewThumbnailPlayer <PreviewThumbnailPlayer
@ -281,9 +295,9 @@ export default function DesktopEventView({
)} )}
</div> </div>
</div> </div>
<div className="md:w-[100px] overflow-y-auto no-scrollbar"> <div className="md:w-[100px] mt-2 overflow-y-auto no-scrollbar">
<EventReviewTimeline <EventReviewTimeline
segmentDuration={60} segmentDuration={segmentDuration}
timestampSpread={15} timestampSpread={15}
timelineStart={timeRange.before} timelineStart={timeRange.before}
timelineEnd={timeRange.after} timelineEnd={timeRange.after}

View File

@ -7,6 +7,11 @@ module.exports = {
"./app/**/*.{ts,tsx}", "./app/**/*.{ts,tsx}",
"./src/**/*.{ts,tsx}", "./src/**/*.{ts,tsx}",
], ],
safelist: [
{
pattern: /(outline|shadow)-severity_(alert|detection|motion)/,
},
],
theme: { theme: {
container: { container: {
center: true, center: true,