From e701be870a0f1aca48dfaa4eaea599868697e11b Mon Sep 17 00:00:00 2001 From: iris Date: Fri, 27 Nov 2026 23:09:04 +0100 Subject: [PATCH] swarm-ui: with an agent open, the list's filters sit behind one filter button An open agent narrows the list to a column, where the filter boxes and menus took three rows. They now stack in a popover under one button that shows how many filters are active; the full-width list keeps them in the bar. --- docs/4-implementation/web-ui/swarm-ui.md | 7 +- .../swarm-ui/src/pages/agents/AgentsPage.tsx | 3 + .../src/ui/filterable-view/FilterPopover.tsx | 112 ++++++++++++++++++ .../src/ui/filterable-view/FilterableView.css | 18 +++ .../src/ui/filterable-view/FilterableView.tsx | 25 +++- .../src/ui/filterable-view/filter-label.ts | 8 ++ .../multiselect-filter/MultiselectFilter.tsx | 10 +- .../swarm-ui/test/filter-label.test.mjs | 12 ++ 8 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 frontend/packages/swarm-ui/src/ui/filterable-view/FilterPopover.tsx create mode 100644 frontend/packages/swarm-ui/src/ui/filterable-view/filter-label.ts create mode 100644 frontend/packages/swarm-ui/test/filter-label.test.mjs diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index b1aa3c3ea..e4608b42d 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -154,7 +154,12 @@ above the details shuts them and the list takes the width again, and focus returns to the agent's card. A name the roster doesn't have, from a stale link, shows "no agent named …" and the same button. The filter card, which also holds the **+ agent** button and the refresh picker, filters by name, hive, status, -message and wanted state. While the agent list loads for the first time, the +message and wanted state. +While an agent is open the list is a column with no room for them side by side, +so the filters sit behind one funnel button. +It shows how many filters are active beside the icon, and its name reads **filter (2)** to a screen reader. +The button opens a popover with **reset filters** at its foot. +While the agent list loads for the first time, the page shows grey placeholder cards with the same layout as the real ones, so the cards don't jump when the data arrives. The placeholders stand still where motion is off. diff --git a/frontend/packages/swarm-ui/src/pages/agents/AgentsPage.tsx b/frontend/packages/swarm-ui/src/pages/agents/AgentsPage.tsx index ef49f9c0d..a8e6954ec 100644 --- a/frontend/packages/swarm-ui/src/pages/agents/AgentsPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/agents/AgentsPage.tsx @@ -200,6 +200,9 @@ export function AgentsPage() { — every filter of a list behind one `filter` button. A list +// squeezed into a column has no room for a row of text boxes and menus, so they +// stack in a popover instead, with the same state as the bar that would show +// them inline. The button is the funnel icon, with the number of active filters +// after it when there are any; its accessible name is `filter (2)`. +import { useRef, useState } from "preact/hooks"; +import { FilterIcon } from "@hive/shared/icons.js"; +import { Button } from "../button/Button.js"; +import { + MultiselectFilterOptions, + NegateToggle, + type MultiselectFilterState, +} from "../multiselect-filter/MultiselectFilter.js"; +import { Panel } from "../panel/Panel.js"; +import { Popover } from "../popover/Popover.js"; +import type { FilterColumn } from "../table/Table.js"; +import { filterButtonLabel } from "./filter-label.js"; + +export function FilterPopover({ + columns, + getFilter, + updateFilter, + toggleFilterValue, + resetFilters, + activeCount, + multiselectOptionsFor, + label, +}: { + columns: FilterColumn[]; + getFilter: (key: string) => MultiselectFilterState & { value: string }; + updateFilter: ( + key: string, + patch: Partial<{ value: string; values: string[]; negate: boolean }>, + ) => void; + toggleFilterValue: (key: string, value: string) => void; + resetFilters: () => void; + activeCount: number; + multiselectOptionsFor: (c: FilterColumn) => string[]; + label: (c: FilterColumn) => string; +}) { + const [open, setOpen] = useState(false); + const anchorRef = useRef(null); + return ( + <> + + + + setOpen(false)} + anchorRef={anchorRef} + label="filters" + > + setOpen(false)}> +
+ {columns.map((c) => { + const name = label(c); + if (c.filterMode === "multiselect") { + const filter = getFilter(c.key); + return ( +
+ {name} + toggleFilterValue(c.key, v)} + scrollable={false} + /> + updateFilter(c.key, { negate })} + /> +
+ ); + } + return ( + + updateFilter(c.key, { + value: (e.target as HTMLInputElement).value, + }) + } + /> + ); + })} + {activeCount > 0 ? ( + + ) : null} +
+
+
+ + ); +} diff --git a/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.css b/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.css index 7e149192c..1e642f513 100644 --- a/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.css +++ b/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.css @@ -40,3 +40,21 @@ gap: 0.5em; margin-left: auto; } +/* The filters stacked in a popover (`FilterPopover`). */ +.ui-filter-popover { + display: flex; + flex-direction: column; + gap: 0.6em; +} +.ui-filter-popover-group { + margin: 0; + padding: 0.4em 0.6em 0.5em; + border: 1px solid var(--border); + border-radius: var(--radius-sm); + min-width: 0; +} +.ui-filter-popover-group legend { + padding: 0 0.3em; + color: var(--muted); + font-size: 0.85em; +} diff --git a/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.tsx b/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.tsx index ffa3a282a..d92e514b1 100644 --- a/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.tsx +++ b/frontend/packages/swarm-ui/src/ui/filterable-view/FilterableView.tsx @@ -27,6 +27,7 @@ import { type FilterColumn, type TableColumn, } from "../table/Table.js"; +import { FilterPopover } from "./FilterPopover.js"; import "./FilterableView.css"; function isFilterable(c: FilterColumn): boolean { @@ -52,9 +53,11 @@ function FilterBar({ multiselectOptionsFor, actions, standalone, + compact, }: { actions?: ComponentChildren; standalone?: boolean; + compact?: boolean; columns: FilterColumn[]; getFilter: (key: string) => MultiselectFilterState & { value: string }; updateFilter: ( @@ -76,7 +79,19 @@ function FilterBar({ : "ui-filterable-view-filter-bar" } > - {filterable.map((c) => { + {compact ? ( + + ) : null} + {(compact ? [] : filterable).map((c) => { const label = columnLabel(c); if (c.filterMode === "multiselect") { return ( @@ -106,7 +121,7 @@ function FilterBar({ /> ); })} - {activeFilters.length > 0 ? ( + {activeFilters.length > 0 && !compact ? (