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:
parent
25965341e0
commit
6f73bf0c55
1 changed files with 310 additions and 365 deletions
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue