1
1
import { useState } from "react" ;
2
2
import CopyIcon from "./icons/CopyIcon" ;
3
+ import { mapValues } from "../utils/ObjectHelpers" ;
3
4
4
5
interface SponsoredFeed {
5
6
name : string ;
@@ -26,25 +27,16 @@ export const SponsoredFeedsTable = ({
26
27
} ;
27
28
28
29
// Calculate parameter statistics
29
- const paramCounts = feeds . reduce ( ( acc , feed ) => {
30
- acc [ feed . updateParameters ] = ( acc [ feed . updateParameters ] || 0 ) + 1 ;
31
- return acc ;
32
- } , { } as Record < string , number > ) ;
30
+ const paramCounts = mapValues (
31
+ Object . groupBy ( feeds , ( feed ) => feed . updateParameters ) ,
32
+ ( feeds : SponsoredFeed [ ] ) => feeds . length
33
+ ) ;
33
34
34
35
const defaultParams = Object . entries ( paramCounts ) . sort (
35
36
( [ , a ] , [ , b ] ) => b - a
36
37
) [ 0 ] [ 0 ] ;
37
38
38
- // Calculate table height based on number of items
39
- // Each row is approximately 40px (py-2 = 8px top + 8px bottom + content height)
40
- // Header is approximately 48px (py-2 = 8px top + 8px bottom + font height)
41
- // Show 7 rows by default, then scroll - but maintain consistent minimum height
42
- const maxVisibleRows = 7 ;
43
- const shouldScroll = feeds . length > maxVisibleRows ;
44
- const rowHeight = 56 ; // Increased row height to account for actual content height
45
- const headerHeight = 48 ; // Header height in pixels
46
- const exactTableHeight = `${ headerHeight + maxVisibleRows * rowHeight } px` ; // Exact height for 7 rows
47
- const tableHeight = shouldScroll ? exactTableHeight : "auto" ; // Use exact height for scrollable tables
39
+ // CSS max-h-96 will handle scrolling automatically
48
40
49
41
return (
50
42
< div className = "my-6" >
@@ -88,10 +80,7 @@ export const SponsoredFeedsTable = ({
88
80
89
81
{ /* Table */ }
90
82
< div className = "overflow-x-auto" >
91
- < div
92
- className = { `${ shouldScroll ? "overflow-y-auto" : "" } ` }
93
- style = { { height : tableHeight } }
94
- >
83
+ < div className = "overflow-y-auto max-h-96" >
95
84
< table className = "w-full text-sm min-w-full" >
96
85
< thead className = "sticky top-0 bg-gray-50 dark:bg-gray-800 z-30" >
97
86
< tr >
@@ -181,14 +170,6 @@ export const SponsoredFeedsTable = ({
181
170
</ table >
182
171
</ div >
183
172
</ div >
184
-
185
- { /* Show count indicator when scrolling is needed */ }
186
- { shouldScroll && (
187
- < div className = "px-3 py-1 bg-gray-50 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-600 text-xs text-gray-500 text-center" >
188
- Showing { maxVisibleRows } of { feeds . length } feeds • Scroll to see
189
- more
190
- </ div >
191
- ) }
192
173
</ div >
193
174
</ div >
194
175
) ;
0 commit comments