Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 130 additions & 61 deletions src/components/clinical-dashboard/favourites-command-library-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Heart,
MoreVertical,
Pill,
Pin,
Quote,
Search,
ShieldCheck,
Expand All @@ -24,6 +25,7 @@ import { useMemo, useRef, useState } from "react";

import {
FavouritesMobileBrowseRail,
FavouritesMobileQuickViews,
FavouritesSidebar,
useFavouritesNavCollapsed,
type FavouritesViewMode,
Expand Down Expand Up @@ -237,14 +239,23 @@ function filterAndSortItems(
});
}

function MiniIconTile({ icon: Icon, active = false }: { icon: LucideIcon; active?: boolean }) {
function MiniIconTile({
icon: Icon,
active = false,
className,
}: {
icon: LucideIcon;
active?: boolean;
className?: string;
}) {
return (
<span
className={cn(
"grid h-9 w-9 shrink-0 place-items-center rounded-lg border",
active
? "border-[color:var(--clinical-accent-border)] bg-[color:var(--clinical-accent-soft)] text-[color:var(--clinical-accent)]"
: "border-[color:var(--border)] bg-[color:var(--surface)] text-[color:var(--text-muted)]",
className,
)}
>
<Icon className="h-4 w-4" aria-hidden />
Expand Down Expand Up @@ -457,7 +468,7 @@ function FavouriteMobileCard({
<article
data-testid={`favourite-mobile-card-${item.id}`}
className={cn(
"relative min-w-0 max-w-full rounded-lg border bg-[color:var(--surface)] p-3 shadow-[var(--shadow-tight)]",
"relative min-w-0 max-w-full rounded-xl border bg-[color:var(--surface)] p-3 shadow-[var(--shadow-tight)]",
selected
? "border-[color:var(--clinical-accent-border)] bg-[color:var(--clinical-accent-soft)]/35 shadow-[inset_3px_0_0_var(--clinical-accent)]"
: "border-[color:var(--border)]",
Expand All @@ -468,48 +479,64 @@ function FavouriteMobileCard({
onClick={() => onSelect(item.id)}
aria-pressed={selected}
aria-label={`Select ${item.title}`}
className={cn("absolute inset-0 cursor-pointer rounded-lg", focusRing)}
className={cn("absolute inset-0 cursor-pointer rounded-xl", focusRing)}
/>

<div className="pointer-events-none relative min-w-0">
<h3 className="line-clamp-2 text-sm-minus font-bold leading-5 text-[color:var(--text-heading)]">
{item.title}
</h3>
<p className="mt-1 line-clamp-2 text-2xs font-medium leading-4 text-[color:var(--text-muted)]">
{item.description}
</p>
<div className="mt-3 flex flex-wrap gap-1.5">
<div className="flex items-start gap-2.5">
<MiniIconTile icon={item.icon} active={selected} />
<div className="min-w-0 flex-1">
<div className="flex items-start gap-1.5">
{item.pinned ? (
<>
<Pin
className="mt-1 h-3 w-3 shrink-0 -rotate-45 fill-current text-[color:var(--clinical-accent)]"
aria-hidden
/>
<span className="sr-only">Pinned</span>
</>
) : null}
<h3 className="line-clamp-2 text-sm-minus font-bold leading-5 text-[color:var(--text-heading)]">
{item.title}
</h3>
</div>
<p className="mt-0.5 line-clamp-1 text-2xs font-medium leading-4 text-[color:var(--text-muted)]">
{item.description}
</p>
</div>
</div>

<div className="mt-2.5 flex flex-wrap items-center gap-1.5">
<SmallChip className={typeStyles[item.type]}>{item.type}</SmallChip>
{isSourceBacked(item) ? (
<SmallChip className="border-[color:var(--success-border)] bg-[color:var(--success-soft)] text-[color:var(--success)]">
<ShieldCheck className="h-3 w-3" aria-hidden />
Source-backed
</SmallChip>
) : null}
</div>
</div>

<dl className="pointer-events-none relative mt-3 grid gap-2 border-t border-[color:var(--border)] pt-3 text-2xs font-semibold">
<div className="flex min-w-0 items-center justify-between gap-3">
<dt className="inline-flex items-center gap-1.5 text-[color:var(--text-muted)]">
<Folder className="h-3.5 w-3.5" aria-hidden />
Set
</dt>
<dd className="min-w-0 truncate text-right text-[color:var(--text-heading)]">{item.set}</dd>
</div>
<div className="flex min-w-0 items-center justify-between gap-3">
<dt className="text-[color:var(--text-muted)]">Last used</dt>
<dd className="min-w-0 truncate text-right text-[color:var(--text-heading)]">{item.lastUsed}</dd>
<div className="mt-2.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-2xs font-semibold text-[color:var(--text-muted)]">
<span className="inline-flex min-w-0 items-center gap-1">
<Folder className="h-3.5 w-3.5 shrink-0" aria-hidden />
<span className="min-w-0 truncate text-[color:var(--text-heading)]">{item.set}</span>
</span>
<span className="text-[color:var(--text-soft)]" aria-hidden>
·
</span>
<span className="whitespace-nowrap text-[color:var(--text-heading)]">{item.lastUsed}</span>
</div>
</dl>
</div>

<div className="relative z-[1] mt-3 grid grid-cols-[minmax(0,1fr)_2.75rem] gap-2">
<Link
href={item.href}
className={cn(
"inline-flex h-tap min-w-0 items-center justify-center rounded-lg border border-[color:var(--clinical-accent-border)] bg-[color:var(--surface)] px-3 text-sm-minus font-bold text-[color:var(--clinical-accent)] hover:bg-[color:var(--clinical-accent-soft)]",
"inline-flex h-tap min-w-0 items-center justify-center gap-1.5 rounded-lg border border-[color:var(--clinical-accent-border)] bg-[color:var(--surface)] px-3 text-sm-minus font-bold text-[color:var(--clinical-accent)] hover:bg-[color:var(--clinical-accent-soft)]",
focusRing,
)}
>
<ExternalLink className="h-4 w-4" aria-hidden />
Open
</Link>
<RowActionsMenu item={item} />
Expand Down Expand Up @@ -553,11 +580,21 @@ function FavouritesTable({
return rows.filter((item) => favouriteMatchesCommandScopes(item, commandScopes));
}, [commandScopes, items, searchTerm, selectedSet, selectedTypeId, viewMode, sortMode]);

// With the item workspace open (only at 2xl), the middle column narrows sharply.
// Drop the leading icon and the secondary Evidence column there so titles keep
// room instead of collapsing to a couple of characters.
const compact = Boolean(selectedItemId);
const rowIconClass = compact ? "hidden" : "hidden 2xl:grid";
const evidenceHeadClass = cn("hidden px-3", compact ? "" : "w-[7rem] 2xl:table-cell");
const evidenceCellClass = cn("hidden px-3 align-middle", compact ? "" : "2xl:table-cell");

return (
<section className="min-w-0 max-w-full overflow-hidden rounded-lg border border-[color:var(--border)] bg-[color:var(--surface)] shadow-[var(--shadow-soft)]">
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-[color:var(--border)] px-3 py-2.5">
<p className="text-2xs font-semibold uppercase tracking-[0.06em] text-[color:var(--text-muted)]">
{tableRows.length} {tableRows.length === 1 ? "item" : "items"}
<section className="min-w-0 max-w-full overflow-hidden rounded-xl border border-[color:var(--border)] bg-[color:var(--surface)] shadow-[var(--shadow-soft)]">
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-[color:var(--border)] bg-[color:var(--surface-wash)] px-3.5 py-2.5">
<p className="inline-flex items-center gap-1.5 text-2xs font-semibold uppercase tracking-[0.06em] text-[color:var(--text-muted)]">
<Heart className="h-3.5 w-3.5 text-[color:var(--clinical-accent)]" aria-hidden />
<span className="nums font-bold text-[color:var(--text-heading)]">{tableRows.length}</span>
{tableRows.length === 1 ? "item" : "items"}
{tableRows.length !== items.length ? ` of ${items.length}` : ""}
</p>
<div className="flex flex-wrap items-center gap-2">
Expand All @@ -583,25 +620,25 @@ function FavouritesTable({
</div>

<div className="hidden overflow-x-auto sm:block">
<table aria-label="Saved favourites" className="min-w-[36rem] w-full border-collapse text-left">
<table aria-label="Saved favourites" className="w-full min-w-[34rem] table-fixed border-collapse text-left">
<thead>
<tr className="h-10 border-b border-[color:var(--border)] bg-[color:var(--surface)] text-2xs font-semibold uppercase tracking-[0.08em] text-[color:var(--text-muted)]">
<th scope="col" className="min-w-[12rem] px-3">
<tr className="h-9 border-b border-[color:var(--border)] bg-[color:var(--surface-wash)] text-2xs font-semibold uppercase tracking-[0.08em] text-[color:var(--text-muted)]">
<th scope="col" className="min-w-[11rem] px-3.5">
Item
</th>
<th scope="col" className="min-w-[6.5rem] px-3">
<th scope="col" className="w-[6rem] px-3">
Type
</th>
<th scope="col" className="min-w-[7rem] px-3">
<th scope="col" className="w-[7rem] px-3">
Set
</th>
<th scope="col" className="hidden min-w-[7rem] px-3 lg:table-cell">
<th scope="col" className={evidenceHeadClass}>
Evidence
</th>
<th scope="col" className="min-w-[6rem] px-3">
<th scope="col" className="w-[6.5rem] px-3">
Last used
</th>
<th scope="col" className="min-w-[7.5rem] px-3 text-right">
<th scope="col" className="w-[7.5rem] px-3 text-right">
Action
</th>
</tr>
Expand All @@ -620,18 +657,32 @@ function FavouritesTable({
"bg-[color:var(--clinical-accent-soft)]/45 shadow-[inset_3px_0_0_var(--clinical-accent)]",
)}
>
<td className="px-3 align-middle">
<td className="px-3.5 align-middle">
<button
type="button"
onClick={() => onSelectItem(item.id)}
aria-pressed={selected}
className={cn("min-w-0 max-w-full rounded-md text-left", focusRing)}
className={cn("flex min-w-0 max-w-full items-center gap-2.5 rounded-md text-left", focusRing)}
>
<span className="line-clamp-1 block text-sm-minus font-bold text-[color:var(--text-heading)]">
{item.title}
</span>
<span className="mt-0.5 line-clamp-1 block text-2xs font-medium text-[color:var(--text-muted)]">
{item.description}
<MiniIconTile icon={item.icon} active={selected} className={rowIconClass} />
<span className="flex min-w-0 flex-1 flex-col">
<span className="flex min-w-0 items-center gap-1.5">
{item.pinned ? (
<>
<Pin
className="h-3 w-3 shrink-0 -rotate-45 fill-current text-[color:var(--clinical-accent)]"
aria-hidden
/>
<span className="sr-only">Pinned</span>
</>
) : null}
<span className="line-clamp-1 min-w-0 text-sm-minus font-bold text-[color:var(--text-heading)]">
{item.title}
</span>
</span>
<span className="mt-0.5 line-clamp-1 text-2xs font-medium text-[color:var(--text-muted)]">
{item.description}
</span>
</span>
</button>
</td>
Expand All @@ -644,14 +695,22 @@ function FavouritesTable({
<span className="line-clamp-1">{item.set}</span>
</span>
</td>
<td className="hidden px-3 align-middle lg:table-cell">
<span className="inline-flex items-center gap-1.5 text-2xs font-semibold text-[color:var(--clinical-accent)]">
<ShieldCheck className="h-3.5 w-3.5 shrink-0" aria-hidden />
<span className="line-clamp-1">{item.evidence}</span>
</span>
<td className={evidenceCellClass}>
{isSourceBacked(item) ? (
<span className="inline-flex items-center gap-1.5 text-2xs font-semibold text-[color:var(--clinical-accent)]">
<ShieldCheck className="h-3.5 w-3.5 shrink-0" aria-hidden />
<span className="line-clamp-1">{item.evidence}</span>
</span>
) : (
<span className="inline-flex items-center gap-1.5 text-2xs font-semibold text-[color:var(--text-muted)]">
<span className="line-clamp-1">{item.evidence}</span>
</span>
)}
</td>
<td className="px-3 align-middle">
<span className="text-2xs font-semibold text-[color:var(--text-heading)]">{item.lastUsed}</span>
<span className="whitespace-nowrap text-2xs font-semibold text-[color:var(--text-heading)]">
{item.lastUsed}
</span>
</td>
<td className="px-3 align-middle" onClick={(event) => event.stopPropagation()}>
<div className="flex items-center justify-end gap-2">
Expand All @@ -672,10 +731,10 @@ function FavouritesTable({
})}
{tableRows.length === 0 ? (
<tr>
{/* The Evidence column is hidden below lg, so span 5 there and 6 at lg+. */}
{/* The Evidence column is hidden below 2xl, so span 5 there and 6 at 2xl+. */}
{[
{ colSpan: 5, className: "px-4 py-10 text-center lg:hidden" },
{ colSpan: 6, className: "hidden px-4 py-10 text-center lg:table-cell" },
{ colSpan: 5, className: "px-4 py-10 text-center 2xl:hidden" },
{ colSpan: 6, className: "hidden px-4 py-10 text-center 2xl:table-cell" },
].map(({ colSpan, className }) => (
<td key={colSpan} colSpan={colSpan} className={className}>
<Search className="mx-auto mb-2 h-5 w-5 text-[color:var(--text-soft)]" aria-hidden />
Expand Down Expand Up @@ -980,7 +1039,7 @@ export function FavouritesCommandLibraryPage({ query = "" }: { query?: string })
onSelectViewMode={setViewMode}
/>
<div className="min-w-0 overflow-x-hidden px-4 py-5 sm:px-6 lg:px-7">
<div className="mx-auto grid min-w-0 max-w-[66rem] gap-3">
<div className="mx-auto grid min-w-0 max-w-[66rem] gap-3 2xl:max-w-[72rem]">
<header>
<div className="flex min-w-0 items-start gap-3">
<span className="mt-1 grid h-8 w-8 shrink-0 place-items-center rounded-lg border border-[color:var(--clinical-accent-border)] bg-[color:var(--clinical-accent-soft)] text-[color:var(--clinical-accent)]">
Expand All @@ -1007,6 +1066,24 @@ export function FavouritesCommandLibraryPage({ query = "" }: { query?: string })
</div>
<UniversalSearchAlsoMatches modeId="favourites" query={query} />

<FavouritesMobileQuickViews
items={items}
selectedSetId={effectiveSelectedSetId}
selectedTypeId={selectedTypeId}
viewMode={viewMode}
onSelectSet={setSelectedSetId}
onSelectType={setSelectedTypeId}
onSelectViewMode={setViewMode}
/>

<FavouritesMobileBrowseRail
sets={sets}
selectedSetId={effectiveSelectedSetId}
viewMode={viewMode}
onSelectSet={setSelectedSetId}
onSelectViewMode={setViewMode}
/>

<ActiveFilterChips
searchTerm={query}
selectedTypeId={selectedTypeId}
Expand Down Expand Up @@ -1038,14 +1115,6 @@ export function FavouritesCommandLibraryPage({ query = "" }: { query?: string })
onSelectItem={setSelectedItemId}
/>
)}

<FavouritesMobileBrowseRail
sets={sets}
selectedSetId={effectiveSelectedSetId}
viewMode={viewMode}
onSelectSet={setSelectedSetId}
onSelectViewMode={setViewMode}
/>
</div>
</div>
{selectedItem ? <ItemWorkspace item={selectedItem} onClose={() => setSelectedItemId(null)} /> : null}
Expand Down
Loading
Loading