@@ -42,7 +42,7 @@ type GridItem = { batchId: number; resultId: number; index: number };
4242const ROW_HEIGHT = 26 ;
4343const HEADER = 30 ;
4444export const MARGIN_BOTTOM = 10 ;
45- export const MAXIMUMG_GRID_HEIGHT_PX = 300 ;
45+ const DEFAULT_INITIAL_MIN_NUMBER_OF_VISIBLE_ROWS = 8 ;
4646
4747export const QueryResultsGridView = ( ) => {
4848 const classes = useStyles ( ) ;
@@ -80,26 +80,40 @@ export const QueryResultsGridView = () => {
8080 } , [ resultSetSummaries ] ) ;
8181
8282 function naturalHeight ( rowCount : number ) : number {
83- return HEADER + rowCount * ROW_HEIGHT + MARGIN_BOTTOM ;
83+ let visibleRows = rowCount === 0 ? 1 : rowCount ;
84+ if ( visibleRows > DEFAULT_INITIAL_MIN_NUMBER_OF_VISIBLE_ROWS ) {
85+ visibleRows = DEFAULT_INITIAL_MIN_NUMBER_OF_VISIBLE_ROWS ;
86+ }
87+ return visibleRows * ROW_HEIGHT + HEADER + MARGIN_BOTTOM ;
8488 }
8589
8690 const gridHeights : number [ ] = useMemo ( ( ) => {
8791 if ( ! gridViewContainerHeight || gridList ?. length === 0 ) {
8892 return [ ] ;
8993 }
9094
91- const naturalHeights = gridList . map ( ( it ) =>
95+ const numGrids = gridList . length ;
96+
97+ // If only one grid, use available space
98+ if ( numGrids === 1 ) {
99+ return [ gridViewContainerHeight ] ;
100+ }
101+
102+ const preferredHeights = gridList . map ( ( it ) =>
92103 naturalHeight ( resultSetSummaries ?. [ it . batchId ] ?. [ it . resultId ] ?. rowCount ?? 0 ) ,
93104 ) ;
94105
95- const equalHeights = gridViewContainerHeight / gridList . length ;
106+ // Calculate total minimum height needed.
107+ const totalMinHeight = preferredHeights . reduce ( ( sum , h ) => sum + h , 0 ) ;
96108
97- return gridList . map ( ( _ , i ) =>
98- Math . min (
99- naturalHeights [ i ] ,
100- Math . max ( equalHeights , Math . min ( gridViewContainerHeight , MAXIMUMG_GRID_HEIGHT_PX ) ) ,
101- ) ,
102- ) ;
109+ // Calculate height adjustment if we have extra space to distribute evenly
110+ const heightAdjustment =
111+ gridViewContainerHeight > totalMinHeight
112+ ? ( gridViewContainerHeight - totalMinHeight ) / numGrids
113+ : 0 ;
114+
115+ // Distribute heights: preferred + proportional share of extra space
116+ return preferredHeights . map ( ( preferredHeight ) => preferredHeight + heightAdjustment ) ;
103117 } , [ gridList , gridViewContainerHeight ] ) ;
104118
105119 // Restore grid view container scroll position on mount
0 commit comments