Skip to content

feat(ou-tree): search mode: search input, pruned tree with paged results, highlighting and reveal - #1787

Merged
HendrikThePendric merged 39 commits into
feat/paged-org-unit-treefrom
feat/ou-tree-filtered-mode
Nov 17, 2026
Merged

HendrikThePendric merged 39 commits into
feat/paged-org-unit-treefrom
feat/ou-tree-filtered-mode

Conversation

@HendrikThePendric

@HendrikThePendric HendrikThePendric commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Implements DHIS2-21263 (client side, batch 4 of OuTree)


Description

Search mode for OuTree: a search over the tree endpoint, scoped to the tree's roots, shown as the tree pruned to the matching branches. Still over the stand-in, still not exported.

  • Search input. useOuTreeSearch owns the term: trimmed, at least 2 characters (SEARCH_MIN_LENGTH), debounced by 300 ms (SEARCH_DEBOUNCE_MS), with the help text and a status (idle, too-short, loading, loaded with the total, failed). OuTreeSearchInput is an InputField over that hook; an app can bring its own input. New dependency on @dhis2-ui/input.
  • Any search resets the tree, and so does clearing one. Result pages (RESULTS_PAGE_SIZE, 50) load in order as you scroll, with skeleton rows for results not received yet and retry rows for a failed page; a late answer for an earlier term is dropped. The next page is also requested when the last received result scrolls into view, so a revealed node's children, which may hold results from later pages, stay a page ahead of the scroll instead of showing such a result plain. The pruned tree (tree/pruned-tree.ts) is built from the results and their paths, and does not wait for the roots.
  • The tree browses the same in both modes. Every node keeps its arrow and one open set serves both modes. Matching branches open on arrival; a result without matching children opens to all of its children.
  • Result styling. A result gets a yellow100 background. Where the client finds the term in the name (search/match-segments.ts, shared with the stand-in) every occurrence is bold; a quoted or wildcard term marks the whole name. The tree builds one match splitter per search (createMatchSplitter, exposed by useOuTreeMatchSplitter), so the per-term work is done once for all rows; OuTreeMatchedText only renders the segments. renderLabel gets isResult, searchTerm and splitMatches for custom labels.
  • Show all children. An open node with matching children shows an eye while its row is hovered that swaps them for its complete children, and back. The matching children stay listed until the complete list is loaded, and through a failure. Hover is tree state (isHovered, setHovered), reported by OuTreeRowShell through onHoverChange, so batch 5 can add the focused row the same way.
  • No results shows the line "No results found".
  • Hooks: useOuTree adds mode and searchStatus; useOuTreeNode adds isResult, isRevealed, hasMatchingChildren and isHovered; useOuTreeActions adds search, clearSearch, toggleRevealed, retryResultsPage and setHovered; new useOuTreeSearchTerm and useOuTreeMatchSplitter.
  • From the review: the modes are browse and search, and a node's view full or pruned by how it lists its children; the row kinds for a parent's children pages are children-skeleton and children-error, next to result-skeleton and result-error; TypeScript imports name a barrel's directory, without /index; a broken endpoint contract (a result without its root or ancestors, a listed id the store lacks) throws instead of being dropped with a warning.
  • Stories: Search (try clin, san jos, "Rio de Janeiro" and san*) and SearchFailing, plus building blocks for the new pieces.

Left for later: groups, level and currentlyOpen; a result counter, which an app renders from status.total. The result colours are starting points to tune. For batch 5, with the focus model: the eye on the focused row as well as the hovered one, the searchbox role on the input, and shrinking node rows to kind, id, depth and view so the row component reads the rest through useOuTreeNode and row reuse becomes the key plus depth.


Known issues

  • The eye and the retry controls are buttons inside a treeitem, and the eye renders only while the row is hovered, so neither is keyboard-reachable yet. Batch 5's focus model owns both.
  • Highlighting is client-side and can miss what the server matched; the background marks the result either way.
  • The input is type="text", since Chromium draws a second clear cross for type="search"; the searchbox role comes with batch 5.
  • eslint's React Compiler warning on useVirtualizer remains, as in batch 3.

Checklist

  • API docs are generated (nothing is exported, so there is nothing to document)
  • Tests were added
  • Storybook demos were added

Screenshots

The Search story over the PAHO stand-in, searching clin: Georgia collapsed from its arrow; Georgia being revealed, with Clinch still listed while its counties load; Georgia revealed under a revealed United States.

outree--search-clin-georgia-collapsed outree--search-clin-georgia-revealing outree--search-clin-georgia-revealed

🤖 Generated with Claude Code

HendrikThePendric and others added 17 commits October 29, 2026 10:09
…find a match's range

The fixture's matcher moves to src/ou-tree/search/ so the client
matches as the stand-in and the backend do. findMatch returns the
matched range in the label's own indexes through a per-character
fold that keeps each folded character's origin.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…order

The store fetches one page of a filtered query and stores every entry
of it; the pruned tree appends each result's path from the first shown
root down, which is in order because results arrive in tree order.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…laceholders

Node rows carry their view and whether they are a result; filtered mode
walks the pruned tree, switches to the browse walk under revealed nodes
and appends a placeholder row per result not received yet.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…r with reveal

search resets the tree and requests page one; later pages are requested
one at a time when a placeholder row is in range. Page answers build
the pruned tree from the given roots the store has, so a search works
before the roots answered. A revealed node is a browse pocket; open and
toggle act only on browse rows. clearSearch restores initiallyOpen.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
setSearchInput trims the value, clears any search at once below
SEARCH_MIN_LENGTH and otherwise runs it after SEARCH_DEBOUNCE_MS.
getSearchStatus derives idle, too-short, loading, loaded or failed and
keeps its object while nothing changed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
useOuTreeSearch gives an input the typed value, the debounced setter,
the status and help text while the term is too short; useOuTreeSearchTerm
gives labels the effective term. useOuTree gains mode and searchStatus,
useOuTreeNode isResult and isRevealed, useOuTreeActions the search,
reveal and results-page retry actions.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
OuTreeMatchedText emphasises the term's match in a label, or all of it
for a quoted or wildcard term; OuTreeNodeLabel paints a result's
background; OuTreeRevealToggle is the eye after a pruned node's label,
shown by OuTreeRowShell only on hover or focus within through the
data-hover-only attribute; OuTreeNoResults is the empty line.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…the search input

A pruned row has the toggle space, the match marked in the label, the
result background and the eye; a revealed node shows its browse children
under it with the retry body when their page failed. The placeholder rows
render result-skeleton and result-error rows too, OuTreeList shows the
filtered rows whatever the roots status or the no-results line, and
OuTreeSearchInput is an InputField over useOuTreeSearch.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Search and SearchFailing compose OuTreeSearchInput over OuTreeList; the
building blocks show the input's three states, the matched text, the
reveal toggle and the no-results line. The stand-in's failWith already
rejects a tree page, so the failing story needs no new option.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… its path stops short

search(term) with a blank term would match everything; it now clears any
search. addResults appends the result itself when its path ends at its
parent, as the spec says, instead of dropping it unreported.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…atching branches open

One open set serves both modes. A node with matching children opens when
the page that places it arrives, unless the user closed it, and shows its
matching children; a result without any starts closed and opens to all
of its children, which marks it revealed, so a later page placing a
result under it does not narrow the list. The eye shows only on an open
node with matching children, and on one whose reveal failed, as the way
back; revealing opens the node and closing keeps the reveal. A
pruned-tree node keeps its view wherever it is listed, under a revealed
ancestor included. useOuTreeNode gains hasMatchingChildren.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…o second clear cross

InputField does not forward a role, so the input is a textbox until the
focus work gives it searchbox.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…rounds do not touch

The label sits on a 20px line box with a 2px margin inside the 24px row,
as the skeleton bars do; the text stays where it was.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…complete list is loaded

Revealing switched the walk to the slots at once, so the matching
children vanished while page one loaded. They now stay, the loader in
the arrow slot, until the page is loaded; if it fails the node stays
open on them with the retry body, which calls open.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@HendrikThePendric
HendrikThePendric requested a review from a team as a code owner October 29, 2026 16:01
@HendrikThePendric
HendrikThePendric changed the base branch from master to feat/paged-org-unit-tree October 29, 2026 16:12
…p an index loop

Resolves the five SonarCloud code smells on #1787 that are not about
keyboard access: S3358 in OuTreeList and OuTreeMatchedText, S6582 in
flattenRows and the tree state, S4138 in foldTextWithOrigin.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot

Copy link
Copy Markdown
Contributor

🚀 Deployed on https://pr-1787--dhis2-ui.netlify.app

@dhis2-bot
dhis2-bot temporarily deployed to netlify October 29, 2026 16:27 Inactive
…e index segment

JavaScript keeps index.js for the web standards; for TypeScript the plain
directory import is the norm. No resolution or build effect.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 14:53 Inactive
…children-error

The row kinds for an empty slot of a parent's children were skeleton
and error, next to batch 4's result-skeleton and result-error, so the
retry branch in OuTreeErrorRow read as error versus result rather than
children versus results. Paging names say which kind they mean; now the
rows do too, data-row-kind and row keys included.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 15:00 Inactive
…ith early returns

OuTreeList is the container around it and no longer subscribes to the
tree. ListContent is always mounted and calls the virtualiser hook before
its returns, so the virtualiser keeps its measurements across the
no-results and roots states as before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 15:08 Inactive
…ody with early returns

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 15:15 Inactive
splitMatches replaces findMatch: it cuts a label into plain and matched
segments, every non-overlapping occurrence of a plain term or the whole
label for a quoted or wildcard term, so OuTreeMatchedText and a custom
label map the same list. The module is now search/match-segments.ts.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 15:51 Inactive
… row render

createMatchSplitter(term) does the per-term work once; the tree state
keeps the splitter with the search and useOuTreeMatchSplitter exposes
it. OuTreeMatchedText takes segments and computes nothing, and
renderLabel gets the splitter as splitMatches.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 16:03 Inactive
stripCaseAndAccents and stripCaseAndAccentsWithPositions, with a
sourceIndex, replace foldText, foldTextWithOrigin and origin; the two
curried splitter helpers become one splitAtOccurrences and a closure
with three cases; the docs open with a worked example. No behaviour
change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 16:21 Inactive
rendersTheSame and reuseUnchanged name the row reuse across rebuilds,
pushChildSlots and pushResultPlaceholders say what they push, walkPruned
reads the filtered view from the closure instead of a parameter, and the
doc describes each mode in its own paragraph. No behaviour change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 16, 2026 16:32 Inactive
HendrikThePendric and others added 6 commits November 16, 2026 17:39
…hey could shrink

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ot or ancestors

A result with no shown root in its path, or with an ancestor the store
does not hold, breaks the tree endpoint's contract. Dropping it with a
dev-only warning hid the bug behind a tree that looked complete; the
throw names the result and the contract, and the app keeps running.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s not hold

Every id the walk lists comes from the store, so a missing one is a
bug; skipping it drew a tree with a branch quietly gone. walkPruned
takes the filtered view instead of guarding on it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… its children

'browse' named a mode, not how a node lists its children, and a node
listing all of them appears in both modes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…t filtered

The mode names are now the pair browse and search, the words the actions
and state already use; SearchView, searchView and the test file follow.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 17, 2026 15:38 Inactive
HendrikThePendric and others added 2 commits November 17, 2026 16:48
…does

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… part of the walk's input

View now names how a node lists its children; the search's slice of the
row walk's input is not a view of anything.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 17, 2026 15:57 Inactive
…of flattenRows

reuseUnchanged, nodeOf and the result placeholder rows need no walk
state, so they sit at module scope next to rendersTheSame; flattenRows
keeps only the mutually recursive walk over its accumulator.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 17, 2026 16:12 Inactive
HendrikThePendric and others added 2 commits November 17, 2026 17:37
…esult scrolls into view

A revealed node lists its children from children pages, so a child that
is a result on a page not received yet showed plain, a false non-match,
until a placeholder below the whole list came into view. Results arrive
in tree order, so the last received result always precedes such a child;
its row in view now requests the next page, a step ahead of the scroll.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…t page

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 17, 2026 16:42 Inactive
Changes and rows, browsing, searching, reveal and hover, loading what
scrolls into view, start. The two pure helpers, searchRowsInput and
sameStatus, move to module scope. No behaviour change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@HendrikThePendric HendrikThePendric changed the title feat(ou-tree): filtered mode: search input, pruned tree with paged results, highlighting and reveal feat(ou-tree): search mode: search input, pruned tree with paged results, highlighting and reveal Nov 17, 2026
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
5 New issues
4 New Code Smells (required ≤ 0)
1 New Bugs (required ≤ 0)
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@HendrikThePendric
HendrikThePendric merged commit 6961681 into feat/paged-org-unit-tree Nov 17, 2026
6 of 7 checks passed
@HendrikThePendric
HendrikThePendric deleted the feat/ou-tree-filtered-mode branch November 17, 2026 16:50
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 17, 2026 16:51 Inactive

This branch was previously deployed

1 inactive deployment
netlify — a0037b8c Deployed Nov 17, 2026 by dhis2-bot
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.

2 participants