-
Notifications
You must be signed in to change notification settings - Fork 0
Search: make universal results mode-aware #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d0dcf8c
feat(search): make universal search mode-aware
BigSimmo d5cd9b3
Merge remote-tracking branch 'origin/main' into codex/universal-searc…
BigSimmo 01f587d
Merge remote-tracking branch 'origin/main' into codex/universal-searc…
BigSimmo e53686c
fix(search): close results sheet on page scroll
BigSimmo b036632
fix(search): address mode-aware result review findings
BigSimmo 33d5638
Merge remote-tracking branch 'origin/main' into codex/universal-searc…
BigSimmo 4395a97
fix(search): keep answer results ahead of cross-mode matches
BigSimmo 7fe8ab6
fix(search): avoid hidden submitted-result requests
BigSimmo 5b4b604
fix(search): align medication shortcut counts
BigSimmo 3adcc6a
chore: start merge conflict resolution
Copilot 423075c
Changes before error encountered
Copilot 9876295
Merge remote-tracking branch 'origin/main' into codex/universal-searc…
BigSimmo 16e2078
Merge remote-tracking branch 'origin/codex/universal-search-mode-rank…
BigSimmo e265228
fix: continue merge conflict resolution - add missing specifiers stub…
Copilot d77c2b7
fix(search): retain formulation as the canonical mode
BigSimmo 972d45e
Merge remote-tracking branch 'origin/codex/universal-search-mode-rank…
BigSimmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/components/clinical-dashboard/universal-search-also-matches.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| "use client"; | ||
|
|
||
| import Link from "next/link"; | ||
|
|
||
| import { useUniversalSearch } from "@/components/clinical-dashboard/use-universal-search"; | ||
| import { cn } from "@/components/ui-primitives"; | ||
| import { appModeDefinition, appModeHomeHref, type AppModeId } from "@/lib/app-modes"; | ||
| import { appModeIcons } from "@/lib/app-mode-icons"; | ||
| import { universalSearchModeForDomain } from "@/lib/universal-search-mode-context"; | ||
|
|
||
| export function UniversalSearchAlsoMatches({ | ||
| modeId, | ||
| query, | ||
| className, | ||
| }: { | ||
| modeId: AppModeId; | ||
| query: string; | ||
| className?: string; | ||
| }) { | ||
| const trimmedQuery = query.trim(); | ||
| const universal = useUniversalSearch({ | ||
| query: trimmedQuery, | ||
| enabled: trimmedQuery.length >= 2, | ||
| contextMode: modeId, | ||
| limitPerDomain: 2, | ||
| }); | ||
| const preferred = new Set(universal.preferredDomains ?? []); | ||
| const groups = (() => { | ||
| const groupByDomain = new Map(universal.groups.map((group) => [group.kind, group])); | ||
| const orderedGroups = (universal.domainOrder ?? universal.groups.map((group) => group.kind)) | ||
| .map((domain) => groupByDomain.get(domain)) | ||
| .filter((group): group is NonNullable<typeof group> => | ||
| Boolean(group && !preferred.has(group.kind) && group.items.length > 0), | ||
| ); | ||
| const byMode = new Map< | ||
| AppModeId, | ||
| { modeId: AppModeId; items: Array<(typeof universal.groups)[number]["items"][number]> } | ||
| >(); | ||
|
|
||
| for (const group of orderedGroups) { | ||
| const targetModeId = universalSearchModeForDomain(group.kind); | ||
| if (targetModeId === modeId) continue; | ||
| const modeGroup = byMode.get(targetModeId) ?? { modeId: targetModeId, items: [] }; | ||
| for (const item of group.items) { | ||
| if (modeGroup.items.length >= 2) break; | ||
| if (!modeGroup.items.some((existing) => existing.href === item.href)) modeGroup.items.push(item); | ||
| } | ||
| byMode.set(targetModeId, modeGroup); | ||
| } | ||
|
|
||
| return [...byMode.values()].filter((group) => group.items.length > 0).slice(0, 4); | ||
| })(); | ||
|
|
||
| if (universal.query !== trimmedQuery || groups.length === 0) return null; | ||
|
|
||
| return ( | ||
| <section | ||
| className={cn( | ||
| "basis-full rounded-lg border border-[color:var(--border)] bg-[color:var(--surface-subtle)] p-2.5", | ||
| className, | ||
| )} | ||
| aria-label="Matches in other modes" | ||
| data-testid="universal-also-matches" | ||
| > | ||
| <div className="mb-2 flex items-center justify-between gap-3 px-1"> | ||
| <p className="text-xs font-extrabold text-[color:var(--text-heading)]">Also matches in other modes</p> | ||
| <span className="text-2xs font-bold text-[color:var(--text-soft)]">Across Clinical KB</span> | ||
| </div> | ||
| <div className="grid gap-1 sm:grid-cols-2 xl:grid-cols-4"> | ||
| {groups.map((group) => { | ||
| const targetModeId = group.modeId; | ||
| const targetMode = appModeDefinition(targetModeId); | ||
| const TargetIcon = appModeIcons[targetModeId]; | ||
| return ( | ||
| <div | ||
| key={targetModeId} | ||
| className="flex min-w-0 items-start gap-2 rounded-lg border border-[color:var(--border)] bg-[color:var(--surface)] p-2" | ||
| > | ||
| <span className="grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-[color:var(--clinical-accent-soft)] text-[color:var(--clinical-accent)]"> | ||
| <TargetIcon className="h-4 w-4" aria-hidden /> | ||
| </span> | ||
| <span className="min-w-0 flex-1 space-y-0.5"> | ||
| <span className="block truncate text-2xs font-bold uppercase tracking-wide text-[color:var(--clinical-accent)]"> | ||
| {targetMode.label} | ||
| </span> | ||
| {group.items.map((item) => ( | ||
| <Link | ||
| key={item.href} | ||
| href={item.href} | ||
| className="block truncate text-xs font-extrabold text-[color:var(--text)] hover:underline" | ||
| > | ||
| {item.title} | ||
| </Link> | ||
| ))} | ||
| </span> | ||
| <Link | ||
| href={appModeHomeHref(targetModeId, { query: trimmedQuery, run: true })} | ||
| className="shrink-0 text-2xs font-bold text-[color:var(--text-muted)] hover:text-[color:var(--clinical-accent)]" | ||
| > | ||
| View all | ||
| </Link> | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.