* scroll minimap to keep it in view

* remove console log

* change ref

* rebase to dev

* rebase to dev

* rebase to dev

* fix history flexbox and live extra scrollbar

* remove extra class
This commit is contained in:
Josh Hawkins
2024-02-22 21:15:50 -06:00
committed by GitHub
parent f84d2db406
commit a6aa5328aa
5 changed files with 204 additions and 139 deletions

View File

@@ -61,7 +61,8 @@ function eventsToScrubberItems(events: Event[]): ScrubberItem[] {
}
const generateRandomEvent = (): ReviewSegment => {
const start_time = Math.floor(Date.now() / 1000) - Math.random() * 60 * 60;
const start_time =
Math.floor(Date.now() / 1000) - 10800 - Math.random() * 60 * 60;
const end_time = Math.floor(start_time + Math.random() * 60 * 10);
const severities: ReviewSeverity[] = [
"significant_motion",
@@ -123,6 +124,23 @@ function UIPlayground() {
setMockEvents(initialEvents);
}, []);
// Calculate minimap start and end times based on events
const minimapStartTime = useMemo(() => {
if (mockEvents && mockEvents.length > 0) {
return Math.min(...mockEvents.map((event) => event.start_time));
}
return Math.floor(Date.now() / 1000); // Default to current time if no events
}, [events]);
const minimapEndTime = useMemo(() => {
if (mockEvents && mockEvents.length > 0) {
return Math.max(
...mockEvents.map((event) => event.end_time ?? event.start_time)
);
}
return Math.floor(Date.now() / 1000); // Default to current time if no events
}, [events]);
const [zoomLevel, setZoomLevel] = useState(0);
const [zoomSettings, setZoomSettings] = useState({
segmentDuration: 60,
@@ -150,101 +168,114 @@ function UIPlayground() {
setZoomSettings(possibleZoomLevels[nextZoomLevel]);
}
const [isDragging, setIsDragging] = useState(false);
const handleDraggingChange = (dragging: boolean) => {
setIsDragging(dragging);
};
return (
<>
<Heading as="h2">UI Playground</Heading>
<div className="w-full h-full">
<div className="flex h-full">
<div className="flex-1 content-start gap-2 overflow-y-auto no-scrollbar mt-4 mr-5">
<Heading as="h2">UI Playground</Heading>
<Heading as="h4" className="my-5">
Scrubber
</Heading>
<p className="text-small">
Shows the 10 most recent events within the last 4 hours
</p>
{!config && <ActivityIndicator />}
{config && (
<div>
{events && events.length > 0 && (
<>
<ActivityScrubber
items={eventsToScrubberItems(events)}
selectHandler={onSelect}
/>
</>
)}
</div>
)}
{config && (
<div>
{timeline && (
<>
<TimelineScrubber eventID={timeline} />
</>
)}
</div>
)}
<div className="flex">
<div className="flex-grow">
<div ref={contentRef}>
<Heading as="h4" className="my-5">
Timeline
</Heading>
<p className="text-small">Handlebar timestamp: {handlebarTime}</p>
<p>
<Button onClick={handleZoomOut} disabled={zoomLevel === 0}>
Zoom Out
</Button>
<Button
onClick={handleZoomIn}
disabled={zoomLevel === possibleZoomLevels.length - 1}
>
Zoom In
</Button>
</p>
<Heading as="h4" className="my-5">
Color scheme
Scrubber
</Heading>
<p className="text-small">
Colors as set by the current theme. See the{" "}
<a
className="underline"
href="https://ui.shadcn.com/docs/theming"
>
shadcn theming docs
</a>{" "}
for usage.
Shows the 10 most recent events within the last 4 hours
</p>
<div className="my-5">
{colors.map((color, index) => (
<ColorSwatch
key={index}
name={color}
value={`hsl(var(--${color}))`}
/>
))}
{!config && <ActivityIndicator />}
{config && (
<div>
{events && events.length > 0 && (
<>
<ActivityScrubber
items={eventsToScrubberItems(events)}
selectHandler={onSelect}
/>
</>
)}
</div>
)}
{config && (
<div>
{timeline && (
<>
<TimelineScrubber eventID={timeline} />
</>
)}
</div>
)}
<div ref={contentRef}>
<Heading as="h4" className="my-5">
Timeline
</Heading>
<p className="text-small">Handlebar timestamp: {handlebarTime}</p>
<p className="text-small">
Handlebar is dragging: {isDragging ? "yes" : "no"}
</p>
<p>
<Button onClick={handleZoomOut} disabled={zoomLevel === 0}>
Zoom Out
</Button>
<Button
onClick={handleZoomIn}
disabled={zoomLevel === possibleZoomLevels.length - 1}
>
Zoom In
</Button>
</p>
<Heading as="h4" className="my-5">
Color scheme
</Heading>
<p className="text-small">
Colors as set by the current theme. See the{" "}
<a
className="underline"
href="https://ui.shadcn.com/docs/theming"
>
shadcn theming docs
</a>{" "}
for usage.
</p>
<div className="my-5">
{colors.map((color, index) => (
<ColorSwatch
key={index}
name={color}
value={`hsl(var(--${color}))`}
/>
))}
</div>
</div>
</div>
</div>
<div className="flex-none">
<EventReviewTimeline
segmentDuration={zoomSettings.segmentDuration} // seconds per segment
timestampSpread={zoomSettings.timestampSpread} // minutes between each major timestamp
timelineStart={Math.floor(Date.now() / 1000)} // timestamp start of the timeline - the earlier time
timelineEnd={Math.floor(Date.now() / 1000) - 6 * 60 * 60} // end of timeline - the later time
showHandlebar // show / hide the handlebar
handlebarTime={handlebarTime} // set the time of the handlebar
setHandlebarTime={setHandlebarTime} // expose handler to set the handlebar time
showMinimap // show / hide the minimap
minimapStartTime={Math.floor(Date.now() / 1000) - 35 * 60} // start time of the minimap - the earlier time (eg 1:00pm)
minimapEndTime={Math.floor(Date.now() / 1000) - 21 * 60} // end of the minimap - the later time (eg 3:00pm)
events={mockEvents} // events, including new has_been_reviewed and severity properties
severityType={"alert"} // choose the severity type for the middle line - all other severity types are to the right
contentRef={contentRef} // optional content ref where previews are, can be used for observing/scrolling later
/>
<div className="w-[100px] overflow-y-auto no-scrollbar">
<EventReviewTimeline
segmentDuration={zoomSettings.segmentDuration} // seconds per segment
timestampSpread={zoomSettings.timestampSpread} // minutes between each major timestamp
timelineStart={Math.floor(Date.now() / 1000)} // timestamp start of the timeline - the earlier time
timelineEnd={Math.floor(Date.now() / 1000) - 6 * 60 * 60} // end of timeline - the later time
showHandlebar // show / hide the handlebar
handlebarTime={handlebarTime} // set the time of the handlebar
setHandlebarTime={setHandlebarTime} // expose handler to set the handlebar time
onHandlebarDraggingChange={handleDraggingChange} // function for state of handlebar dragging
showMinimap // show / hide the minimap
minimapStartTime={minimapStartTime} // start time of the minimap - the earlier time (eg 1:00pm)
minimapEndTime={minimapEndTime} // end of the minimap - the later time (eg 3:00pm)
events={mockEvents} // events, including new has_been_reviewed and severity properties
severityType={"alert"} // choose the severity type for the middle line - all other severity types are to the right
contentRef={contentRef} // optional content ref where previews are, can be used for observing/scrolling later
/>
</div>
</div>
</div>
</>