"use client"; import { useState } from "react"; import { trpc } from "~/lib/trpc/client.js"; import type { WidgetProps } from "~/components/dashboard/widget-registry.js"; import { InfoTooltip } from "~/components/ui/InfoTooltip.js"; type SortKey = "eid" | "name" | "chapter" | "score" | "lcr"; export function TopValueWidget({ config }: WidgetProps) { const limit = (config.limit as number) || 10; const [sortKey, setSortKey] = useState("score"); const [sortDir, setSortDir] = useState<"asc" | "desc">("desc"); function toggleSort(key: SortKey) { if (sortKey === key) setSortDir((d) => (d === "asc" ? "desc" : "asc")); else { setSortKey(key); setSortDir(key === "score" ? "desc" : "asc"); } } const { data, isLoading } = trpc.dashboard.getTopValueResources.useQuery( { limit }, { staleTime: 60_000, placeholderData: (prev) => prev }, ); if (isLoading) { return (
{[...Array(8)].map((_, i) => (
))}
); } const list = data ?? []; if (list.length === 0) { return (

No scores computed yet or you lack access.

Admins can recompute scores in Settings.

); } const sorted = [...list].sort((a, b) => { const mult = sortDir === "asc" ? 1 : -1; switch (sortKey) { case "eid": return mult * a.eid.localeCompare(b.eid); case "name": return mult * a.displayName.localeCompare(b.displayName); case "chapter": return mult * (a.chapter ?? "").localeCompare(b.chapter ?? ""); case "score": return mult * ((a.valueScore ?? 0) - (b.valueScore ?? 0)); case "lcr": return mult * (a.lcrCents - b.lcrCents); default: return 0; } }); function Ind({ k }: { k: SortKey }) { return sortKey === k ? {sortDir === "asc" ? "▲" : "▼"} : ; } return (
{sorted.map((r, i) => ( ))}
# Composite price/quality score 0–100.
Weights: Skill Depth 30% · Cost Efficiency 25% · Skill Breadth 15% · Chargeability 15% · Experience 15%.
Recompute in Admin → Settings.
} width="w-72" />
{i + 1} {r.eid} {r.displayName} {r.chapter ?? "—"} = 70 ? "bg-green-100 text-green-700" : (r.valueScore ?? 0) >= 40 ? "bg-amber-100 text-amber-700" : "bg-red-100 text-red-700" }`} > {r.valueScore ?? "—"} {(r.lcrCents / 100).toFixed(0)}
); }