Repository navigation
refactor(grid): one column-type predicate, and align numeric columns - #511
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #510. Started as "add alignment", turned up two bugs first.
Two definitions of "numeric", disagreeing
EditableCellalready had one, predating this work:A substring test, so
POINTmatched (po·int) andYEARdidn't. #510 then added a stricter one insql-types.tswithout noticing:YEARPOINTMULTIPOINTConsequence: editing a spatial column offered
<input type="number">, andYEARgot a text input despite being an integer. The duplication was mine, from #510; consolidating intosql-typeson the base type rather than a substring fixes both misclassifications.isBooleanTypeandisLongTextTypemove there too — the latter was duplicated verbatim inEditableCellandTruncatedCell.A third instance of the precision bug
Consolidating exposed it. On commit,
parseEditValuepushed any numeric column throughNumber():So #502 fixed BIGINT on the way in, and editing a cell corrupted it on the way back out.
isExactNumericTypenow 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
VARCHARholding 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 forPOINT/MULTIPOINT/YEARpinning the old matcher's mistakes,isExactNumericTypeas a subset ofisNumericSqlType, and that the text predicates no longer match on substringsResultsGrid.browser.test.tsx— real DOM: a numeric column's cells carrytext-right tabular-numsand 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.