Download code/web/src/components/model-table.tsx from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 4.23 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/9a0cfd0a89e51b35a25d45ea178b2b5d18cb41ed/code/web/src/components/model-table.tsx
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@9a0cfd0a89e51b35a25d45ea178b2b5d18cb41ed/code/web/src/components/model-table.tsx
-
curl -L -o model-table.tsx https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/9a0cfd0a89e51b35a25d45ea178b2b5d18cb41ed/code/web/src/components/model-table.tsx
4.23 kB
| import { useMemo, useState } from "react" | |
| import { ArrowDown, ArrowUp, Search } from "lucide-react" | |
| import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" | |
| import { Input } from "@/components/ui/input" | |
| import { Button } from "@/components/ui/button" | |
| import { REL_NAME, type Author, type Repo } from "@/lib/types" | |
| import { num as fmt, hfUrl } from "@/lib/format" | |
| import { RelDot } from "@/components/rel" | |
| import { Who } from "@/components/who" | |
| type Key = "id" | "rel" | "dl30" | "dlall" | "d1" | |
| export function ModelTable({ repos, authors, hasDaily }: { repos: Repo[]; authors: Record<string, Author>; hasDaily: boolean }) { | |
| const [q, setQ] = useState("") | |
| const [sort, setSort] = useState<{ k: Key; dir: 1 | -1 }>({ k: "dl30", dir: -1 }) | |
| const [shown, setShown] = useState(20) | |
| const rows = useMemo(() => { | |
| const s = q.trim().toLowerCase() | |
| const list = s ? repos.filter((r) => r.id.toLowerCase().includes(s)) : repos | |
| return [...list].sort((a, b) => { | |
| const x = a[sort.k], y = b[sort.k] | |
| if (x == null || y == null) return (x == null ? 1 : 0) - (y == null ? 1 : 0) | |
| return (x < y ? -1 : x > y ? 1 : 0) * sort.dir | |
| }) | |
| }, [repos, q, sort]) | |
| const cols: [Key, string, boolean][] = [ | |
| ["id", "Model", false], ["rel", "Type", false], ["dl30", "30 days", true], ["dlall", "All-time", true], | |
| ...(hasDaily ? ([["d1", "Last day", true]] as [Key, string, boolean][]) : []), | |
| ] | |
| const head = (k: Key, label: string, num: boolean) => ( | |
| <TableHead key={k} className={`h-11 text-[15px] ${num ? "text-right" : ""}`}> | |
| <button className={`inline-flex items-center gap-1 text-muted-foreground hover:text-foreground ${sort.k === k ? "text-foreground" : ""}`} | |
| onClick={() => setSort((s) => ({ k, dir: s.k === k ? (-s.dir as 1 | -1) : -1 }))}> | |
| {label} | |
| {sort.k === k && (sort.dir < 0 ? <ArrowDown className="size-4" /> : <ArrowUp className="size-4" />)} | |
| </button> | |
| </TableHead> | |
| ) | |
| return ( | |
| <div> | |
| <div className="relative mb-4 max-w-sm"> | |
| <Search className="pointer-events-none absolute top-1/2 left-3.5 size-4 -translate-y-1/2 text-muted-foreground" /> | |
| <Input value={q} onChange={(e) => { setQ(e.target.value); setShown(20) }} placeholder="Search models or builders" | |
| className="h-11 rounded-full pl-10 text-[15px]" aria-label="Search models or builders" /> | |
| </div> | |
| <Table className="text-[15px]"> | |
| <TableHeader> | |
| <TableRow className="border-border/60 hover:bg-transparent">{cols.map(([k, l, n]) => head(k, l, n))}</TableRow> | |
| </TableHeader> | |
| <TableBody> | |
| {rows.slice(0, shown).map((r) => { | |
| const [owner, name] = r.id.split("/") | |
| return ( | |
| <TableRow key={r.id} className="border-border/60"> | |
| <TableCell className="py-3"> | |
| <a href={hfUrl(r.id)} target="_blank" rel="noopener" className="flex min-w-0 items-center gap-3 hover:underline"> | |
| <Who name={owner} authors={authors} size="size-7" /> | |
| <span className="max-w-[min(52vw,520px)] truncate" title={r.id}> | |
| <span className="text-muted-foreground">{owner}/</span>{name} | |
| </span> | |
| </a> | |
| </TableCell> | |
| <TableCell className="py-3 whitespace-nowrap"> | |
| <span className="inline-flex items-center gap-2"><RelDot rel={r.rel} />{REL_NAME[r.rel]}</span> | |
| </TableCell> | |
| <TableCell className="py-3 text-right tabular-nums">{fmt(r.dl30)}</TableCell> | |
| <TableCell className="py-3 text-right tabular-nums">{fmt(r.dlall)}</TableCell> | |
| {hasDaily && <TableCell className="py-3 text-right tabular-nums">{fmt(r.d1)}</TableCell>} | |
| </TableRow> | |
| ) | |
| })} | |
| </TableBody> | |
| </Table> | |
| {rows.length > shown && ( | |
| <div className="mt-5 flex justify-center"> | |
| <Button variant="secondary" className="h-10 rounded-full px-6 text-[15px]" onClick={() => setShown((n) => n + 50)}> | |
| Show 50 more | |
| </Button> | |
| </div> | |
| )} | |
| </div> | |
| ) | |
| } | |