Skip to content

Commit d4ea452

Browse files
authored
[HUD] navbar metrics section to use grouped dropdown component (#7519)
Requires #7518 Changes the metrics dropdown to use the grouped dropdown component Also remove the old component since there are no more usages after removing this one I checked that on touchscreen, tapping metrics doesn't navigate to the metrics page but opens the dropdown, which makes the old behavior Old: <img width="242" height="230" alt="image" src="https://github.com/user-attachments/assets/93c8822d-e0cf-43b1-ad99-65790aa03e73" /> New: <img width="300" height="161" alt="image" src="https://github.com/user-attachments/assets/fb9108e6-0223-447a-b771-d3ccc1a1d4a8" />
1 parent 39aa74d commit d4ea452

File tree

1 file changed

+28
-83
lines changed

1 file changed

+28
-83
lines changed

torchci/components/layout/NavBar.tsx

Lines changed: 28 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,11 @@
11
import { benchmarkNavGroup } from "components/benchmark_v3/pages/BenchmarkListPage";
22
import styles from "components/layout/NavBar.module.css";
33
import Link from "next/link";
4-
import React, { useState } from "react";
54
import { AiFillGithub } from "react-icons/ai";
65
import ThemeModePicker from "../common/ThemeModePicker";
76
import LoginSection from "./LoginSection";
87
import { NavBarGroupDropdown, NavItem } from "./NavBarGroupDropdown";
98

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-
899
function NavBar() {
9010
const benchmarkDropdown = benchmarkNavGroup;
9111

@@ -185,7 +105,11 @@ function NavBar() {
185105
name: "vLLM CI metrics",
186106
href: "/metrics/vllm",
187107
},
188-
];
108+
].map((item) => ({
109+
label: item.name,
110+
route: item.href,
111+
type: "item" as const,
112+
}));
189113

190114
return (
191115
<div className={styles.navbar}>
@@ -247,8 +171,29 @@ function NavBar() {
247171
KPIs
248172
</Link>
249173
</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+
/>
252197
<NavBarGroupDropdown title="Dev Infra" items={devInfraDropdown} />
253198
<li
254199
style={{ cursor: "pointer", display: "flex", alignItems: "center" }}

0 commit comments

Comments
 (0)