Files
legal-ai/web-ui/src/components/graph/graph-node-panel.tsx
Chaim 9a126f7c36 feat(graph): research-gap (ghost) nodes (corpus graph PR C)
Turns the graph into a gap-finder: the 247 unresolved internal citations
(a corpus precedent cites a ruling NOT in the corpus) collapse to 230 distinct
"gap" nodes — each sized by how many corpus precedents cite it, i.e. the
most-wanted missing precedent.

Backend (web/graph_api.py — read-only, G2):
- "gap" added to VALID_NODE_TYPES (NOT default → off unless requested).
- New _gap_nodes_and_edges(): gap:<normalized citation> nodes from
  precedent_internal_citations WHERE cited_case_law_id IS NULL, sized by global
  in-degree; cites edges only from precedents present in the view (dangling-edge
  invariant holds). Best-effort enrichment from missing_precedents via exact
  normalized-citation match → gap_status + missing_precedent_id. Validated:
  230 gaps, top ע"א 3213/97 (cited 5×), 230/230 matched to missing_precedents.
- GraphNode += gap_status, missing_precedent_id. Metrics correctly exclude gap
  edges (target not a precedent). No app.py change (gated via node_types).

Frontend:
- graph.ts: GraphNodeType += "gap"; node fields.
- graph-filter-panel: toggle "חוסרי מחקר (פסיקה חסרה)" (off by default).
- graph-canvas: gaps render as faint hollow dashed circles, never recoloured
  by color-by; sized by citation count.
- graph-node-panel: gap branch — "מצוטטת ע״י N פסיקות" + status badge + link
  to /missing-precedents.

web-ui build + lint pass. Invariants: G2 (SELECT-only), UI2 (model grows on
explicit Pydantic). api:types post-deploy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 21:21:53 +00:00

138 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
/**
* Side panel shown when a node is selected. For precedent/halacha nodes it
* deep-links into the existing precedent library (/precedents/[id]) so the
* graph is a navigation surface, not a dead-end visualization.
*/
import Link from "next/link";
import { ExternalLink, X } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import type { GraphNode } from "@/lib/api/graph";
const TYPE_LABELS: Record<string, string> = {
precedent: "פסיקה",
halacha: "הלכה",
topic: "נושא",
practice_area: "תחום",
gap: "פסיקה חסרה",
};
const GAP_STATUS_LABELS: Record<string, string> = {
open: "ממתינה לקליטה",
uploaded: "הועלתה",
closed: "טופלה",
irrelevant: "לא רלוונטית",
};
const PA_LABELS: Record<string, string> = {
rishuy_uvniya: "רישוי ובנייה",
betterment_levy: "היטל השבחה",
compensation_197: "פיצויים (ס׳ 197)",
appeals_committee: "ועדת ערר",
};
const SOURCE_LABELS: Record<string, string> = {
external_upload: "פסיקה חיצונית",
internal_committee: "החלטת ועדה",
cited_only: "מוזכר בלבד",
nevo_seed: "נבו",
};
export function GraphNodePanel({
node,
onClose,
}: {
node: GraphNode;
onClose: () => void;
}) {
const isPrecedentLike = node.type === "precedent" || node.type === "halacha";
const isGap = node.type === "gap";
return (
<Card className="bg-surface border-rule shadow-sm w-80 shrink-0 overflow-y-auto">
<CardContent className="space-y-4 p-4">
<div className="flex items-start justify-between gap-2">
<div className="space-y-1">
<Badge variant="outline" className="text-[0.65rem]">
{TYPE_LABELS[node.type] ?? node.type}
</Badge>
<h2 className="text-navy text-base leading-snug m-0">{node.label}</h2>
</div>
<Button
variant="ghost"
size="icon"
onClick={onClose}
aria-label="סגור"
className="shrink-0"
>
<X className="size-4" />
</Button>
</div>
<dl className="space-y-2 text-sm">
{isPrecedentLike && (
<Row label="ציטוטים נכנסים" value={String(node.size)} />
)}
{node.practice_area && (
<Row label="תחום" value={PA_LABELS[node.practice_area] ?? node.practice_area} />
)}
{node.source_kind && (
<Row label="מקור" value={SOURCE_LABELS[node.source_kind] ?? node.source_kind} />
)}
{node.precedent_level && <Row label="דרגה" value={node.precedent_level} />}
{isGap && (
<>
<Row label="מצוטטת ע״י" value={`${node.size} פסיקות בקורפוס`} />
{node.gap_status && (
<Row
label="סטטוס"
value={GAP_STATUS_LABELS[node.gap_status] ?? node.gap_status}
/>
)}
<p className="text-ink-muted text-xs leading-relaxed m-0">
פסיקה זו מצוטטת בקורפוס אך אינה קיימת בו מועמדת לקליטה.
</p>
</>
)}
{!isPrecedentLike && !isGap && (
<p className="text-ink-muted text-xs leading-relaxed m-0">
לחיצה על נקודה זו מתמקדת בשכניה כל הפסיקות המשויכות אליה.
</p>
)}
</dl>
{isPrecedentLike && node.case_law_id && (
<Button asChild variant="outline" className="w-full">
<Link href={`/precedents/${node.case_law_id}`}>
<ExternalLink className="size-4 me-2" />
פתח בספריית הפסיקה
</Link>
</Button>
)}
{isGap && (
<Button asChild variant="outline" className="w-full">
<Link href="/missing-precedents">
<ExternalLink className="size-4 me-2" />
לרשימת הפסיקה החסרה
</Link>
</Button>
)}
</CardContent>
</Card>
);
}
function Row({ label, value }: { label: string; value: string }) {
return (
<div className="flex items-baseline justify-between gap-3">
<dt className="text-ink-muted text-xs shrink-0">{label}</dt>
<dd className="text-ink text-end m-0">{value}</dd>
</div>
);
}