Skip to content

Commit 0ed6b51

Browse files
committed
Make sure the column is wide enough for the header cell
1 parent df3521c commit 0ed6b51

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

apps/webapp/app/components/code/TSQLResultsTable.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const MIN_COLUMN_WIDTH = 60;
5454
const MAX_COLUMN_WIDTH = 400;
5555
const CHAR_WIDTH_PX = 7.5; // Approximate width of a monospace character at text-xs (12px)
5656
const CELL_PADDING_PX = 40; // px-2 (8px) on each side + buffer for copy button
57+
const HEADER_ICONS_WIDTH_PX = 72; // Sort icon (16px) + filter icon (12px) + info icon (16px) + gaps (12px) + header padding (16px)
5758
const SAMPLE_SIZE = 100; // Number of rows to sample for width calculation
5859

5960
// Type for row data
@@ -306,21 +307,25 @@ function calculateColumnWidth(
306307
rows: RowData[],
307308
column: OutputColumnMetadata
308309
): number {
309-
// Start with header length
310-
let maxLength = columnName.length;
310+
// Calculate minimum width needed for the header (text + icons)
311+
const headerWidth = Math.ceil(columnName.length * CHAR_WIDTH_PX + HEADER_ICONS_WIDTH_PX);
311312

312313
// Sample rows to find max content length
314+
let maxContentLength = 0;
313315
const sampleRows = rows.slice(0, SAMPLE_SIZE);
314316
for (const row of sampleRows) {
315317
const value = row[columnName];
316318
const displayLength = getDisplayLength(value, column);
317-
if (displayLength > maxLength) {
318-
maxLength = displayLength;
319+
if (displayLength > maxContentLength) {
320+
maxContentLength = displayLength;
319321
}
320322
}
321323

322-
// Calculate pixel width: characters * char width + padding
323-
const calculatedWidth = Math.ceil(maxLength * CHAR_WIDTH_PX + CELL_PADDING_PX);
324+
// Calculate pixel width for content: characters * char width + padding
325+
const contentWidth = Math.ceil(maxContentLength * CHAR_WIDTH_PX + CELL_PADDING_PX);
326+
327+
// Use the larger of header width or content width
328+
const calculatedWidth = Math.max(headerWidth, contentWidth);
324329

325330
// Apply min/max bounds
326331
return Math.min(MAX_COLUMN_WIDTH, Math.max(MIN_COLUMN_WIDTH, calculatedWidth));

0 commit comments

Comments
 (0)