import { Handle, Position, type NodeProps } from '@xyflow/react'; import { Ban, Fingerprint, Flag, Globe2, Play, ScanSearch, Shield, ShieldCheck, } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { cn } from '@/lib/utils'; import type { WAFRuleNode } from '@/lib/services/openflare'; import { displayNodeTitle } from './node-factory'; export interface RuleFlowNodeData extends Record { rule: WAFRuleNode; issues: number; } const meta = { start: { icon: Play }, ip_match: { icon: Fingerprint }, geo_match: { icon: Globe2 }, ua_check: { icon: ScanSearch }, security_check: { icon: Shield }, pow: { icon: ShieldCheck }, allow: { icon: Flag }, block: { icon: Ban }, } as const; const outputHandles: Partial> = { start: ['next'], ip_match: ['true', 'false'], geo_match: ['true', 'false'], ua_check: ['true', 'false'], security_check: ['true', 'false'], pow: ['next'], }; export function RuleNode({ data, selected }: NodeProps) { const value = data as RuleFlowNodeData; const { rule, issues } = value; const { icon: Icon } = meta[rule.type]; const title = displayNodeTitle(rule); return (
0 && 'border-destructive', )} > {rule.type !== 'start' && ( )}
{title} {rule.id}
{issues > 0 && {issues}}
{(outputHandles[rule.type] ?? []).map((handle, index, all) => ( {handle} ))}
); }