From bd9eddfd349e21e96d0803b4640231e41093fc2b Mon Sep 17 00:00:00 2001 From: Maksim Kostromin Date: Tue, 13 Oct 2026 15:04:44 -0400 Subject: [PATCH] fix: show detected column types and ignore header row in detection The type badge was hidden for every column except the sorted one, so only one column looked typed. It now stays visible at reduced opacity. With "1st Row = Header" off, the header text was counted as a sample and pushed sparse columns (one value plus -- elsewhere, e.g. SEC yield, Exp ratio, YTD, 1-10 year) under the 60% threshold. Detection now retries without row 0 when the first pass returns string. --- src/main.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index f5e6514..c87d616 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -437,9 +437,9 @@ const TYPE_PATTERNS: { type: ColumnType; pattern: RegExp }[] = [ { type: 'number', pattern: /^[+-]?[\d,]+\.?\d*$/ }, ]; -function detectColumnType(rows: string[][], colIndex: number): ColumnType { +function detectColumnTypeFrom(rows: string[][], colIndex: number, start: number): ColumnType { const samples: string[] = []; - for (let i = 0; i < rows.length && samples.length < TYPE_DETECTION_SAMPLE_SIZE; i++) { + for (let i = start; i < rows.length && samples.length < TYPE_DETECTION_SAMPLE_SIZE; i++) { const val = (rows[i][colIndex] || '').trim(); if (val !== '' && val !== '--' && val !== 'N/A' && val !== 'n/a') samples.push(val); } @@ -451,6 +451,13 @@ function detectColumnType(rows: string[][], colIndex: number): ColumnType { return 'string'; } +// With "1st Row = Header" off, row 0 is the header text and outvotes sparse columns +// (one value plus "--" everywhere else), so retry without it before giving up +function detectColumnType(rows: string[][], colIndex: number): ColumnType { + const type = detectColumnTypeFrom(rows, colIndex, 0); + return type === 'string' && rows.length > 1 ? detectColumnTypeFrom(rows, colIndex, 1) : type; +} + const SUFFIX_MULTIPLIERS: Record = { 'K': 1e3, 'M': 1e6, 'B': 1e9, 'T': 1e12 }; function extractSortValue(cellValue: string, colType: ColumnType): number | string | null { @@ -977,7 +984,7 @@ const ColumnHeader: React.FC<{ {header}