Skip to content

refactor(grid): one column-type predicate, and align numeric columns - #511

Merged
EVWorth merged 1 commit into
mainfrom
fix/grid-numeric-alignment
Aug 28, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/grid-numeric-alignment

Conversation

@EVWorth

@EVWorth EVWorth commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Follows #510. Started as "add alignment", turned up two bugs first.

Two definitions of "numeric", disagreeing

EditableCell already had one, predating this work:

return /int|decimal|numeric|float|double|real|bit/.test(dt.toLowerCase());

A substring test, so POINT matched (po·int) and YEAR didn't. #510 then added a stricter one in sql-types.ts without noticing:

type EditableCell sql-types
YEAR false true
POINT true false
MULTIPOINT true false

Consequence: editing a spatial column offered <input type="number">, and YEAR got a text input despite being an integer. The duplication was mine, from #510; consolidating into sql-types on the base type rather than a substring fixes both misclassifications.

isBooleanType and isLongTextType move there too — the latter was duplicated verbatim in EditableCell and TruncatedCell.

A third instance of the precision bug

Consolidating exposed it. On commit, parseEditValue pushed any numeric column through Number():

if (isNumericType(dataType)) {
  const n = Number(rawValue);   // 9007199254740993 -> ...992

So #502 fixed BIGINT on the way in, and editing a cell corrupted it on the way back out. isExactNumericType now keeps BIGINT and DECIMAL as text — matching how they arrive from Rust — and those cells use a text input, since a number input normalises large values too.

The alignment

The grid had none — every data cell was left-aligned. I said last time that stringifying BIGINT had left numbers left-aligned; that was wrong, they never were right-aligned. Nothing regressed.

Numeric columns are now right-aligned with tabular figures, and headers follow their column so the two agree. Driven by the declared type, because BIGINT and DECIMAL arrive as strings and the value's JavaScript type no longer identifies a number — the same reason SQLyog aligns from IS_NUM(field->type). For DECIMAL this gives decimal-point alignment for free, since MySQL returns a fixed scale; FLOAT/DOUBLE vary, so they align on the right edge only.

NULL — I changed my mind

I'd argued NULL shouldn't be right-aligned, so it doesn't read as data. Implementing it, mixed alignment within a column just looks broken, and it turned out the real problem was different: a genuine NULL and a VARCHAR holding the text "NULL" rendered identically.

So the column keeps one alignment and NULL is styled muted and italic instead. That distinguishes the two cases, which alignment never would have, and doesn't break the run of digits.

Tests

  • sql-types.test.ts — explicit cases for POINT/MULTIPOINT/YEAR pinning the old matcher's mistakes, isExactNumericType as a subset of isNumericSqlType, and that the text predicates no longer match on substrings
  • ResultsGrid.browser.test.tsx — real DOM: a numeric column's cells carry text-right tabular-nums and a text column's don't; headers agree with their column. Verified the first fails without the change.

1597 unit (+8), 292 browser (+2), type-check clean, lint unchanged at 180 warnings / 0 errors.

There were two definitions of "is this column numeric" that disagreed.
EditableCell had a substring regex, /int|decimal|.../, matched against
the lowercased type — so POINT and MULTIPOINT counted as numeric
(po·int) while YEAR did not. #510 then added a second, stricter one in
sql-types without noticing the first.

Consolidated into sql-types, matching the base type rather than a
substring, which fixes both misclassifications on the way past.
isBooleanType and isLongTextType move there too; the latter was
duplicated verbatim in EditableCell and TruncatedCell.

Consolidating surfaced a third instance of the precision bug: on commit,
parseEditValue pushed any numeric column through Number(), so editing a
BIGINT wrote back a value with the last digit dropped. isExactNumericType
now keeps BIGINT and DECIMAL as text, matching how they arrive from Rust,
and those cells use a text input since a number input normalises them
too.

Alignment, which the grid had none of: numeric columns are right-aligned
with tabular figures, headers follow their column. Driven by the declared
type, since BIGINT and DECIMAL arrive as strings and the value's
JavaScript type no longer identifies a number — the same reason SQLyog
aligns from IS_NUM(field->type). For DECIMAL this is decimal-point
alignment for free, as MySQL returns a fixed scale.

NULL is styled muted and italic instead of being left-aligned. It read
identically to a VARCHAR containing the text "NULL", and styling
separates them without breaking a column's run of digits.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit 453c83d into main Aug 28, 2026
9 checks passed
@EVWorth
EVWorth deleted the fix/grid-numeric-alignment branch August 28, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant