Skip to content

Commit

Permalink
Fix calendar selection (#11959)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Jun 14, 2024
1 parent 2934c78 commit b49cda2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 16 additions & 2 deletions web/src/components/overlay/ReviewActivityCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
});

Expand Down
2 changes: 2 additions & 0 deletions web/src/types/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export type FilterList = {
labels?: string[];
zones?: string[];
};

export const LAST_24_HOURS_KEY = "last24Hours";
4 changes: 2 additions & 2 deletions web/src/views/events/EventView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)}`;
Expand Down

0 comments on commit b49cda2

Please sign in to comment.