Fix calendar selection (#11959)

This commit is contained in:
Nicolas Mowen 2024-06-14 12:14:32 -05:00 committed by GitHub
parent 2934c7817d
commit b49cda274d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import { useMemo } from "react";
import { FaCircle } from "react-icons/fa";
import { getUTCOffset } from "@/utils/dateUtil";
import { type DayContentProps } from "react-day-picker";
import { LAST_24_HOURS_KEY } from "@/types/filter";
type ReviewActivityCalendarProps = {
reviewSummary?: ReviewSummary;
@ -32,10 +33,23 @@ export default function ReviewActivityCalendar({
const unreviewedAlerts: Date[] = [];
Object.entries(reviewSummary).forEach(([date, data]) => {
if (date == LAST_24_HOURS_KEY) {
return;
}
const parts = date.split("-");
const cal = new Date(date);
cal.setFullYear(
parseInt(parts[0]),
parseInt(parts[1]) - 1,
parseInt(parts[2]),
);
if (data.total_alert > data.reviewed_alert) {
unreviewedAlerts.push(new Date(date));
unreviewedAlerts.push(cal);
} else if (data.total_detection > data.reviewed_detection) {
unreviewedDetections.push(new Date(date));
unreviewedDetections.push(cal);
}
});

View File

@ -8,3 +8,5 @@ export type FilterList = {
labels?: string[];
zones?: string[];
};
export const LAST_24_HOURS_KEY = "last24Hours";

View File

@ -49,7 +49,7 @@ import scrollIntoView from "scroll-into-view-if-needed";
import { Toaster } from "@/components/ui/sonner";
import { toast } from "sonner";
import { cn } from "@/lib/utils";
import { FilterList } from "@/types/filter";
import { FilterList, LAST_24_HOURS_KEY } from "@/types/filter";
import { GiSoundWaves } from "react-icons/gi";
type EventViewProps = {
@ -96,7 +96,7 @@ export default function EventView({
let summary;
if (filter?.before == undefined) {
summary = reviewSummary["last24Hours"];
summary = reviewSummary[LAST_24_HOURS_KEY];
} else {
const day = new Date(filter.before * 1000);
const key = `${day.getFullYear()}-${("0" + (day.getMonth() + 1)).slice(-2)}-${("0" + day.getDate()).slice(-2)}`;