From 1da5497c62aa8f2594aff59191a868b1b2b551ed Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Tue, 14 Nov 2023 18:12:48 +0300 Subject: [PATCH] fix: improve responsiveness of the canary UI --- src/components/Canary/index.tsx | 61 +++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/src/components/Canary/index.tsx b/src/components/Canary/index.tsx index 404ac4c6b..04744a242 100644 --- a/src/components/Canary/index.tsx +++ b/src/components/Canary/index.tsx @@ -35,6 +35,8 @@ import { separateLabelsByBooleanType } from "./labels"; import { decodeUrlSearchParams, useUpdateParams } from "./url"; +import { IconButton } from "../IconButton"; +import { FaFilter } from "react-icons/fa"; const FilterKeyToLabelMap = { environment: "Environment", @@ -74,6 +76,7 @@ export function Canary({ const tabBy = searchParams.get("tabBy"); const groupBy = searchParams.get("groupBy"); const refreshInterval = useRefreshRateFromLocalStorage(); + const [isMenuItemOpen, setIsMenuItemOpen] = useState(false); const [isLoading, setIsLoading] = useState(true); @@ -217,10 +220,15 @@ export function Canary({
- +
-
+
+
+ { + setIsMenuItemOpen((prev) => !prev); + }} + title="filter" + icon={} + /> +
handleSearch(e.target.value)} @@ -630,20 +647,52 @@ type SidebarStickyProps = { className?: string; style?: React.CSSProperties; children?: React.ReactNode; + isMenuItemOpen?: boolean; + setMenuItemOpen?: (isOpen: boolean) => void; }; function SidebarSticky({ className, style, children, + isMenuItemOpen = false, + setMenuItemOpen = () => {}, ...props }: SidebarStickyProps) { + const ref = useRef(null); + + useEffect(() => { + function handleClickOutside(event: any) { + if (ref.current && !ref.current.contains(event.target)) { + setMenuItemOpen(false); + } + } + + function keyPress(e: KeyboardEvent) { + if (e.key === "Escape") { + setMenuItemOpen(false); + } + } + + document.addEventListener("mousedown", handleClickOutside); + document.addEventListener("keydown", keyPress); + return () => { + document.removeEventListener("mousedown", handleClickOutside); + document.removeEventListener("keydown", keyPress); + }; + }, [ref, setMenuItemOpen]); + return (