From 6a74418c7a2da83752c8d4abb752718937d45db2 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 5 Apr 2024 11:00:51 -0600 Subject: [PATCH] Add toast and filtering --- web/src/components/filter/LogLevelFilter.tsx | 126 ++++++++++++++++++ .../components/filter/ReviewFilterGroup.tsx | 4 +- web/src/pages/Logs.tsx | 38 ++++-- 3 files changed, 156 insertions(+), 12 deletions(-) create mode 100644 web/src/components/filter/LogLevelFilter.tsx diff --git a/web/src/components/filter/LogLevelFilter.tsx b/web/src/components/filter/LogLevelFilter.tsx new file mode 100644 index 000000000..13a0b069e --- /dev/null +++ b/web/src/components/filter/LogLevelFilter.tsx @@ -0,0 +1,126 @@ +import { Button } from "../ui/button"; +import { FaFilter } from "react-icons/fa"; +import { isMobile } from "react-device-detect"; +import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer"; +import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; +import { LogSeverity } from "@/types/log"; +import { Label } from "../ui/label"; +import { Switch } from "../ui/switch"; +import { DropdownMenuSeparator } from "../ui/dropdown-menu"; + +type LogLevelFilterButtonProps = { + selectedLabels?: LogSeverity[]; + updateLabelFilter: (labels: LogSeverity[] | undefined) => void; +}; +export function LogLevelFilterButton({ + selectedLabels, + updateLabelFilter, +}: LogLevelFilterButtonProps) { + const trigger = ( + + ); + const content = ( + + ); + + if (isMobile) { + return ( + + {trigger} + + {content} + + + ); + } + + return ( + + {trigger} + {content} + + ); +} + +type GeneralFilterContentProps = { + selectedLabels: LogSeverity[] | undefined; + updateLabelFilter: (labels: LogSeverity[] | undefined) => void; +}; +export function GeneralFilterContent({ + selectedLabels, + updateLabelFilter, +}: GeneralFilterContentProps) { + return ( + <> +
+
+ + { + if (isChecked) { + updateLabelFilter(undefined); + } + }} + /> +
+ +
+ {["debug", "info", "warning", "error"].map((item) => ( +
+ + { + if (isChecked) { + const updatedLabels = selectedLabels + ? [...selectedLabels] + : []; + + updatedLabels.push(item as LogSeverity); + updateLabelFilter(updatedLabels); + } else { + const updatedLabels = selectedLabels + ? [...selectedLabels] + : []; + + // can not deselect the last item + if (updatedLabels.length > 1) { + updatedLabels.splice( + updatedLabels.indexOf(item as LogSeverity), + 1, + ); + updateLabelFilter(updatedLabels); + } + } + }} + /> +
+ ))} +
+
+ + + ); +} diff --git a/web/src/components/filter/ReviewFilterGroup.tsx b/web/src/components/filter/ReviewFilterGroup.tsx index a3c3fadbc..91e390847 100644 --- a/web/src/components/filter/ReviewFilterGroup.tsx +++ b/web/src/components/filter/ReviewFilterGroup.tsx @@ -567,7 +567,7 @@ export function GeneralFilterContent({ {allLabels.map((item) => (