swarm-ui: fold an agent's long activity lists, and list subagents as rows
On a busy agent the activity section grew long: the todos and bash tasks ran to dozens of rows, and the subagents were one wrapping line of badges. Each list now shows its first five rows with a "show all N" button; expanded, the rows scroll in a bounded box. The subagents are one row each (name, model and effort, state and age), running first and the rest dimmed, as in the menu on the terminal page, and a picked subagent stays in view when the list is folded.
This commit is contained in:
parent
1448168569
commit
ef4c9214f7
3 changed files with 271 additions and 88 deletions
19
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.css
Normal file
19
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.css
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* <CappedRows> — the button under a folded list, and the bounded scroll box of
|
||||
an expanded one. */
|
||||
.ui-capped-rows-open {
|
||||
max-height: 18em;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.ui-capped-rows-toggle {
|
||||
margin-top: 0.4em;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: var(--blue);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ui-capped-rows-toggle:hover,
|
||||
.ui-capped-rows-toggle:focus-visible {
|
||||
text-decoration: underline;
|
||||
}
|
||||
44
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx
Normal file
44
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// <CappedRows> — a list that shows its first few rows and a "show all N"
|
||||
// button for the rest, so a busy agent's long list doesn't push the rest of the
|
||||
// details off the screen. Expanded, the rows scroll inside a bounded box. The
|
||||
// caller draws the rows: it gets the ones to show and puts them in its own
|
||||
// list element, so each list keeps its own markup and columns.
|
||||
import type { ComponentChildren } from "preact";
|
||||
import { useState } from "preact/hooks";
|
||||
import { capRows } from "./cap-rows.js";
|
||||
import "./CappedRows.css";
|
||||
|
||||
export function CappedRows<T>({
|
||||
rows,
|
||||
keep,
|
||||
noun,
|
||||
children,
|
||||
}: {
|
||||
rows: readonly T[];
|
||||
/** Rows that show even while folded, such as the picked one. */
|
||||
keep?: (row: T) => boolean;
|
||||
/** What the rows are, for the button: "show all 12 todos". */
|
||||
noun: string;
|
||||
children: (shown: T[]) => ComponentChildren;
|
||||
}) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const { shown, hidden } = capRows(rows, expanded, keep);
|
||||
const foldable = expanded || hidden > 0;
|
||||
return (
|
||||
<>
|
||||
<div class={expanded ? "ui-capped-rows ui-capped-rows-open" : undefined}>
|
||||
{children(shown)}
|
||||
</div>
|
||||
{foldable ? (
|
||||
<button
|
||||
type="button"
|
||||
class="ui-capped-rows-toggle"
|
||||
aria-expanded={expanded}
|
||||
onClick={() => setExpanded((e) => !e)}
|
||||
>
|
||||
{expanded ? "show fewer" : `show all ${rows.length} ${noun}`}
|
||||
</button>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
21
frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts
Normal file
21
frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// Which rows of a long list show while it is folded to its first few, without
|
||||
// a DOM, so the rule can be tested.
|
||||
|
||||
/** How many rows a folded list shows. */
|
||||
export const CAP = 5;
|
||||
|
||||
/**
|
||||
* The rows to draw. Folded, that is the first `cap`, plus any later row `keep`
|
||||
* names (a picked row must not vanish when the list refreshes and reorders);
|
||||
* expanded, all of them. `hidden` counts the rows left out.
|
||||
*/
|
||||
export function capRows<T>(
|
||||
rows: readonly T[],
|
||||
expanded: boolean,
|
||||
keep: (row: T) => boolean = () => false,
|
||||
cap: number = CAP,
|
||||
): { shown: T[]; hidden: number } {
|
||||
if (expanded || rows.length <= cap) return { shown: [...rows], hidden: 0 };
|
||||
const shown = rows.filter((row, i) => i < cap || keep(row));
|
||||
return { shown, hidden: rows.length - shown.length };
|
||||
}
|
||||
Loading…
Reference in a new issue