|
1 | 1 | import { benchmarkNavGroup } from "components/benchmark_v3/pages/BenchmarkListPage"; |
2 | 2 | import styles from "components/layout/NavBar.module.css"; |
3 | 3 | import Link from "next/link"; |
4 | | -import React, { useState } from "react"; |
5 | 4 | import { AiFillGithub } from "react-icons/ai"; |
6 | 5 | import ThemeModePicker from "../common/ThemeModePicker"; |
7 | 6 | import LoginSection from "./LoginSection"; |
8 | 7 | import { NavBarGroupDropdown, NavItem } from "./NavBarGroupDropdown"; |
9 | 8 |
|
10 | | -const NavBarDropdown = ({ |
11 | | - title, |
12 | | - items, |
13 | | -}: { |
14 | | - title: string; |
15 | | - items: any; |
16 | | -}): JSX.Element => { |
17 | | - const [dropdown, setDropdown] = useState(false); |
18 | | - const dropdownStyle = dropdown ? { display: "block" } : {}; |
19 | | - const firstItemHref = items.length > 0 ? items[0].href : "#"; |
20 | | - |
21 | | - // Check if device is touch-enabled |
22 | | - const isTouchDevice = React.useMemo( |
23 | | - () => |
24 | | - typeof window !== "undefined" && |
25 | | - ("ontouchstart" in window || navigator.maxTouchPoints > 0), |
26 | | - [] |
27 | | - ); |
28 | | - |
29 | | - // Set dropdown state only on non-touch devices |
30 | | - const setDropdownIfNotTouch = (value: boolean) => { |
31 | | - if (!isTouchDevice) { |
32 | | - setDropdown(value); |
33 | | - } |
34 | | - }; |
35 | | - |
36 | | - // Close dropdown when clicking outside |
37 | | - React.useEffect(() => { |
38 | | - const handleClickOutside = (event: MouseEvent) => { |
39 | | - const target = event.target as HTMLElement; |
40 | | - if (!target.closest(`.${styles.dropdownContainer}`)) { |
41 | | - setDropdown(false); |
42 | | - } |
43 | | - }; |
44 | | - |
45 | | - if (dropdown) { |
46 | | - document.addEventListener("click", handleClickOutside); |
47 | | - return () => { |
48 | | - document.removeEventListener("click", handleClickOutside); |
49 | | - }; |
50 | | - } |
51 | | - }, [dropdown]); |
52 | | - |
53 | | - return ( |
54 | | - <li |
55 | | - onMouseEnter={() => setDropdownIfNotTouch(true)} |
56 | | - onMouseLeave={() => setDropdownIfNotTouch(false)} |
57 | | - style={{ padding: 0 }} |
58 | | - className={`${styles.dropdownContainer} ${ |
59 | | - dropdown ? styles.dropdownOpen : "" |
60 | | - }`} |
61 | | - > |
62 | | - <Link |
63 | | - href={firstItemHref} |
64 | | - prefetch={false} |
65 | | - className={styles.dropdowntitle} |
66 | | - onClick={(e) => { |
67 | | - if (isTouchDevice) { |
68 | | - // otherwise the menu will close immediately on touch devices |
69 | | - e.preventDefault(); |
70 | | - } |
71 | | - setDropdown(!dropdown); |
72 | | - }} |
73 | | - > |
74 | | - {title} ▾ |
75 | | - </Link> |
76 | | - <ul className={styles.dropdown} style={dropdownStyle}> |
77 | | - {items.map((item: any) => ( |
78 | | - <li key={item.href}> |
79 | | - <Link href={item.href} prefetch={false}> |
80 | | - {item.name} |
81 | | - </Link> |
82 | | - </li> |
83 | | - ))} |
84 | | - </ul> |
85 | | - </li> |
86 | | - ); |
87 | | -}; |
88 | | - |
89 | 9 | function NavBar() { |
90 | 10 | const benchmarkDropdown = benchmarkNavGroup; |
91 | 11 |
|
@@ -185,7 +105,11 @@ function NavBar() { |
185 | 105 | name: "vLLM CI metrics", |
186 | 106 | href: "/metrics/vllm", |
187 | 107 | }, |
188 | | - ]; |
| 108 | + ].map((item) => ({ |
| 109 | + label: item.name, |
| 110 | + route: item.href, |
| 111 | + type: "item" as const, |
| 112 | + })); |
189 | 113 |
|
190 | 114 | return ( |
191 | 115 | <div className={styles.navbar}> |
@@ -247,8 +171,29 @@ function NavBar() { |
247 | 171 | KPIs |
248 | 172 | </Link> |
249 | 173 | </li> |
250 | | - <NavBarGroupDropdown title="Benchmarks" items={benchmarkDropdown} />{" "} |
251 | | - <NavBarDropdown title="Metrics" items={metricsDropdown} /> |
| 174 | + <NavBarGroupDropdown title="Benchmarks" items={benchmarkDropdown} /> |
| 175 | + <NavBarGroupDropdown |
| 176 | + title={ |
| 177 | + <Link |
| 178 | + href="/metrics" |
| 179 | + prefetch={false} |
| 180 | + onClick={(e) => { |
| 181 | + const isTouchDevice = |
| 182 | + typeof window !== "undefined" && |
| 183 | + ("ontouchstart" in window || navigator.maxTouchPoints > 0); |
| 184 | + if (isTouchDevice) { |
| 185 | + e.preventDefault(); |
| 186 | + } |
| 187 | + }} |
| 188 | + > |
| 189 | + Metrics ▾ |
| 190 | + </Link> |
| 191 | + } |
| 192 | + // showCarrot false since the spacing is unusual if we use the |
| 193 | + // default |
| 194 | + showCarrot={false} |
| 195 | + items={metricsDropdown} |
| 196 | + /> |
252 | 197 | <NavBarGroupDropdown title="Dev Infra" items={devInfraDropdown} /> |
253 | 198 | <li |
254 | 199 | style={{ cursor: "pointer", display: "flex", alignItems: "center" }} |
|
0 commit comments