Indicate on calendar which days have unreviewed activity (#10381)

This commit is contained in:
Nicolas Mowen 2024-03-11 09:14:41 -06:00 committed by GitHub
parent 3515361320
commit 8d4b9bc7ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 95 additions and 19 deletions

View File

@ -10,8 +10,7 @@ import {
DropdownMenuSeparator, DropdownMenuSeparator,
DropdownMenuTrigger, DropdownMenuTrigger,
} from "../ui/dropdown-menu"; } from "../ui/dropdown-menu";
import { Calendar } from "../ui/calendar"; import { ReviewFilter, ReviewSummary } from "@/types/review";
import { ReviewFilter } from "@/types/review";
import { getEndOfDayTimestamp } from "@/utils/dateUtil"; import { getEndOfDayTimestamp } from "@/utils/dateUtil";
import { useFormattedTimestamp } from "@/hooks/use-date-utils"; import { useFormattedTimestamp } from "@/hooks/use-date-utils";
import { FaCalendarAlt, FaFilter, FaVideo } from "react-icons/fa"; import { FaCalendarAlt, FaFilter, FaVideo } from "react-icons/fa";
@ -20,15 +19,18 @@ import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer";
import { Switch } from "../ui/switch"; import { Switch } from "../ui/switch";
import { Label } from "../ui/label"; import { Label } from "../ui/label";
import FilterCheckBox from "./FilterCheckBox"; import FilterCheckBox from "./FilterCheckBox";
import ReviewActivityCalendar from "../overlay/ReviewActivityCalendar";
const ATTRIBUTES = ["amazon", "face", "fedex", "license_plate", "ups"]; const ATTRIBUTES = ["amazon", "face", "fedex", "license_plate", "ups"];
type ReviewFilterGroupProps = { type ReviewFilterGroupProps = {
reviewSummary?: ReviewSummary;
filter?: ReviewFilter; filter?: ReviewFilter;
onUpdateFilter: (filter: ReviewFilter) => void; onUpdateFilter: (filter: ReviewFilter) => void;
}; };
export default function ReviewFilterGroup({ export default function ReviewFilterGroup({
reviewSummary,
filter, filter,
onUpdateFilter, onUpdateFilter,
}: ReviewFilterGroupProps) { }: ReviewFilterGroupProps) {
@ -102,6 +104,7 @@ export default function ReviewFilterGroup({
}} }}
/> />
<CalendarFilterButton <CalendarFilterButton
reviewSummary={reviewSummary}
day={ day={
filter?.after == undefined ? undefined : new Date(filter.after * 1000) filter?.after == undefined ? undefined : new Date(filter.after * 1000)
} }
@ -273,22 +276,17 @@ function CamerasFilterButton({
} }
type CalendarFilterButtonProps = { type CalendarFilterButtonProps = {
reviewSummary?: ReviewSummary;
day?: Date; day?: Date;
updateSelectedDay: (day?: Date) => void; updateSelectedDay: (day?: Date) => void;
}; };
function CalendarFilterButton({ function CalendarFilterButton({
reviewSummary,
day, day,
updateSelectedDay, updateSelectedDay,
}: CalendarFilterButtonProps) { }: CalendarFilterButtonProps) {
const disabledDates = useMemo(() => {
const tomorrow = new Date();
tomorrow.setHours(tomorrow.getHours() + 24, -1, 0, 0);
const future = new Date();
future.setFullYear(tomorrow.getFullYear() + 10);
return { from: tomorrow, to: future };
}, []);
const selectedDate = useFormattedTimestamp( const selectedDate = useFormattedTimestamp(
day == undefined ? 0 : day?.getTime() / 1000, day == undefined ? 0 : day?.getTime() / 1000 + 1,
"%b %-d", "%b %-d",
); );
@ -302,14 +300,10 @@ function CalendarFilterButton({
); );
const content = ( const content = (
<> <>
<Calendar <ReviewActivityCalendar
mode="single" reviewSummary={reviewSummary}
disabled={disabledDates} selectedDay={day}
selected={day} onSelect={updateSelectedDay}
showOutsideDays={false}
onSelect={(day) => {
updateSelectedDay(day);
}}
/> />
<DropdownMenuSeparator /> <DropdownMenuSeparator />
<div className="p-2 flex justify-center items-center"> <div className="p-2 flex justify-center items-center">

View File

@ -0,0 +1,78 @@
import { ReviewSummary } from "@/types/review";
import { Calendar } from "../ui/calendar";
import { useMemo } from "react";
import { FaCircle } from "react-icons/fa";
type ReviewActivityCalendarProps = {
reviewSummary?: ReviewSummary;
selectedDay?: Date;
onSelect: (day?: Date) => void;
};
export default function ReviewActivityCalendar({
reviewSummary,
selectedDay,
onSelect,
}: ReviewActivityCalendarProps) {
const disabledDates = useMemo(() => {
const tomorrow = new Date();
tomorrow.setHours(tomorrow.getHours() + 24, -1, 0, 0);
const future = new Date();
future.setFullYear(tomorrow.getFullYear() + 10);
return { from: tomorrow, to: future };
}, []);
return (
<Calendar
mode="single"
disabled={disabledDates}
showOutsideDays={false}
selected={selectedDay}
onSelect={onSelect}
components={{
DayContent: (date) => (
<ReviewActivityDay reviewSummary={reviewSummary} day={date.date} />
),
}}
/>
);
}
type ReviewActivityDayProps = {
reviewSummary?: ReviewSummary;
day: Date;
};
function ReviewActivityDay({ reviewSummary, day }: ReviewActivityDayProps) {
const dayActivity = useMemo(() => {
if (!reviewSummary) {
return "none";
}
const allActivity =
reviewSummary[
`${day.getFullYear()}-${("0" + (day.getMonth() + 1)).slice(-2)}-${("0" + day.getDate()).slice(-2)}`
];
if (!allActivity) {
return "none";
}
if (allActivity.total_alert > allActivity.reviewed_alert) {
return "alert";
} else if (allActivity.total_detection > allActivity.reviewed_detection) {
return "detection";
} else {
return "none";
}
}, [reviewSummary, day]);
return (
<div className="flex flex-col justify-center items-center">
{day.getDate()}
{dayActivity != "none" && (
<FaCircle
className={`size-2 ${dayActivity == "alert" ? "fill-severity_alert" : "fill-severity_detection"}`}
/>
)}
</div>
);
}

View File

@ -238,7 +238,11 @@ export default function EventView({
</ToggleGroup> </ToggleGroup>
{selectedReviews.length <= 0 ? ( {selectedReviews.length <= 0 ? (
<ReviewFilterGroup filter={filter} onUpdateFilter={updateFilter} /> <ReviewFilterGroup
reviewSummary={reviewSummary}
filter={filter}
onUpdateFilter={updateFilter}
/>
) : ( ) : (
<ReviewActionGroup <ReviewActionGroup
selectedReviews={selectedReviews} selectedReviews={selectedReviews}