Global search (portal)
The portal has one search for everything a coach looks for: pages, tasks, settings, people, exercises, workout templates and tags. It opens from the search field at the top of the sidebar or with ⌘K (macOS) / Ctrl+K (elsewhere) on any portal page. The decision behind it is ADR 0019.
What the search finds
| Group | Source | Where a result goes |
|---|---|---|
| Pages | The sidebar's destinations (sidebar-nav.tsx) and the account menu's (account-menu.tsx) | The page |
| Actions | action-candidates.ts: data export, migration from the old enode Pro app, roster upload | Starts the task (its drawer) |
| Settings | The generated settings index (settings-index.generated.ts) | The settings page and tab, scrolled to the setting's row |
| Users | The users store (useUsers) | Users page searching the name |
| Exercises | The exercises store (useExercises), by display name | Exercises page searching the name |
| Workouts | The workout templates store (useTemplates) | Workouts page searching the name |
| Tags | The tags store (getAllTags) | Tags page searching the name |
The stores load when the search opens, not on every page.
Portal only
The search is the portal's alone: its code lives in
apps/portal/src/components/global-search/ and every result is a portal
address. What the generator learns from source files — the catalogue net and
the page keywords — comes only from files under apps/portal/src/. A string
of a component the portal shares with the tracking app gets in only when the
portal actually rendered it, so app-only rows ("Only on this device") never
appear. A test of the generated index guards this.
Who sees which result
- Pages follow the sidebar:
useSidebarNav()is the one rule set for the sidebar and the search, so the search never offers a page the sidebar hides. - Actions use the same checks as their own buttons: the sidebar's export
button state,
featureMigrationplus the owner role, andfeatureUserBatchUploadplus access to the Users page. - Settings carry the roles and privileges the generator measured (see How the settings index stays current).
- People, exercises, workouts and tags appear only when the user can open their list page.
Matching and ranking
The rules live in search-rank.ts
and are pure:
- Case- and accent-insensitive; every word of the query must match the label, the detail line or a keyword.
- A label that starts with the word ranks first, then a word of the label that starts with it.
- Words of four characters or more also match inside a word and with a typo
(
editCap), so "trainig" finds "Training". Shorter words only match word starts. - Words outside the label must all match within one keyword: "end date" matches a page through its "End date", not through "End session" plus an unrelated "Date".
- The group with the best match comes first (equal groups in the order pages, actions, settings, users, exercises, workouts, tags), at most six results each.
- A result found only through a keyword names it on its second line ("Mentions “Calendar view”").
Pages are found by their own words
Every page has keywords: the labels, headings and screen-reader names of the
portal files the page is built from (its page.tsx and everything it
imports, transitively — its tour included). "calendar" finds the Planner through
"Calendar view" and "Your training calendar", with no synonym list to keep.
A word on three or more pages names nothing in particular and is left out.
The generator writes them as PAGE_KEYWORDS next to the settings index.
Tags as search terms
A person's, exercise's or workout's tags are keywords of its result and its second line: searching "push" also finds every exercise tagged Push.
One result per place
Results that land in the same place are shown once, as the best-matching one
(place on a candidate):
- a page and its first tab (Devices and its Recording tab);
- the labels of one settings row (a setting's name and its value);
- a group with one setting (a heading over one row): the setting names the result and the heading is a keyword, so "ani" finds "Show animations", not its group "Display";
- things with the same name on the same list (a catalogue exercise and the athletes' own copies of it).
Related pages
A person, exercise or tag result offers the same thing on other pages, as buttons on the active result (→ / ← with the keyboard, Enter to open):
| Result | Related pages |
|---|---|
| Person | History (their sessions), Planner (their plan), Profiles |
| Exercise | History (its sessions), Profiles |
| Tag | History (sessions with the tag), Planner |
Every address is one the target page already reads (view state in the address, ADR 0017), so each page searches with its own rules — History with its server search.
Jumping to a setting
A settings result opens <page>?find=<key>, where key is the i18n content
hash of the setting's label. FindTargetScroller,
mounted once in the app shell:
- removes
findfrom the address (Back and reload do not scroll again); - waits up to six seconds for the setting to appear (data may load first);
- finds the row by its
data-findanchor, else by its translated label; - scrolls it to the centre of the page.
The row is not highlighted: a flash over rows and cards of every shape did not look clean everywhere, so the jump alone marks the place.
A setting that never appears leaves the page as it is.
How the settings index stays current
Nobody writes settings entries by hand. The generator
(scripts/search-index/generate.run.tsx,
rules in build-index.ts) renders every page under
/dashboard/settings, /dashboard/account, /dashboard/devices and
/dashboard/help with the real components and records each t(...) call:
- Pages and tabs are found by themselves: every
page.tsxunder those routes, plus the tabs and sub-pages the pages link to (?page=…,?view=…). A page that only forwards is skipped. - Visibility is measured, not written down: the pages render once per role of the demo's role catalogue and once per privilege left out of the owner's set (split in halves, so a page costs a dozen renders, not forty). An entry records the roles that saw it and the privileges whose removal hid it.
- Page chrome is left out: a label most pages of a group show (the tab row, a scope note) is not a setting, except as its own page's tab.
- The catalogue net: a label of a portal file only one page renders that no render showed (data loaded in an effect) is still kept for that page, with unknown visibility, ranked after the rendered entries.
- A page that cannot render fails the run with React's error, never
quietly. A "must be used inside …" error means the page needs a provider
that
renderTree()does not set up yet; mirrordashboard/layout.tsx.
| Command | What it does |
|---|---|
npm run search:index | Writes settings-index.generated.ts: the settings index and the page keywords (about 5 s) |
npm run search:index:check | Fails when the committed index is stale |
The shared pre-commit hook (.githooks/pre-commit)
runs search:index whenever a commit touches portal, shared-UI or core
source, and adds the index to the commit when it changed. It never blocks;
skip it once with SKIP_SEARCH_INDEX=1.
TODO: The generator renders on the server, so effects do not run: settings a
page only loads in an effect (the notification topics, the live display's
metrics) come from the catalogue net with unknown visibility. Rendering with a
DOM environment (happy-dom) and the demo backend would measure them too; it
needs the dev dependency approved.
Look
- Brand colour and greys only: icon tiles are grey; the active result's tile turns red-orange, together with an orange crescent along the row's front (an orange rounded rectangle under the grey one, which sits 3 px to the right; the orange one only spans the front curve, so the right corners stay clean) and the matched part of each label.
- The active result switches without a transition.
- Key hints use arrow icons, not text arrows, so they sit centred in the key.
- Related pages are pill buttons on the active result only; the one chosen with → is inverted.
- The field has no focus ring; the red-orange caret marks it.
Tests
| Test | What it covers |
|---|---|
search-rank.test.ts, settings-index.test.ts, entity-candidates.test.ts, action-candidates.test.ts, global-search-hotkey.test.ts | Ranking, places, visibility, related links, tasks, the shortcut |
scripts/search-index/build-index.test.ts | The generator's rules (labels, chrome, rows, visibility, catalogue net) |
tests/demo/global-search.spec.ts | The real portal (demo build): opening, pages, a setting's jump, tasks, rows, related pages |