PCB_agentic_ai / frontend /src /components /ValidationPanel.tsx
mindchainai's picture
AI guide chatbot, simplified toolbar, KiCad 10 import with pours, exact outlines and hole rules
3fa1554 verified
Raw History Blame Contribute Delete
3.91 kB
import { AlertTriangle, CheckCircle2, ShieldCheck, XCircle } from 'lucide-react'
import { useState } from 'react'
import type { Design, Issue } from '../types/pcb'
import { EmptyNote } from './ui'
interface Props {
design: Design
selectedIssue: Issue | null
onSelectIssue: (i: Issue) => void
}
export function ValidationPanel({ design, selectedIssue, onSelectIssue }: Props) {
const v = design.validation
const [sev, setSev] = useState<'all' | 'error' | 'warning'>('all')
if (!v) return <EmptyNote icon={<ShieldCheck size={28} />} title="Not checked yet">The DRC runs automatically once the board is generated or imported.</EmptyNote>
const issues = v.issues.filter((i) => i.severity !== 'info' && (sev === 'all' || i.severity === sev))
return (
<div className="flex h-full min-h-0 flex-col">
<div className="p-3">
<div className="flex items-center gap-2">
<span className="panel-title">DRC results</span>
<span className="flex-1" />
<span className={`rounded px-2 py-0.5 text-[11px] font-semibold ${v.errors ? 'bg-bad/15 text-bad' : v.warnings ? 'bg-warn/15 text-warn' : 'bg-ok/15 text-ok'}`}>
{v.errors ? 'FAIL' : v.warnings ? 'PASS with warnings' : 'PASS'}
</span>
</div>
<ul className="mt-2 space-y-1 font-mono text-[12.5px]" aria-label="DRC checks">
{v.checks.map((c) => (
<li key={c.check} className="flex items-start gap-2">
{c.status === 'pass' ? <CheckCircle2 size={14} className="mt-0.5 shrink-0 text-ok" />
: c.status === 'warn' ? <AlertTriangle size={14} className="mt-0.5 shrink-0 text-warn" />
: <XCircle size={14} className="mt-0.5 shrink-0 text-bad" />}
<span className={c.status === 'pass' ? 'text-ink-200' : c.status === 'warn' ? 'text-amber-200' : 'text-red-200'}>{c.summary}</span>
</li>
))}
</ul>
</div>
<div className="flex items-center gap-1 border-t border-ink-700 px-2 py-1.5">
<span className="panel-title px-1">Issues</span>
<span className="flex-1" />
{(['all', 'error', 'warning'] as const).map((s) => (
<button key={s} type="button" onClick={() => setSev(s)} aria-pressed={sev === s}
className={`rounded border px-2 py-0.5 text-[11px] ${sev === s ? 'border-accent bg-accent/10 text-accent' : 'border-ink-600 text-ink-300 hover:bg-ink-800'}`}>
{s === 'all' ? `all ${v.errors + v.warnings}` : s === 'error' ? `errors ${v.errors}` : `warnings ${v.warnings}`}
</button>
))}
</div>
<ul className="min-h-0 flex-1 overflow-y-auto px-1 pb-2">
{issues.map((i) => (
<li key={i.id}>
<button type="button" onClick={() => onSelectIssue(i)}
className={`flex w-full items-start gap-2 rounded px-2 py-1.5 text-left text-[12px] hover:bg-ink-800 ${selectedIssue?.id === i.id ? 'bg-ink-800 ring-1 ring-accent/40' : ''}`}>
{i.severity === 'error' ? <XCircle size={13} className="mt-0.5 shrink-0 text-bad" /> : <AlertTriangle size={13} className="mt-0.5 shrink-0 text-warn" />}
<span className="min-w-0 flex-1">
<span className="text-ink-100">{i.message}</span>
<span className="block text-[10.5px] text-ink-500">
{i.check}{i.layer ? ` · ${i.layer}` : ''}{i.x !== null && i.y !== null ? ` · (${i.x.toFixed(2)}, ${i.y.toFixed(2)})` : ''}
</span>
</span>
</button>
</li>
))}
{!issues.length && (
<EmptyNote icon={<ShieldCheck size={26} />} title={sev === 'all' ? 'No DRC issues' : `No ${sev}s`}>
Every check passed on the current geometry.
</EmptyNote>
)}
</ul>
</div>
)
}