Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions client/src/pages/SectorComplianceDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ import {
} from "lucide-react";

// Rendered inside DashboardLayout via App.tsx router
// ─── Sector compliance baseline scores (last audit cycle) ────────────────────
// TODO: migrate to DB-driven config (e.g. /api/trpc/sectorConfig.baselines)
// so scores update per audit cycle without redeploying.
const BASELINE_SCORES: Record<string, number> = {
fintech: 87,
healthcare: 92,
energy: 78,
insurance: 85,
telecom: 81,
};

// ─── Sector metadata ──────────────────────────────────────────────────────────
const SECTOR_META: Record<string, {
name: string;
Expand Down Expand Up @@ -243,6 +232,17 @@ export default function SectorComplianceDetail() {

const workersQuery = trpc.workers.status.useQuery(undefined, { refetchInterval: 30000 });

// Sector baseline (DB-driven — latest sector_benchmarks snapshot)
const benchmarkQuery = trpc.sectorBenchmarks.list.useQuery(
{ sector },
{ enabled: !!sector }
);
const baselineScore = (() => {
const rows = (benchmarkQuery.data ?? []) as Array<{ avg_compliance_score?: number | string }>;
const v = rows[0]?.avg_compliance_score;
return v != null && !Number.isNaN(Number(v)) ? Math.round(Number(v)) : null;
})();

// ── Resolve active query ─────────────────────────────────────────────────
type EntityRow = Record<string, unknown>;
let entities: EntityRow[] = [];
Expand Down Expand Up @@ -371,8 +371,8 @@ export default function SectorComplianceDetail() {
<div className="text-xs text-muted-foreground mb-1">Compliance Score</div>
<div className="text-3xl font-bold text-foreground">{score}%</div>
<Progress value={score} className="mt-2 h-1.5" />
{BASELINE_SCORES[sector] && (
<div className="text-xs text-muted-foreground mt-1">Baseline: {BASELINE_SCORES[sector]}%</div>
{baselineScore != null && (
<div className="text-xs text-muted-foreground mt-1">Sector baseline: {baselineScore}%</div>
)}
</CardContent>
</Card>
Expand Down
9 changes: 6 additions & 3 deletions server/phase21.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ describe("SectorComplianceDetail page", () => {
expect(c).toContain("trpc.insurance.listCompanies.useQuery");
expect(c).toContain("trpc.telecom.listOperators.useQuery");
});
it("shows compliance score per sector", () => {
it("sources the sector baseline from the DB (sectorBenchmarks), not hardcoded scores", () => {
const c = fs.readFileSync(detailPath, "utf-8");
expect(c).toContain("fintech: 87");
expect(c).toContain("healthcare: 92");
expect(c).toContain("trpc.sectorBenchmarks.list.useQuery");
expect(c).toContain("avg_compliance_score");
// Guard against reintroducing the old hardcoded baseline map
expect(c).not.toContain("fintech: 87");
expect(c).not.toContain("BASELINE_SCORES");
});
it("has pagination controls", () => {
const c = fs.readFileSync(detailPath, "utf-8");
Expand Down
Loading