|
1 | 1 | import type { DeviceToolVersions as ToolVersions } from "@t3tools/contracts"; |
2 | 2 | import { Popover, PopoverPopup, PopoverTitle, PopoverTrigger } from "~/components/ui/popover"; |
3 | 3 |
|
4 | | -export function DeviceToolVersions({ tools }: { tools: ToolVersions | undefined }) { |
| 4 | +export function DeviceToolVersions({ |
| 5 | + tools, |
| 6 | + kind, |
| 7 | +}: { |
| 8 | + tools: ToolVersions | undefined; |
| 9 | + kind?: keyof ToolVersions; |
| 10 | +}) { |
| 11 | + const selected = kind ? tools?.[kind] : undefined; |
| 12 | + const version = |
| 13 | + selected?.runningVersion ?? |
| 14 | + (selected?.installedVersions.includes(selected.requiredVersion) |
| 15 | + ? selected.requiredVersion |
| 16 | + : selected?.installedVersions |
| 17 | + .toSorted((a, b) => a.localeCompare(b, undefined, { numeric: true })) |
| 18 | + .at(-1)); |
| 19 | + const label = kind === "hub" ? "Device hub" : "Agent device"; |
5 | 20 | return ( |
6 | 21 | <Popover> |
7 | | - <PopoverTrigger className="rounded text-xs text-muted-foreground underline decoration-muted-foreground/40 underline-offset-4 hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"> |
8 | | - Versions |
| 22 | + <PopoverTrigger |
| 23 | + aria-label={ |
| 24 | + kind |
| 25 | + ? `${label}: ${version ? `version ${version}` : selected ? "not installed" : "version unknown"}. Show details` |
| 26 | + : undefined |
| 27 | + } |
| 28 | + className="rounded text-xs text-muted-foreground underline decoration-muted-foreground/40 underline-offset-4 hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring" |
| 29 | + > |
| 30 | + {kind |
| 31 | + ? version |
| 32 | + ? `v${version}` |
| 33 | + : selected |
| 34 | + ? "Not installed" |
| 35 | + : "Version unknown" |
| 36 | + : "Versions"} |
9 | 37 | </PopoverTrigger> |
10 | 38 | <PopoverPopup align="end" className="w-80"> |
11 | | - <PopoverTitle className="text-sm">Device tools</PopoverTitle> |
| 39 | + <PopoverTitle className="text-sm">{kind ? label : "Device tools"}</PopoverTitle> |
12 | 40 | {tools ? ( |
13 | 41 | <div className="mt-4 divide-y divide-border/50"> |
14 | 42 | {( |
15 | 43 | [ |
16 | 44 | ["Device hub", tools.hub], |
17 | 45 | ["Agent device", tools.agent], |
18 | 46 | ] as const |
19 | | - ).map(([name, tool]) => ( |
20 | | - <div key={name} className="space-y-2 py-3 first:pt-0 last:pb-0"> |
21 | | - <p className="text-xs font-medium">{name}</p> |
22 | | - <dl className="grid grid-cols-[auto_1fr] gap-x-6 gap-y-1 text-xs"> |
23 | | - <dt className="text-muted-foreground">Running</dt> |
24 | | - <dd className="text-right font-mono">{tool.runningVersion ?? "Not running"}</dd> |
25 | | - <dt className="text-muted-foreground">Required</dt> |
26 | | - <dd className="text-right font-mono">{tool.requiredVersion}</dd> |
27 | | - <dt className="text-muted-foreground">Installed</dt> |
28 | | - <dd className="text-right font-mono break-words"> |
29 | | - {tool.installedVersions.join(", ") || "None"} |
30 | | - </dd> |
31 | | - </dl> |
32 | | - </div> |
33 | | - ))} |
| 47 | + ) |
| 48 | + .filter(([name]) => !kind || name === label) |
| 49 | + .map(([name, tool]) => ( |
| 50 | + <div key={name} className="space-y-2 py-3 first:pt-0 last:pb-0"> |
| 51 | + <p className="text-xs font-medium">{name}</p> |
| 52 | + <dl className="grid grid-cols-[auto_1fr] gap-x-6 gap-y-1 text-xs"> |
| 53 | + <dt className="text-muted-foreground">Running</dt> |
| 54 | + <dd className="text-right font-mono">{tool.runningVersion ?? "Not running"}</dd> |
| 55 | + <dt className="text-muted-foreground">Required</dt> |
| 56 | + <dd className="text-right font-mono">{tool.requiredVersion}</dd> |
| 57 | + <dt className="text-muted-foreground">Installed</dt> |
| 58 | + <dd className="text-right font-mono break-words"> |
| 59 | + {tool.installedVersions.join(", ") || "None"} |
| 60 | + </dd> |
| 61 | + </dl> |
| 62 | + </div> |
| 63 | + ))} |
34 | 64 | </div> |
35 | 65 | ) : ( |
36 | 66 | <p className="mt-3 text-xs text-muted-foreground">Versions have not been checked.</p> |
|
0 commit comments