Skip to content

Server-side browse filter (grep by name) - #70

Merged
lance0 merged 8 commits into
masterfrom
feat/browse-filter
Jun 23, 2026
Merged

lance0 merged 8 commits into
masterfrom
feat/browse-filter

Conversation

@lance0

@lance0 lance0 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

What

Browsing a kind from the Nav rail capped at the first 500 rows — useless on a large instance (you can't scroll to one device among hundreds of thousands). This adds a server-side name filter: while browsing a kind, / opens a filter input, and Enter re-fetches that kind narrowed by name.

┏━ Devices · name contains "bfr" · 52 ━━━━━━━━━━━━━┓
┃> bfr-core-01              chi1                  ┃
┃  bfr-core-02              chi1                  ┃
┃  bfr-edge-01              den1                  ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
/ filter · Enter open · Esc clear · r refresh

Behavior

  • / is contextual: while browsing a kind it filters that list; a search-result list keeps the global q= search. (Mode::BrowseFilter, distinct from Mode::Search.)
  • Explicit, not live — Enter applies it, so editing the filter doesn't hammer NetBox.
  • Per-kind field: name__ic (devices/racks/sites/VLANs/VRFs/route-targets), prefix__ic (prefixes), address__ic (IPs), cid__ic (circuits). ASN/IP-range have no substring field, so / there falls back to global search.
  • Title shows the filter + count (Devices · name contains "bfr" · 52); a 500+ count signals the cap so truncation is never silent ("refine the filter").
  • Clearing: Esc peels the active filter (back to the full list) before it leaves the screen; Ctrl+X or an empty Enter also clear it.

Deliberately not raising the browse cap — at 335k devices, scrolling is the wrong model; server-side filtering is the fix.

How

browse() gains an optional filter arg that pushes the kind's substring param; browse_filter_field(kind) maps the field (and lets the TUI tell whether a kind is filterable). AppCommand::Browse carries the filter; Mode::BrowseFilter handles the input (apply on Enter, clear on Ctrl+X/empty, cancel on Esc). Switching browse kinds resets the filter.

Tests

  • browse: field mapping per kind; a filtered fetch sends name__ic=<value> (wiremock).
  • state: / opens the filter and Enter dispatches Browse { filter: Some(..) }; Esc peels an active filter back to an unfiltered re-browse.
  • Full gate green (fmt, clippy ×2, tests ×2). The name__ic/prefix__ic/address__ic lookups were confirmed against a live 4.6 instance.

Scoped to browse/nav only (not global search). Substring only; regex (name__iregex) can be a later advanced mode.

lance0 added 8 commits June 23, 2026 15:25
Browsing a kind from the Nav rail capped at the first BROWSE_CAP rows, which is
useless on a large instance (you can't scroll to a device among hundreds of
thousands). Add a server-side name filter: `/` while browsing a kind opens a
filter input (distinct from the global `q=` search); Enter re-fetches that kind
with the kind's substring field (name__ic / prefix__ic / address__ic / cid__ic).

- Explicit, not live — Enter applies it, so editing doesn't hammer NetBox.
- Pane title shows the filter + count ("Devices · name contains 'bfr' · 52"); a
  `500+` count signals the cap so truncation is never silent.
- Esc peels the filter (back to the full list) before leaving; Ctrl+X / empty
  Enter also clear it.
- New `Mode::BrowseFilter`, `browse::browse_filter_field`, and a `filter` arg on
  `browse()` / `AppCommand::Browse`.

Covered by browse (field map + filtered fetch) and state (/ applies, Esc peels)
tests.
- Empty filtered browse kept its context: a filter that matched nothing fell
  through to the recents/empty-home render. Now an active browse (browse_kind set,
  no search query) stays on the browse path even with zero rows, showing the
  titled context ("Devices · name contains 'zzz' · 0") plus a "No matching
  devices." note instead of the recents fallback.
- 'r' refreshes a browsed list: it returned "nothing to refresh" for a browse
  (refresh only handled search). Now 'r' re-browses the current kind with its
  active filter (shared browse_current_cmd helper).
- CHANGELOG: restore the '## [0.10.0]' heading a prior edit dropped, which had
  collapsed the shipped 0.10.0 entries back under [Unreleased] with a duplicate
  '### Added'.

Tests: empty-filter render keeps context + note (TestBackend); 'r' re-browses
with the filter.
- Help modal + key reference now read `/ search / filter list` (the dual role);
  the first-run empty-home hint stays focused on search.
- clear_search and clear_for_profile_switch also reset browse_filter/filter_input,
  not just browse_kind — no dangling filter after a palette clear or a switch.
- clear_for_profile_switch bumps browse_gen too, so a BrowseComplete in flight from
  the old instance can't repopulate results after a switch (pre-existing gap).
- Empty-state note is filter-aware ("No matching X" vs "No X") and drops the dead
  None arm; Ctrl+X and the Esc-peel now fence during a switch like Enter does.
- CHANGELOG: clarify Esc (clears on the list, cancels while editing).
list_all paged at the configured page_size, so every caller made ceil(max/
page_size) serial round trips — a 500-row browse = 5, a 1000-port panel walk = 10.
Size each page to max(page_size, min(max, MAX_PAGE_SIZE)): a fetch within the
server window lands in one trip; page_size stays a throughput floor; large fetches
page at the 1000 window. No caller pulls more rows than its own max.

Reconcile the pagination tests to the new contract: single-request for max<=1000,
multi-page (offset advances by the window) above it — including a mid-stream
short-page B1 guard. The circuit panel-walk test now asserts a non-first mapping
is found in the one (grown) page rather than across forced small pages.
Address review nits on the list_all reconciliation:
- the B1 guard's page is the first, not mid-stream — rename to
  list_all_advances_offset_by_page_size_on_a_short_first_page.
- page_size_is_clamped_to_server_window: note the clamp is proven by
  page_size()==1000; the wire limit=max(1000,100)=1000 is the floor
  dominating, incidental to the clamp itself.
…lookup)

The browse filter mapped Prefix/Aggregate to prefix__ic and IpAddress to
address__ic, but those aren't real NetBox filters: prefix and address are
CIDR/inet columns (MultiValueCharFilter over network types), not CharFields,
so they get no __ic (icontains) lookup. NetBox silently ignores unknown
filter params and returns the whole table, so the filter looked applied while
matching nothing it claimed to — a 'lying filter' over 496k prefixes / 2.1M
addresses. There is no STRICT_FILTERING knob in NetBox to make this 400, and
the behavior is identical across 4.2-4.6.

browse_filter_field now returns None for Prefix, Aggregate, and IpAddress, so
/ falls back to global search for those kinds (the router already branches on
filter-field presence). The footer hint is kind-aware to match. The 6
name-bearing kinds (name__ic) and circuits (cid__ic) are unaffected.

Containment filtering (within_include / parent) is the correct future filter
for these kinds; tracked separately.

Verified against a live NetBox 4.6.2 instance: name filter narrows devices
correctly; prefix list routes / to search.
The Option-3 fix relied on two kind-aware branches that the live drive
exercised but no unit test did:
- the / router sending a browsed Prefix/IP to Mode::Search (not BrowseFilter).
  filter_field_maps_each_kind locks the mapping, but a router that ignored
  browse_filter_field would still pass it — this asserts the behavioral flip.
- footer_nav advertising / search (not / filter) for a non-filterable browse.

Mirrors slash_browse_filter_applies_name_filter_on_enter for the search path.
The footer's Focus::Nav arm hard-coded '/ search', but the / router opens the
name filter when the browsed kind is filterable (no focus check). Since startup
lands on the Nav rail with Devices (a filterable kind) browsed, the app's front
door advertised '/ search' while / actually opened the filter.

Make the rail arm kind-aware like the List-pane arm, keyed off the settled
browse_kind (not nav_selected) so the hint tracks what / will act on without
flickering ahead of an in-flight live-browse: '/ filter' for name-bearing kinds,
'/ search' for prefix/IP (and Recent). Extend the footer test to pin the rail.

Also tighten the CHANGELOG: Ctrl+X / empty-Enter clear the filter while editing
(Normal-mode clear is Esc); Ctrl+X is unbound in Normal.
@lance0
lance0 merged commit e0b560a into master Jun 23, 2026
4 checks passed
@lance0
lance0 deleted the feat/browse-filter branch June 23, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant