45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
|||
|
|
|
||
|
|
export interface DeviceUsageRow {
|
||
|
|
deviceId: number;
|
||
|
|
displayName: string | null;
|
||
|
|
bleName: string;
|
||
|
|
sessionCount: number;
|
||
|
|
totalActiveMs: number;
|
||
|
|
commandCount: number;
|
||
|
|
lastUsedAt: number | null;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function DeviceUsageTable({ devices }: { devices: DeviceUsageRow[] }) {
|
||
|
|
if (devices.length === 0) {
|
||
|
|
return <p className="text-sm text-muted-foreground">No device activity yet.</p>;
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Table>
|
||
|
|
<TableHeader>
|
||
|
|
<TableRow>
|
||
|
|
<TableHead>Device</TableHead>
|
||
|
|
<TableHead>Sessions</TableHead>
|
||
|
|
<TableHead>Active time</TableHead>
|
||
|
|
<TableHead>Commands</TableHead>
|
||
|
|
<TableHead>Last used</TableHead>
|
||
|
|
</TableRow>
|
||
|
|
</TableHeader>
|
||
|
|
<TableBody>
|
||
|
|
{devices.map((d) => (
|
||
|
|
<TableRow key={d.deviceId}>
|
||
|
|
<TableCell className="font-medium">{d.displayName ?? d.bleName}</TableCell>
|
||
|
|
<TableCell>{d.sessionCount}</TableCell>
|
||
|
|
<TableCell>{(d.totalActiveMs / 60_000).toFixed(1)}m</TableCell>
|
||
|
|
<TableCell>{d.commandCount}</TableCell>
|
||
|
|
<TableCell className="text-muted-foreground">
|
||
|
|
{d.lastUsedAt ? new Date(d.lastUsedAt).toLocaleString() : "Never"}
|
||
|
|
</TableCell>
|
||
|
|
</TableRow>
|
||
|
|
))}
|
||
|
|
</TableBody>
|
||
|
|
</Table>
|
||
|
|
);
|
||
|
|
}
|