brackt/app/routes/admin.tsx
Chris Parsons e5295812f6
Formalize simulator system with manifest, input-policy, runner, and admin UI (#409)
Introduces three new schema tables (simulator_profiles,
sports_season_simulator_configs, season_participant_simulator_inputs),
a central model layer (app/models/simulator.ts), and a single runner
entry point so every simulator run follows the same prepare → simulate
→ persist → snapshot → recalculate flow.

Key additions:
- manifest.ts: per-simulator display names, default configs, required/
  optional inputs, derivable-input declarations, and setup sections
- input-policy.ts: resolves sourceElo from projectedWins,
  projectedTablePoints, or sourceOdds; resolves ratings from sourceOdds;
  supports block / fallbackElo / averageKnown / worstKnownMinus strategies
- runner.ts: single entry point for admin simulation runs; materialises
  derived inputs, normalises result columns, zeroes omitted participants,
  snapshots EVs, and recalculates linked fantasy standings
- /admin/simulators: inventory page with per-season readiness and bulk run
- /admin/sports-seasons/:id/simulator: per-season setup page with readiness
  summary, input-policy editor, raw JSON config override, and CSV bulk input
- NCAAM/NCAAW simulators now read ratings from season_participant_simulator_inputs,
  falling back to the hardcoded name-keyed maps while DB data is being populated
- Clone flow copies simulator config by default; volatile inputs (odds, Elo)
  only copied when explicitly requested

Code-review fixes included in this commit:
- source field in compatibility bridge checked with !== null instead of !== undefined
- sourceEloRequirementLabel no longer appends "configured fallback" when the
  participant is already excluded from all resolved sources
- Duplicate inline label maps in input-policy.ts replaced with simulatorInputLabel
- save-config preserves existing inputPolicy when the submitted JSON omits it
- Input table truncation label added (Showing 20 of N)
- CSV description notes values must not contain commas
- N+1 comment added to listSportsSeasonSimulatorSummaries
- assertRegistrySchemaDriftFree called in manifest tests
- Runner test suite added covering happy path, already-running guard,
  readiness failure, empty results, and error recovery with status reset

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 21:09:53 -07:00

98 lines
2.9 KiB
TypeScript

import { Link, Outlet, redirect } from "react-router";
import { auth } from "~/lib/auth.server";
import type { Route } from "./+types/admin";
import { isUserAdmin } from "~/models/user";
import { Button } from "~/components/ui/button";
import {
LayoutDashboard,
Trophy,
Calendar,
FolderKanban,
RefreshCw,
Award,
Activity,
} from "lucide-react";
export function meta(): Route.MetaDescriptors {
return [{ title: "Admin - Brackt" }];
}
export async function loader(args: Route.LoaderArgs) {
const session = await auth.api.getSession({ headers: args.request.headers });
const userId = session?.user.id ?? null;
if (!userId) {
throw redirect("/");
}
const isAdmin = await isUserAdmin(userId);
if (!isAdmin) {
throw redirect("/");
}
return { isAdmin };
}
export default function AdminLayout() {
return (
<div className="flex min-h-screen">
{/* Sidebar */}
<aside className="w-64 border-r bg-muted/40">
<div className="flex h-16 items-center border-b px-6">
<h2 className="text-lg font-semibold">Admin Panel</h2>
</div>
<nav className="space-y-1 p-4">
<Button variant="ghost" className="w-full justify-start" asChild>
<Link to="/admin">
<LayoutDashboard className="mr-2 h-4 w-4" />
Dashboard
</Link>
</Button>
<Button variant="ghost" className="w-full justify-start" asChild>
<Link to="/admin/sports">
<Trophy className="mr-2 h-4 w-4" />
Sports
</Link>
</Button>
<Button variant="ghost" className="w-full justify-start" asChild>
<Link to="/admin/sports-seasons">
<Calendar className="mr-2 h-4 w-4" />
Sports Seasons
</Link>
</Button>
<Button variant="ghost" className="w-full justify-start" asChild>
<Link to="/admin/simulators">
<Activity className="mr-2 h-4 w-4" />
Simulators
</Link>
</Button>
<Button variant="ghost" className="w-full justify-start" asChild>
<Link to="/admin/tournaments">
<Award className="mr-2 h-4 w-4" />
Tournaments
</Link>
</Button>
<Button variant="ghost" className="w-full justify-start" asChild>
<Link to="/admin/templates">
<FolderKanban className="mr-2 h-4 w-4" />
Season Templates
</Link>
</Button>
<div className="border-t my-2" />
<Button variant="ghost" className="w-full justify-start" asChild>
<Link to="/admin/data-sync">
<RefreshCw className="mr-2 h-4 w-4" />
Data Sync
</Link>
</Button>
</nav>
</aside>
{/* Main Content */}
<main className="flex-1">
<Outlet />
</main>
</div>
);
}