Watch
0
0
Fork
You've already forked hyperhive
0

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.
This commit is contained in:
iris 2026-11-27 23:09:04 +01:00
commit e701be870a
6 changed files with 186 additions and 9 deletions

View file

@ -200,6 +200,9 @@ export function AgentsPage() {
<FilterableView
view="cards"
standalone
// An open agent narrows the list to a column: one button holds
// the filters.
compactFilters={selected !== null}
barActions={barActions}
columns={FIELDS}
rows={rows}

View file

@ -0,0 +1,112 @@
// <FilterPopover> — 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<T>({
columns,
getFilter,
updateFilter,
toggleFilterValue,
resetFilters,
activeCount,
multiselectOptionsFor,
label,
}: {
columns: FilterColumn<T>[];
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<T>) => string[];
label: (c: FilterColumn<T>) => string;
}) {
const [open, setOpen] = useState(false);
const anchorRef = useRef<HTMLSpanElement>(null);
return (
<>
<span ref={anchorRef}>
<Button
ariaLabel={filterButtonLabel(activeCount)}
onClick={() => setOpen((o) => !o)}
>
<FilterIcon />
{activeCount > 0 ? ` ${activeCount}` : null}
</Button>
</span>
<Popover
open={open}
onClose={() => setOpen(false)}
anchorRef={anchorRef}
label="filters"
>
<Panel title="filters" onClose={() => setOpen(false)}>
<div class="ui-filter-popover">
{columns.map((c) => {
const name = label(c);
if (c.filterMode === "multiselect") {
const filter = getFilter(c.key);
return (
<fieldset key={c.key} class="ui-filter-popover-group">
<legend>{name}</legend>
<MultiselectFilterOptions
options={multiselectOptionsFor(c)}
filter={filter}
onToggle={(v) => toggleFilterValue(c.key, v)}
scrollable={false}
/>
<NegateToggle
negate={filter.negate}
onChange={(negate) => updateFilter(c.key, { negate })}
/>
</fieldset>
);
}
return (
<input
key={c.key}
type="text"
class="ui-filterable-view-search"
placeholder={`filter by ${name}…`}
aria-label={`filter by ${name}`}
value={getFilter(c.key).value}
onInput={(e) =>
updateFilter(c.key, {
value: (e.target as HTMLInputElement).value,
})
}
/>
);
})}
{activeCount > 0 ? (
<button
type="button"
class="ui-table-reset-filters"
onClick={resetFilters}
>
reset filters
</button>
) : null}
</div>
</Panel>
</Popover>
</>
);
}

View file

@ -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;
}

View file

@ -27,6 +27,7 @@ import {
type FilterColumn,
type TableColumn,
} from "../table/Table.js";
import { FilterPopover } from "./FilterPopover.js";
import "./FilterableView.css";
function isFilterable<T>(c: FilterColumn<T>): boolean {
@ -52,9 +53,11 @@ function FilterBar<T>({
multiselectOptionsFor,
actions,
standalone,
compact,
}: {
actions?: ComponentChildren;
standalone?: boolean;
compact?: boolean;
columns: FilterColumn<T>[];
getFilter: (key: string) => MultiselectFilterState & { value: string };
updateFilter: (
@ -76,7 +79,19 @@ function FilterBar<T>({
: "ui-filterable-view-filter-bar"
}
>
{filterable.map((c) => {
{compact ? (
<FilterPopover
columns={filterable}
getFilter={getFilter}
updateFilter={updateFilter}
toggleFilterValue={toggleFilterValue}
resetFilters={resetFilters}
activeCount={activeFilters.length}
multiselectOptionsFor={multiselectOptionsFor}
label={columnLabel}
/>
) : null}
{(compact ? [] : filterable).map((c) => {
const label = columnLabel(c);
if (c.filterMode === "multiselect") {
return (
@ -106,7 +121,7 @@ function FilterBar<T>({
/>
);
})}
{activeFilters.length > 0 ? (
{activeFilters.length > 0 && !compact ? (
<button
type="button"
class="ui-table-reset-filters"
@ -146,13 +161,16 @@ export function FilterableView<T>(
// `barActions` (buttons, a refresh picker) sit at its trailing edge.
standalone?: boolean;
barActions?: ComponentChildren;
// Cards view only. The filters sit behind one `filter` button and its
// popover instead of in the bar, for a list squeezed into a column.
compactFilters?: boolean;
// Cards view only. Drawn after the cards with the rows the filter leaves, so
// a bar that acts on what is shown (select all) needs no copy of the filter.
footer?: (visibleRows: T[]) => ComponentChildren;
},
) {
const { columns, rows, rowKey, storageKey, renderCard, emptyMessage } = props;
const { standalone, barActions, footer } = props;
const { standalone, barActions, footer, compactFilters } = props;
const {
visibleRows,
activeFilters,
@ -187,6 +205,7 @@ export function FilterableView<T>(
multiselectOptionsFor={multiselectOptionsFor}
actions={barActions}
standalone={standalone}
compact={compactFilters}
/>
{rows.length === 0 && emptyMessage ? (
<p class="ui-filterable-view-empty">{emptyMessage}</p>

View file

@ -0,0 +1,8 @@
// The accessible name of the button that holds a list's filters: its name, and
// how many filters are narrowing the list when any are. Kept apart from the component so
// a test reaches it without a DOM.
/** `filter`, or `filter (2)` while two filters are active. */
export function filterButtonLabel(active: number): string {
return active > 0 ? `filter (${active})` : "filter";
}

View file

@ -66,11 +66,11 @@ export function MultiselectFilterOptions({
// The negate toggle — mara: "you should be able to change if the filter
// is negated or not (eg search for this text vs exclude it)", same
// reasoning as `Table`'s own copy. Small enough (one checkbox+label)
// that keeping it inline here rather than a third exported piece isn't
// worth the indirection; `Table` keeps rendering its own copy for text-
// mode filters, which don't otherwise touch this file at all.
function NegateToggle({
// reasoning as `Table`'s own copy. One checkbox and its label, exported so the
// stacked filters in `FilterPopover` show the same toggle under each option
// list; `Table` keeps rendering its own copy for text-mode filters, which
// don't otherwise touch this file at all.
export function NegateToggle({
negate,
onChange,
}: {