Skip to main content

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​

GroupSourceWhere a result goes
PagesThe sidebar's destinations (sidebar-nav.tsx) and the account menu's (account-menu.tsx)The page
Actionsaction-candidates.ts: data export, migration from the old enode Pro app, roster uploadStarts the task (its drawer)
SettingsThe generated settings index (settings-index.generated.ts)The settings page and tab, scrolled to the setting's row
UsersThe users store (useUsers)Users page searching the name
ExercisesThe exercises store (useExercises), by display nameExercises page searching the name
WorkoutsThe workout templates store (useTemplates)Workouts page searching the name
TagsThe 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, featureMigration plus the owner role, and featureUserBatchUpload plus 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).

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):

ResultRelated pages
PersonHistory (their sessions), Planner (their plan), Profiles
ExerciseHistory (its sessions), Profiles
TagHistory (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:

  1. removes find from the address (Back and reload do not scroll again);
  2. waits up to six seconds for the setting to appear (data may load first);
  3. finds the row by its data-find anchor, else by its translated label;
  4. 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.tsx under 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; mirror dashboard/layout.tsx.
CommandWhat it does
npm run search:indexWrites settings-index.generated.ts: the settings index and the page keywords (about 5 s)
npm run search:index:checkFails 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​

TestWhat it covers
search-rank.test.ts, settings-index.test.ts, entity-candidates.test.ts, action-candidates.test.ts, global-search-hotkey.test.tsRanking, places, visibility, related links, tasks, the shortcut
scripts/search-index/build-index.test.tsThe generator's rules (labels, chrome, rows, visibility, catalogue net)
tests/demo/global-search.spec.tsThe real portal (demo build): opening, pages, a setting's jump, tasks, rows, related pages