@@ -7,6 +7,72 @@ interface ColumnStatsSectionProps {
77 onToggle : ( ) => void
88}
99
10+ interface StatHeaderProps {
11+ stat : string
12+ }
13+
14+ const StatHeader = ( { stat } : StatHeaderProps ) => (
15+ < th
16+ key = { stat }
17+ className = "text-left py-2 px-1 font-medium w-16"
18+ title = { stat }
19+ style = { { color : themeColors . muted } }
20+ >
21+ { stat . length > 6 ? stat . slice ( 0 , 6 ) + '..' : stat }
22+ </ th >
23+ )
24+
25+ interface StatCellProps {
26+ value : SampleValue
27+ }
28+
29+ const StatCell = ( { value } : StatCellProps ) => (
30+ < td
31+ className = "py-2 px-1 font-mono text-xs truncate"
32+ title = { String ( value ) }
33+ style = { { color : themeColors . muted } }
34+ >
35+ { typeof value === 'number'
36+ ? value . toFixed ( 1 )
37+ : String ( value ) . length > 8
38+ ? String ( value ) . slice ( 0 , 8 ) + '..'
39+ : String ( value ) }
40+ </ td >
41+ )
42+
43+ interface ColumnStatRowProps {
44+ columnName : string
45+ statsValue : TableDiffData [ 'row_diff' ] [ 'column_stats' ] [ string ]
46+ }
47+
48+ const ColumnStatRow = ( { columnName, statsValue } : ColumnStatRowProps ) => (
49+ < tr
50+ className = "transition-colors"
51+ style = { {
52+ borderBottom : `1px solid ${ themeColors . border } ` ,
53+ } }
54+ onMouseEnter = { e => {
55+ e . currentTarget . style . backgroundColor =
56+ 'var(--vscode-list-hoverBackground)'
57+ } }
58+ onMouseLeave = { e => {
59+ e . currentTarget . style . backgroundColor = 'transparent'
60+ } }
61+ >
62+ < td
63+ className = "py-2 pr-2 font-mono truncate"
64+ title = { columnName }
65+ >
66+ { columnName }
67+ </ td >
68+ { statsValue && typeof statsValue === 'object'
69+ ? Object . values ( statsValue as Record < string , SampleValue > ) . map ( ( value , idx ) => (
70+ < StatCell key = { idx } value = { value } />
71+ ) )
72+ : [ < StatCell key = "single-value" value = { statsValue } /> ] }
73+ </ tr >
74+ )
75+
1076export function ColumnStatsSection ( {
1177 columnStats,
1278 expanded,
@@ -57,74 +123,22 @@ export function ColumnStatsSection({
57123 Column
58124 </ th >
59125 { statKeys . map ( stat => (
60- < th
61- key = { stat }
62- className = "text-left py-2 px-1 font-medium w-16"
63- title = { stat }
64- style = { { color : themeColors . muted } }
65- >
66- { stat . length > 6 ? stat . slice ( 0 , 6 ) + '..' : stat }
67- </ th >
126+ < StatHeader key = { stat } stat = { stat } />
68127 ) ) }
69128 </ tr >
70129 </ thead >
71130 < tbody >
72131 { Object . entries ( columnStats ) . map ( ( [ col , statsValue ] ) => (
73- < tr
132+ < ColumnStatRow
74133 key = { col }
75- className = "transition-colors"
76- style = { {
77- borderBottom : `1px solid ${ themeColors . border } ` ,
78- } }
79- onMouseEnter = { e => {
80- e . currentTarget . style . backgroundColor =
81- 'var(--vscode-list-hoverBackground)'
82- } }
83- onMouseLeave = { e => {
84- e . currentTarget . style . backgroundColor = 'transparent'
85- } }
86- >
87- < td
88- className = "py-2 pr-2 font-mono truncate"
89- title = { col }
90- >
91- { col }
92- </ td >
93- { statsValue && typeof statsValue === 'object'
94- ? Object . values (
95- statsValue as Record < string , SampleValue > ,
96- ) . map ( ( value : SampleValue , idx : number ) => (
97- < td
98- key = { idx }
99- className = "py-2 px-1 font-mono text-xs truncate"
100- title = { String ( value ) }
101- style = { { color : themeColors . muted } }
102- >
103- { typeof value === 'number'
104- ? value . toFixed ( 1 )
105- : String ( value ) . length > 8
106- ? String ( value ) . slice ( 0 , 8 ) + '..'
107- : String ( value ) }
108- </ td >
109- ) )
110- : [
111- < td
112- key = "single-value"
113- className = "py-2 px-1 font-mono text-xs truncate"
114- title = { String ( statsValue ) }
115- style = { { color : themeColors . muted } }
116- >
117- { typeof statsValue === 'number'
118- ? statsValue . toFixed ( 1 )
119- : String ( statsValue ) }
120- </ td > ,
121- ] }
122- </ tr >
134+ columnName = { col }
135+ statsValue = { statsValue }
136+ />
123137 ) ) }
124138 </ tbody >
125139 </ table >
126140 </ div >
127141 </ div >
128142 </ SectionToggle >
129143 )
130- }
144+ }
0 commit comments