Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | 5x 5x 2x 5x 2x 2x 2x 2x 2x 2x 5x 5x 3x 3x 3x 2x 4x | import {
AlertCircle,
AlertTriangle,
CheckCircle2,
Loader2,
} from "lucide-react";
import { useMemo, useState } from "react";
import { Badge } from "@/ahuora-design-system/ui/badge";
import { ScrollArea } from "@/ahuora-design-system/ui/scroll-area";
import { Tabs, TabsList, TabsTrigger } from "@/ahuora-design-system/ui/tabs";
import { SeverityEnum } from "@/api/apiStore.gen";
import { cn } from "@/lib/utils";
import {
type DiagnosticFinding,
DiagnosticFindingCard,
} from "./DiagnosticFindingCard";
import { buildDiagnosticFindingKey } from "./ruleValidationKey";
interface DiagnosticPanelProps {
findings: DiagnosticFinding[];
onApplyFix?: (findingId: string) => void;
onFocusComponent?: (componentName: string) => void;
isSearching?: boolean;
className?: string;
}
export function DiagnosticPanel({
findings,
onApplyFix,
onFocusComponent,
isSearching,
className,
}: DiagnosticPanelProps) {
const [severityFilter, setSeverityFilter] = useState<
DiagnosticFinding["severity"] | "all"
>("all");
const filteredFindings = useMemo(() => {
if (severityFilter === "all") return findings;
return findings.filter((f) => f.severity === severityFilter);
}, [findings, severityFilter]);
const counts = useMemo(() => {
const error = findings.filter(
(f) => f.severity === SeverityEnum.Error,
).length;
const warning = findings.filter(
(f) => f.severity === SeverityEnum.Warning,
).length;
const total = findings.length;
return { error, warning, total };
}, [findings]);
const scanStatusLabel =
typeof isSearching === "boolean"
? isSearching
? "Scanning"
: "Scan completed"
: null;
if (findings.length === 0) {
const headline = isSearching
? "Searching for diagnostics…"
: "No issues found";
const subtext = isSearching
? "Collecting rule checks and recent diagnostics."
: "All checks completed with no findings.";
return (
<div
className={cn(
"flex flex-1 flex-col rounded-none bg-background w-full min-w-0 h-full",
className,
)}
>
<div className="flex flex-row bg-muted w-full py-1.5 px-2 justify-between items-center">
<h3 className="flex-1 text-sm font-semibold">Diagnostics</h3>
{scanStatusLabel && (
<Badge
variant="outline"
size="xs"
borderRadius="round"
className="shrink-0 flex items-center gap-1"
>
{isSearching && <Loader2 className="h-3 w-3 animate-spin" />}
{scanStatusLabel}
</Badge>
)}
</div>
<div className="flex flex-1 flex-col items-center justify-center p-6">
<div className="flex items-start gap-3 text-left">
{isSearching ? (
<Loader2 className="mt-0.5 h-5 w-5 shrink-0 animate-spin text-muted-foreground" />
) : (
<CheckCircle2 className="mt-0.5 h-5 w-5 shrink-0 text-primary" />
)}
<div>
<p className="text-sm font-semibold text-foreground">
{headline}
</p>
<p className="mt-1 text-xs text-muted-foreground">{subtext}</p>
</div>
</div>
<Badge
variant="secondary"
size="xs"
borderRadius="round"
className="mt-4"
>
0 findings
</Badge>
{isSearching && (
<p className="mt-4 text-center text-xs text-muted-foreground">
Scanning objects and evaluating rules…
</p>
)}
</div>
</div>
);
}
return (
<div
className={cn(
"flex flex-col h-full w-full min-w-0 rounded-none bg-background overflow-hidden",
className,
)}
>
<div className="flex flex-row bg-muted w-full py-1.5 px-2 justify-between items-center">
<h3 className="flex-1 text-sm font-semibold">Diagnostics</h3>
{scanStatusLabel && (
<Badge
variant="outline"
size="xs"
borderRadius="round"
className="shrink-0 flex items-center gap-1"
>
{isSearching && <Loader2 className="h-3 w-3 animate-spin" />}
{scanStatusLabel}
</Badge>
)}
</div>
<div className="flex items-start justify-between gap-3 px-4 pt-4">
<div>
<Badge variant="secondary" size="xs" borderRadius="round">
{counts.total} {counts.total === 1 ? "finding" : "findings"} found
</Badge>
<p className="mt-2 text-xs text-muted-foreground">
All diagnostic findings for this flowsheet.
</p>
</div>
</div>
<Tabs
value={severityFilter}
onValueChange={(value) =>
setSeverityFilter(value as DiagnosticFinding["severity"] | "all")
}
>
<div className="p-3">
<TabsList
type="hFull"
bg="default"
rounded="yes"
className="grid h-auto w-full grid-cols-3 gap-1"
>
<TabsTrigger value="all" size="sm">
All ({counts.total})
</TabsTrigger>
<TabsTrigger value={SeverityEnum.Error} size="sm" className="gap-2">
<AlertCircle className="h-3.5 w-3.5 text-rose-500" />
Errors ({counts.error})
</TabsTrigger>
<TabsTrigger
value={SeverityEnum.Warning}
size="sm"
className="gap-2"
>
<AlertTriangle className="h-3.5 w-3.5 text-amber-500" />
Warnings ({counts.warning})
</TabsTrigger>
</TabsList>
</div>
</Tabs>
<ScrollArea className="flex-1 min-h-0">
<div className="space-y-3 p-4">
{filteredFindings.length === 0 ? (
<div className="py-8 text-center text-sm text-muted-foreground">
No {severityFilter === "all" ? "" : severityFilter} findings
</div>
) : (
filteredFindings.map((finding) => (
<DiagnosticFindingCard
key={buildDiagnosticFindingKey({
ruleReference: finding.ruleReference,
id: finding.id,
componentId: finding.componentId ?? null,
componentName: finding.componentName ?? null,
propertyId: finding.propertyId ?? null,
propertyKey: finding.propertyKey ?? null,
title: finding.title,
})}
finding={finding}
onApplyFix={onApplyFix}
onFocusComponent={onFocusComponent}
/>
))
)}
</div>
</ScrollArea>
</div>
);
}
|