fix: apply type inference pipeline to accessorKey-format grid columns#903
fix: apply type inference pipeline to accessorKey-format grid columns#903
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…Label, fix PercentCellRenderer for progress fields Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…constant Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
|
@copilot 仔细评估是否已经完成了任务中要求的所有开发 |
All acceptance criteria from the issue have been verified complete:
|
There was a problem hiding this comment.
Pull request overview
Fixes a rendering pipeline gap in @object-ui/plugin-grid where accessorKey-format columns previously bypassed ObjectGrid’s type inference and cell renderer injection, leading to raw/unstyled cell output for dates, select-like statuses, and percent/progress fields.
Changes:
- Apply
inferColumnType()→getCellRenderer()toaccessorKey-format columns (while preserving existing customcellrenderers). - Add
humanizeLabel()to@object-ui/fieldsand use it as a fallback for select option labels (including auto-generated options). - Refine
PercentCellRenderernormalization for “whole percent” fields (e.g.,progress,completion) and add coverage via new tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/plugin-grid/src/ObjectGrid.tsx | Applies the inference/renderer pipeline to accessorKey columns and humanizes auto-generated select option labels. |
| packages/fields/src/index.tsx | Exports humanizeLabel(), uses it in SelectCellRenderer, and updates percent normalization for progress/completion-style fields. |
| packages/plugin-grid/src/tests/accessorKey-inference.test.tsx | Adds regression tests ensuring accessorKey columns receive inference/renderers and preserve custom cells. |
| packages/fields/src/tests/cell-renderers.test.tsx | Adds tests for humanizeLabel, SelectCellRenderer fallback behavior, and PercentCellRenderer whole-percent handling. |
| ROADMAP.md | Marks the work as completed and updates reported test counts. |
|
|
||
| return { | ||
| ...col, | ||
| headerIcon: getTypeIcon(inferredType), |
There was a problem hiding this comment.
In the accessorKey branch, inferred columns always overwrite any existing headerIcon on the incoming column object. If a consumer provided a custom headerIcon (but no custom cell), it will be lost. Consider only setting headerIcon when it’s not already present (e.g., prefer col.headerIcon if defined).
| headerIcon: getTypeIcon(inferredType), | |
| headerIcon: col.headerIcon ?? getTypeIcon(inferredType), |
|
|
||
| return { | ||
| ...col, | ||
| headerIcon: getTypeIcon(inferredType), |
There was a problem hiding this comment.
In the accessorKey inference path, consider setting a default align: 'right' for inferred numeric types (number/currency/percent) when the incoming column doesn’t specify align. The ListColumn branch does this inference, so without it the two column formats render numeric fields with different alignment.
| return { | |
| ...col, | |
| headerIcon: getTypeIcon(inferredType), | |
| const isNumericType = | |
| inferredType === 'number' || | |
| inferredType === 'currency' || | |
| inferredType === 'percent'; | |
| return { | |
| ...col, | |
| headerIcon: getTypeIcon(inferredType), | |
| // Respect explicit align, otherwise default right for numeric-like types | |
| align: col.align ?? (isNumericType ? 'right' : undefined), |
ObjectGrid.generateColumns()returnedaccessorKey-format columns as-is, bypassinginferColumnType()→getCellRenderer()entirely. Dates rendered as raw ISO strings, statuses as plain text, progress as raw numbers.Core fix —
ObjectGrid.tsxThe
accessorKeybranch now iterates columns and applies the same inference + renderer pipeline as thefieldbranch, skipping columns that already have acellrenderer:humanizeLabel()—fields/src/index.tsxin_progress→In Progress,high-priority→High PrioritySelectCellRendereruses it as fallback when no explicitoption.labelexistsPercentCellRenderernormalization —fields/src/index.tsxFields matching
WHOLE_PERCENT_FIELD_PATTERN(/progress|completion/) treat values as 0–100 directly. Other percent fields (e.g.probability) continue treating 0–1 as fractions. This meansprogress: 75→75%andprobability: 0.75→75%both render correctly.Tests
cell-renderers.test.tsx(humanizeLabel edge cases, SelectCellRenderer fallback, PercentCellRenderer progress fields)accessorKey-inference.test.tsx(inference, date rendering, progress bars, custom renderer preservation)Original prompt
This section details on the original issue you should resolve
<issue_title>ObjectGrid: accessorKey-format columns bypass type inference — raw dates, no badges, no progress bars</issue_title>
<issue_description>## Summary
The ObjectGrid rendering pipeline completely skips type inference and cell renderer injection when columns use
accessorKeyformat (data-table format) instead offieldformat (ListColumn format). This causes all type-aware rendering to break — dates show raw ISO strings, status/priority show plain text, progress shows raw numbers, and user fields show raw IDs.Root Cause
In
ObjectGrid.generateColumns(), theaccessorKeybranch returns columns as-is with no processing:Meanwhile the
field(ListColumn) branch correctly runsinferColumnType()→getCellRenderer()→ cell renderer injection. This is a platform-level rendering pipeline gap that affects any view usingaccessorKey-format column definitions.Symptoms (all caused by the same root cause)
start_date,end_date)2024-02-01T00:00:00.000ZFeb 1, 2024viaDateCellRendererstatus)in_progress(plain text)<Badge>viaSelectCellRendererpriority)high/critical(plain text)progress)75(raw number)75%viaPercentCellRendererassignee)2(raw ID)UserCellRendererRequired Changes
1. [P0] Apply inference to
accessorKey-format columnsFile:
packages/plugin-grid/src/ObjectGrid.tsx—generateColumns()L506-514When columns are in
accessorKeyformat, iterate and applyinferColumnType()+getCellRenderer()for columns that don't already have acellrenderer:2. [P1] Auto-humanize snake_case select labels
File:
packages/fields/src/index.tsx—SelectCellRendererAdd and export a
humanizeLabel()utility, use as fallback when nooption.labelexists:Also apply in
ObjectGrid.generateColumns()when auto-generating options from data values.3. [P1] PercentCellRenderer value normalization for
progressfieldsFile:
packages/fields/src/index.tsx—PercentCellRendererUse field name to disambiguate 0-1 fraction vs 0-100 whole number:
Affected Packages
packages/plugin-grid/src/ObjectGrid.tsx— core fixpackages/fields/src/index.tsx—SelectCellRenderer,PercentCellRenderer,humanizeLabel()Acceptance Criteria
accessorKey-format columns receive type inference viainferColumnType()getCellRenderer()cell renderers appliedcellrenderer are NOT overriddenin_progress→In Progress)option.labelstill takes priority over humanized fallbackprogressfield with value75renders as75%with correctly filled barprobabilityfield with value0.75renders as75%accessorKey-format inference pathhumanizeLabel()edge casesPercentCellRendererwith progress-type fieldsComments on the Issue (you are @copilot in this section)
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.