swarm ui: agents page opens an agent's details beside the list
Selecting an agent card opens its details in a column on the right of the agents list, at /agents/<name>, instead of unfolding the card in place. The list is full width until an agent is selected, then narrows and the details slide in. A narrow screen shows the details alone, with a back button. A card's message is cut to one line. The shell treats /agents/<name> as the agents page, so the nav tab stays lit and the page is not rebuilt on each selection.
This commit is contained in:
parent
2d3da56907
commit
7bdaea7954
5 changed files with 494 additions and 154 deletions
|
|
@ -0,0 +1,33 @@
|
|||
/* <AgentDetailPane>: the back button, then the agent's icon and name. */
|
||||
.agent-detail-pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75em;
|
||||
}
|
||||
.agent-detail-pane-back {
|
||||
appearance: none;
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 0.5em 0;
|
||||
min-height: 2.75em;
|
||||
color: var(--muted);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.agent-detail-pane-back:hover,
|
||||
.agent-detail-pane-back:focus-visible {
|
||||
color: var(--fg);
|
||||
}
|
||||
.agent-detail-pane-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.7em;
|
||||
}
|
||||
.agent-detail-pane-title h2 {
|
||||
margin: 0;
|
||||
font-size: 1.25em;
|
||||
}
|
||||
/* The name takes the focus when the details open; it is not a control. */
|
||||
.agent-detail-pane-title h2:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
// <AgentDetailPane> — the selected agent's details, in the column beside the
|
||||
// agents list (or alone on a narrow screen): a title row with the back button
|
||||
// and the agent's icon and name, then `AgentDetail`'s state rows and folded
|
||||
// sections, the same ones the terminal page's popover shows, plus the terminal
|
||||
// preview.
|
||||
//
|
||||
// The agent comes from the roster the page already polls, so a state change made
|
||||
// here or a refresh shows at once. A name the roster does not have (a stale link,
|
||||
// an agent destroyed meanwhile) says so and still offers the way back.
|
||||
import { AgentIcon } from "../../agent/AgentIcon.js";
|
||||
import type { AgentActions } from "../../agent/roster/AgentActions.js";
|
||||
import type { AgentRow } from "../../agent/AgentTypes.js";
|
||||
import { AgentDetail } from "../../agent/detail/AgentDetail.js";
|
||||
import { EmptyState } from "../../ui/empty-state/EmptyState.js";
|
||||
import "./AgentDetailPane.css";
|
||||
|
||||
export function AgentDetailPane({
|
||||
name,
|
||||
row,
|
||||
actions,
|
||||
onClose,
|
||||
}: {
|
||||
name: string;
|
||||
/** The roster's row for `name`, or `undefined` when it has none. */
|
||||
row: AgentRow | undefined;
|
||||
actions: AgentActions;
|
||||
/** Back to the list alone. */
|
||||
onClose: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div class="agent-detail-pane">
|
||||
<div class="agent-detail-pane-head">
|
||||
<button type="button" class="agent-detail-pane-back" onClick={onClose}>
|
||||
<span aria-hidden="true">←</span> agents
|
||||
</button>
|
||||
</div>
|
||||
<div class="agent-detail-pane-title">
|
||||
{row ? <AgentIcon name={name} /> : null}
|
||||
<h2 tabIndex={-1} data-details-title>
|
||||
{name}
|
||||
</h2>
|
||||
</div>
|
||||
{row ? (
|
||||
<AgentDetail key={name} row={row} actions={actions} withTerminal />
|
||||
) : (
|
||||
<EmptyState>no agent named {name} in the swarm</EmptyState>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
113
frontend/packages/swarm-ui/src/pages/agents/AgentsLayout.css
Normal file
113
frontend/packages/swarm-ui/src/pages/agents/AgentsLayout.css
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/* <AgentsLayout>: the list and the details of the selected agent.
|
||||
|
||||
Two columns, always, so the widths can animate: the details' column goes from
|
||||
`0fr` to twice the list's, and the gap opens with it. A grid animates between
|
||||
two track lists of the same shape, and `minmax(0, …)` keeps a long line from
|
||||
stretching a column. The list is a third of the page (about 28em at the
|
||||
widest), enough for a card's badges and menu; a card's message is one line. */
|
||||
.agents-layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 0fr);
|
||||
column-gap: 0;
|
||||
align-items: start;
|
||||
transition:
|
||||
grid-template-columns 320ms cubic-bezier(0.3, 0.7, 0.2, 1),
|
||||
column-gap 320ms cubic-bezier(0.3, 0.7, 0.2, 1);
|
||||
}
|
||||
.agents-layout-selected {
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
|
||||
column-gap: 1.25em;
|
||||
}
|
||||
.agents-layout-list {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* The details scroll on their own, under the header, so the list stays in view.
|
||||
The inner box keeps the width the column ends up with while the column grows,
|
||||
so the text does not re-wrap through the slide; the clip hides what has not
|
||||
slid in yet. */
|
||||
.agents-layout-details {
|
||||
min-width: 0;
|
||||
position: sticky;
|
||||
top: 5em;
|
||||
max-height: calc(100dvh - 6.5em);
|
||||
overflow: hidden auto;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transform: translateX(1.5em);
|
||||
transition:
|
||||
opacity 200ms ease,
|
||||
transform 320ms cubic-bezier(0.3, 0.7, 0.2, 1),
|
||||
visibility 0s linear 320ms;
|
||||
}
|
||||
.agents-layout-selected .agents-layout-details {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transform: none;
|
||||
transition:
|
||||
opacity 260ms ease 80ms,
|
||||
transform 320ms cubic-bezier(0.3, 0.7, 0.2, 1),
|
||||
visibility 0s;
|
||||
}
|
||||
.agents-layout-details-inner {
|
||||
min-width: 30em;
|
||||
}
|
||||
|
||||
/* A narrow screen: one column at a time, no slide. */
|
||||
@media (max-width: 60em) {
|
||||
.agents-layout {
|
||||
display: block;
|
||||
transition: none;
|
||||
}
|
||||
.agents-layout-selected .agents-layout-list {
|
||||
display: none;
|
||||
}
|
||||
.agents-layout:not(.agents-layout-selected) .agents-layout-details {
|
||||
display: none;
|
||||
}
|
||||
.agents-layout-details {
|
||||
position: static;
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
transform: none;
|
||||
transition: none;
|
||||
}
|
||||
.agents-layout-details-inner {
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Same three-rule motion guard as the shell's other transitions: the OS
|
||||
preference, the explicit "reduce", then the explicit "allow" over an OS
|
||||
"reduce". */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.agents-layout,
|
||||
.agents-layout-details,
|
||||
.agents-layout-selected .agents-layout-details {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
:root[data-motion="reduce"] .agents-layout,
|
||||
:root[data-motion="reduce"] .agents-layout-details,
|
||||
:root[data-motion="reduce"] .agents-layout-selected .agents-layout-details {
|
||||
transition: none;
|
||||
}
|
||||
@media (min-width: 60.01em) {
|
||||
:root[data-motion="allow"] .agents-layout {
|
||||
transition:
|
||||
grid-template-columns 320ms cubic-bezier(0.3, 0.7, 0.2, 1),
|
||||
column-gap 320ms cubic-bezier(0.3, 0.7, 0.2, 1);
|
||||
}
|
||||
:root[data-motion="allow"] .agents-layout-details {
|
||||
transition:
|
||||
opacity 200ms ease,
|
||||
transform 320ms cubic-bezier(0.3, 0.7, 0.2, 1),
|
||||
visibility 0s linear 320ms;
|
||||
}
|
||||
:root[data-motion="allow"] .agents-layout-selected .agents-layout-details {
|
||||
transition:
|
||||
opacity 260ms ease 80ms,
|
||||
transform 320ms cubic-bezier(0.3, 0.7, 0.2, 1),
|
||||
visibility 0s;
|
||||
}
|
||||
}
|
||||
55
frontend/packages/swarm-ui/src/pages/agents/AgentsLayout.tsx
Normal file
55
frontend/packages/swarm-ui/src/pages/agents/AgentsLayout.tsx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
// <AgentsLayout> — the agents page's two columns: the agent list, and the
|
||||
// details of the selected agent beside it. With nothing selected the list takes
|
||||
// the whole width. Selecting an agent narrows the list to a column and slides
|
||||
// the details in on the right (the two columns' widths animate); closing
|
||||
// reverses it. The details stay drawn, faded, for the length of that animation:
|
||||
// `shown` is the agent that was selected last.
|
||||
//
|
||||
// A narrow screen has room for one column, so the details replace the list
|
||||
// while an agent is selected, and a back button in them returns to it.
|
||||
//
|
||||
// The CSS owns the widths and the breakpoint (`AgentsLayout.css`); this
|
||||
// component owns what is in each column and who has the focus: opening an
|
||||
// agent moves it to the details' title, so a keyboard or screen reader user
|
||||
// lands on what they chose and not on a list they have left behind.
|
||||
import type { ComponentChildren } from "preact";
|
||||
import { useEffect, useRef } from "preact/hooks";
|
||||
import "./AgentsLayout.css";
|
||||
|
||||
export function AgentsLayout({
|
||||
selected,
|
||||
list,
|
||||
details,
|
||||
}: {
|
||||
/** The selected agent's name, or `null` when none is. */
|
||||
selected: string | null;
|
||||
list: ComponentChildren;
|
||||
/** The details to draw for the agent last selected, or `null` before any. */
|
||||
details: ComponentChildren;
|
||||
}) {
|
||||
const detailsRef = useRef<HTMLElement>(null);
|
||||
useEffect(() => {
|
||||
if (selected === null) return;
|
||||
detailsRef.current
|
||||
?.querySelector<HTMLElement>("[data-details-title]")
|
||||
?.focus({ preventScroll: true });
|
||||
}, [selected]);
|
||||
return (
|
||||
<div
|
||||
class={
|
||||
"agents-layout" + (selected === null ? "" : " agents-layout-selected")
|
||||
}
|
||||
>
|
||||
<div class="agents-layout-list">{list}</div>
|
||||
<section
|
||||
class="agents-layout-details"
|
||||
aria-label="agent details"
|
||||
ref={detailsRef}
|
||||
// A shut pane holds nothing a tab stop or a screen reader should reach.
|
||||
{...(selected === null ? { inert: true, "aria-hidden": "true" } : {})}
|
||||
>
|
||||
<div class="agents-layout-details-inner">{details}</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -7,28 +7,26 @@
|
|||
// One fetch, on a refresh-interval cadence like the hives card: `GET
|
||||
// /api/agents/status` — one row per roster agent (identity store is the
|
||||
// roster, so a never-reported agent still gets a row), each already
|
||||
// carrying its freshness/snapshot/config PR/wanted state. Used to be
|
||||
// three separate fetches joined client-side by name; per operator
|
||||
// review feedback ("the view should be filled by a single backend
|
||||
// call") the join moved server-side instead — see
|
||||
// `swarm-controller/src/routes/agents.rs`'s `get_agents_status` handler. No more
|
||||
// per-page joining left to do here: the wire row *is* the row this page renders.
|
||||
// carrying its freshness/snapshot/config PR/wanted state, joined server-side
|
||||
// (see `get_agents_status` in `swarm-controller/src/routes/agents.rs`).
|
||||
//
|
||||
// Owns the "+ agent" trigger too — the roster this populates is the
|
||||
// natural home for the action that populates it. The form itself
|
||||
// (`CreateAgentForm`) mounts inside a `Dialog` here, not its own route.
|
||||
//
|
||||
// The page is a column of separate cards: the hives card, a filter card (with
|
||||
// the "+ agent" button and the refresh picker), then one card per agent, each
|
||||
// opening in place into its details (mara: "one column of expandable cards";
|
||||
// the agents are not wrapped in one big card). This file owns the page's own
|
||||
// state and the filter fields only — `AgentRow` and friends live in
|
||||
// The page is a column of separate cards: a filter card (with the "+ agent"
|
||||
// button and the refresh picker), then one card per agent (mara: "one column
|
||||
// of expandable cards"). Choosing a card selects the agent (`/agents/<name>`):
|
||||
// the list narrows to a column and the agent's details slide in beside it, and
|
||||
// on a narrow screen they replace the list (mara: "it only becomes a
|
||||
// main-detail page only when an agent is tapped"). `AgentsLayout` owns the
|
||||
// columns and `AgentDetailPane` the details; this file owns the page's own
|
||||
// state and the filter fields only. `AgentRow` and friends live in
|
||||
// `AgentTypes.ts`, the wanted-state control in `WantedMenu.tsx`, the actions
|
||||
// on an agent (declare a state, link an account) in `AgentActions.tsx`, the
|
||||
// card in `AgentCard.tsx` and its opened body in `AgentDetail.tsx`
|
||||
// (mara: "agentspage is now giant and deserves a split"). The filter bar is
|
||||
// `FilterableView` (`ui/filterable-view/`, see its own comment).
|
||||
import { useState } from "preact/hooks";
|
||||
// on an agent in `AgentActions.tsx`, the card in `AgentCard.tsx`. The filter
|
||||
// bar is `FilterableView` (`ui/filterable-view/`, see its own comment).
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import { useLocation } from "wouter-preact";
|
||||
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
||||
import { useAgentActions } from "../../agent/roster/AgentActions.js";
|
||||
import { AgentCard } from "../../agent/roster/AgentCard.js";
|
||||
|
|
@ -37,6 +35,10 @@ import { FRESHNESS, type AgentRow } from "../../agent/AgentTypes.js";
|
|||
import { Button } from "../../ui/button/Button.js";
|
||||
import { Dialog } from "../../ui/dialog/Dialog.js";
|
||||
import { SkeletonRegion } from "../../ui/skeleton/Skeleton.js";
|
||||
import { AgentDetailPane } from "./AgentDetailPane.js";
|
||||
import { AgentsLayout } from "./AgentsLayout.js";
|
||||
import { usePageTitle } from "../../shell/page-title.js";
|
||||
import { agentPath, selectedAgent } from "../../shell/routes.js";
|
||||
import { FilterableView } from "../../ui/filterable-view/FilterableView.js";
|
||||
import {
|
||||
RefreshIntervalPicker,
|
||||
|
|
@ -108,6 +110,26 @@ export function AgentsPage() {
|
|||
{ cacheKey: "agents" },
|
||||
);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [path, navigate] = useLocation();
|
||||
const selected = selectedAgent(path);
|
||||
// The details stay drawn, fading out, while the column closes.
|
||||
const lastSelected = useRef(selected);
|
||||
if (selected !== null) lastSelected.current = selected;
|
||||
usePageTitle(selected ?? undefined);
|
||||
// Closing the details shuts the pane the focus was in; it goes back to the
|
||||
// agent's card, so the keyboard path continues from the list.
|
||||
const wasSelected = useRef<string | null>(null);
|
||||
useEffect(() => {
|
||||
const was = wasSelected.current;
|
||||
wasSelected.current = selected;
|
||||
if (was === null || selected !== null) return;
|
||||
const inPane = document.activeElement?.closest("[inert]") != null;
|
||||
if (inPane || document.activeElement === document.body) {
|
||||
document
|
||||
.querySelector<HTMLElement>(`[data-agent="${CSS.escape(was)}"]`)
|
||||
?.focus({ preventScroll: true });
|
||||
}
|
||||
}, [selected]);
|
||||
// The PUT response is the hive's whole declaration set (every agent's
|
||||
// `wanted` state) — same shape `GET /api/hives/{hive}/wanted` returns — so
|
||||
// patch just that field into the rows already on screen rather than firing
|
||||
|
|
@ -159,18 +181,40 @@ export function AgentsPage() {
|
|||
</SkeletonRegion>
|
||||
) : null}
|
||||
{rows ? (
|
||||
<FilterableView
|
||||
view="cards"
|
||||
standalone
|
||||
barActions={barActions}
|
||||
columns={FIELDS}
|
||||
rows={rows}
|
||||
rowKey={(a) => a.name}
|
||||
storageKey="swarm-ui:agents:table-filters"
|
||||
emptyMessage="no agents yet — the swarm-wide identity store has no agents registered on any hive"
|
||||
// Each card gets its live row from `rows` on every render, so an
|
||||
// opened card follows a refresh or a state change made inside it.
|
||||
renderCard={(a) => <AgentCard row={a} actions={actions} />}
|
||||
<AgentsLayout
|
||||
selected={selected}
|
||||
details={
|
||||
lastSelected.current === null ? null : (
|
||||
<AgentDetailPane
|
||||
name={lastSelected.current}
|
||||
row={rows.find((a) => a.name === lastSelected.current)}
|
||||
actions={actions}
|
||||
onClose={() => navigate("/agents")}
|
||||
/>
|
||||
)
|
||||
}
|
||||
list={
|
||||
<FilterableView
|
||||
view="cards"
|
||||
standalone
|
||||
barActions={barActions}
|
||||
columns={FIELDS}
|
||||
rows={rows}
|
||||
rowKey={(a) => a.name}
|
||||
storageKey="swarm-ui:agents:table-filters"
|
||||
emptyMessage="no agents yet — the swarm-wide identity store has no agents registered on any hive"
|
||||
// Each card gets its live row from `rows` on every render, so a
|
||||
// card follows a refresh or a state change made in the details.
|
||||
renderCard={(a) => (
|
||||
<AgentCard
|
||||
row={a}
|
||||
actions={actions}
|
||||
selected={a.name === selected}
|
||||
onOpen={() => navigate(agentPath(a.name))}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
<Dialog
|
||||
|
|
|
|||
Loading…
Reference in a new issue