@@ -3,6 +3,21 @@ import {useAppContext} from "@/AppProvider.tsx";
33import { Warning } from "@/types/GeneratedTypes.tsx" ;
44import { AlertTriangle } from "lucide-react" ;
55
6+ type Palette = { container : string ; badge : string } ;
7+
8+ const CATEGORY_PALETTE : Palette [ ] = [
9+ { container : "bg-blue-50 border-blue-500 text-blue-900" , badge : "bg-blue-200 border-blue-700 text-blue-900" } ,
10+ { container : "bg-amber-50 border-amber-500 text-amber-900" , badge : "bg-amber-200 border-amber-700 text-amber-900" } ,
11+ { container : "bg-emerald-50 border-emerald-500 text-emerald-900" , badge : "bg-emerald-200 border-emerald-700 text-emerald-900" } ,
12+ { container : "bg-purple-50 border-purple-500 text-purple-900" , badge : "bg-purple-200 border-purple-700 text-purple-900" } ,
13+ { container : "bg-pink-50 border-pink-500 text-pink-900" , badge : "bg-pink-200 border-pink-700 text-pink-900" } ,
14+ ] ;
15+
16+ const UNCATEGORIZED_PALETTE : Palette = {
17+ container : "bg-gray-50 border-gray-400 text-gray-900" ,
18+ badge : "bg-gray-200 border-gray-600 text-gray-900" ,
19+ } ;
20+
621export const Warnings : React . FC = ( ) => {
722 const { data} = useAppContext ( ) ;
823
@@ -15,6 +30,17 @@ export const Warnings: React.FC = () => {
1530 } ) ;
1631 } , [ data ] ) ;
1732
33+ const categoryPalette = useMemo < Map < string , Palette > > ( ( ) => {
34+ const map = new Map < string , Palette > ( ) ;
35+ for ( const w of sortedWarnings ) {
36+ if ( ! w . category ) continue ;
37+ if ( ! map . has ( w . category ) ) {
38+ map . set ( w . category , CATEGORY_PALETTE [ map . size % CATEGORY_PALETTE . length ] ) ;
39+ }
40+ }
41+ return map ;
42+ } , [ sortedWarnings ] ) ;
43+
1844 return (
1945 < div className = "border-2 border-black p-3 sm:p-6 rounded-none" data-testid = "warnings-page" >
2046 < div className = "flex items-center gap-2 mb-4" >
@@ -31,24 +57,28 @@ export const Warnings: React.FC = () => {
3157 </ div >
3258 ) : (
3359 < div className = "flex flex-col gap-3" >
34- { sortedWarnings . map ( ( w , idx ) => (
35- < div
36- key = { idx }
37- className = "border-2 p-3 bg-blue-50 border-blue-500 text-blue-900"
38- data-testid = { `warning-${ idx } ` }
39- >
40- { w . category && (
41- < div className = "mb-2" >
42- < span className = "font-mono text-xs px-2 py-0.5 border-2 border-black bg-white" data-testid = { `warning-${ idx } -category` } >
60+ { sortedWarnings . map ( ( w , idx ) => {
61+ const palette = w . category ? ( categoryPalette . get ( w . category ) ?? UNCATEGORIZED_PALETTE ) : UNCATEGORIZED_PALETTE ;
62+ return (
63+ < div
64+ key = { idx }
65+ className = { `border-2 p-3 flex flex-col sm:flex-row sm:items-start gap-2 sm:gap-3 ${ palette . container } ` }
66+ data-testid = { `warning-${ idx } ` }
67+ >
68+ { w . category && (
69+ < span
70+ className = { `shrink-0 self-start font-mono text-xs px-2 py-0.5 border-2 ${ palette . badge } ` }
71+ data-testid = { `warning-${ idx } -category` }
72+ >
4373 { w . category }
4474 </ span >
75+ ) }
76+ < div className = "text-sm whitespace-pre-wrap break-words flex-1" data-testid = { `warning-${ idx } -message` } >
77+ { w . message ?? < span className = "italic text-gray-500" > (no message)</ span > }
4578 </ div >
46- ) }
47- < div className = "text-sm whitespace-pre-wrap break-words" data-testid = { `warning-${ idx } -message` } >
48- { w . message ?? < span className = "italic text-gray-500" > (no message)</ span > }
4979 </ div >
50- </ div >
51- ) ) }
80+ ) ;
81+ } ) }
5282 </ div >
5383 ) }
5484 </ div >
0 commit comments