Watch
0
0
Fork
You've already forked hyperhive
0

frontend: one header menu for the links, user, settings and alerts popovers

Part of the unification order in the UI sweep issue (step c).

The four header menus each kept their own open state, dismiss hook and a copy
of the popover CSS, and the copies had drifted (offset, padding, fade-in). A
shared HeaderMenu now owns the state, the dismiss rules and the popover look;
each menu supplies its button and its rows. The settings popover moves 0.15em
lower and the settings and alerts popovers gain the fade-in.
This commit is contained in:
iris 2026-11-25 22:25:40 +01:00
commit 6f73bf0c55
2 changed files with 310 additions and 365 deletions

View file

@ -1,8 +1,6 @@
/* <AlertsMenu> — the header bell (the shared icon button) with a count badge,
and a popover shaped like the links menu's. */
.alerts-menu {
position: relative;
}
and the shared `HeaderMenu` popover for the list. */
@import "@hive/shared/header-menu.css";
.alerts-menu .ui-icon-button {
position: relative;
color: var(--red);
@ -21,23 +19,6 @@
line-height: 1.2;
text-align: center;
}
.alerts-menu-popover {
position: absolute;
top: calc(100% + 0.4em);
right: 0;
z-index: var(--z-popover);
display: flex;
flex-direction: column;
gap: 0.4em;
width: min(26em, calc(100vw - 2em));
max-height: 70vh;
padding: 0.4em;
overflow-y: auto;
border: 1px solid var(--border);
border-radius: var(--radius-md);
background: var(--bg-elev);
box-shadow: var(--shadow-pop);
}
.alerts-menu-list {
display: flex;
flex-direction: column;
@ -65,13 +46,3 @@
flex-basis: 100%;
overflow-wrap: anywhere;
}
.alerts-menu-link {
display: flex;
align-items: center;
min-height: 2.75em;
padding: 0.4em 0.6em;
border-radius: var(--radius-sm);
}
.alerts-menu-link:hover {
background: var(--bg);
}

View file

@ -3,11 +3,8 @@
// alert fires, and while the alerts can't be read (the swarm may have no
// Grafana): no button beats a dead one. It polls `GET /api/alerts`, the same
// list the reports tab shows.
import { useRef, useState } from "preact/hooks";
import { BellIcon } from "@hive/shared/icons.js";
import { IconButton } from "@hive/shared/icon-button.js";
import { useDismiss } from "@hive/shared/use-dismiss.js";
import "@hive/shared/icon-button.css";
import { HeaderMenu } from "@hive/shared/header-menu.js";
import { ExternalLink } from "../ui/external-link/ExternalLink.js";
import { fetchJson, usePolled } from "../ui/polled/usePolled.js";
import { RelativeTime } from "../ui/relative-time/RelativeTime.js";
@ -38,54 +35,42 @@ export function AlertsMenu() {
}
function AlertsButton({ firing }: { firing: Alert[] }) {
const [open, setOpen] = useState(false);
const rootRef = useRef<HTMLDivElement>(null);
useDismiss({
open,
onDismiss: () => setOpen(false),
inside: [rootRef],
focusOnEscape: () => rootRef.current?.querySelector("button") ?? null,
});
const label = alertsLabel(firing.length);
return (
<div class="alerts-menu" ref={rootRef}>
<IconButton
label={label}
onClick={() => setOpen((v) => !v)}
expanded={open}
>
<BellIcon />
<span class="alerts-menu-count" aria-hidden="true">
{firing.length}
</span>
</IconButton>
{open ? (
<div class="alerts-menu-popover" role="group" aria-label={label}>
<ul class="alerts-menu-list">
{firing.map((a) => {
const since = activeSinceMs(a);
return (
<li key={alertKey(a)} class="alerts-menu-item">
<span class="alerts-menu-name">{a.name}</span>
{since !== null ? (
<span class="alerts-menu-since">
<RelativeTime epochMs={since} />
</span>
) : null}
{a.summary ? (
<span class="alerts-menu-summary">{a.summary}</span>
) : null}
</li>
);
})}
</ul>
<ExternalLink href={GRAFANA_ALERTS_URL} class="alerts-menu-link">
open Grafana's alert list
</ExternalLink>
</div>
) : null}
</div>
<HeaderMenu
class="alerts-menu"
label={label}
popoverClass="header-menu-wide"
trigger={
<>
<BellIcon />
<span class="alerts-menu-count" aria-hidden="true">
{firing.length}
</span>
</>
}
>
<ul class="alerts-menu-list">
{firing.map((a) => {
const since = activeSinceMs(a);
return (
<li key={alertKey(a)} class="alerts-menu-item">
<span class="alerts-menu-name">{a.name}</span>
{since !== null ? (
<span class="alerts-menu-since">
<RelativeTime epochMs={since} />
</span>
) : null}
{a.summary ? (
<span class="alerts-menu-summary">{a.summary}</span>
) : null}
</li>
);
})}
</ul>
<ExternalLink href={GRAFANA_ALERTS_URL} class="header-menu-item">
open Grafana's alert list
</ExternalLink>
</HeaderMenu>
);
}