Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: select a pane's name badge in a terminal group to open the agent's details

This commit is contained in:
iris 2026-11-22 17:20:03 +01:00 • committed by mara
commit 8e2844ec92

View file

@ -0,0 +1,60 @@
// <GroupPaneName> — the name badge of a pane in a group of terminals. Dragging
// it moves the pane onto another pane's edge, and selecting it opens the
// agent's details in a popover under it, as the name badge of an agent's own
// terminal does. The two share one element: a click that follows no drag is the
// select, and it works from the keyboard too. It's a draggable `span`, not a
// button inside one, because Firefox starts no drag from a button.
import { useRef, useState } from "preact/hooks";
import { Badge } from "@hive/shared/badge.js";
import { AgentDetailPopover } from "../detail/AgentDetailPopover.js";
import { LiveAgentIcon } from "./ConnectionDot.js";
import { endAgentDrag, startAgentDrag } from "./termDrag.js";
export function GroupPaneName({
paneKey,
agent,
connection,
}: {
/** The pane's key: its agent, or `agent/subagent` for a subagent's. */
paneKey: string;
/** The agent whose details open; a subagent has none of its own. */
agent: string;
connection: Parameters<typeof LiveAgentIcon>[0]["connection"];
}) {
const [open, setOpen] = useState(false);
const ref = useRef<HTMLSpanElement>(null);
return (
<>
<span
ref={ref}
class="ui-agent-group-grip"
role="button"
tabIndex={0}
aria-expanded={open}
aria-label={`${paneKey}, ${agent}'s details`}
title={`${open ? "close" : "open"} ${agent}'s details; drag ${paneKey} onto another pane to move it`}
draggable
onClick={() => setOpen((o) => !o)}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
setOpen((o) => !o);
}
}}
onDragStart={(e) => startAgentDrag(e, paneKey)}
onDragEnd={endAgentDrag}
>
<Badge
icon={<LiveAgentIcon name={agent} connection={connection} />}
value={paneKey}
/>
</span>
<AgentDetailPopover
agent={agent}
open={open}
onClose={() => setOpen(false)}
anchorRef={ref}
/>
</>
);
}