-
Notifications
You must be signed in to change notification settings - Fork 3
fix: apply type inference pipeline to accessorKey-format grid columns #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
992fb45
e3c1079
8d41a4b
b1cca7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |||||||||||||||||||||||||||||||
| import React, { useEffect, useState, useCallback, useMemo } from 'react'; | ||||||||||||||||||||||||||||||||
| import type { ObjectGridSchema, DataSource, ListColumn, ViewData } from '@object-ui/types'; | ||||||||||||||||||||||||||||||||
| import { SchemaRenderer, useDataScope, useNavigationOverlay, useAction } from '@object-ui/react'; | ||||||||||||||||||||||||||||||||
| import { getCellRenderer, formatCurrency, formatCompactCurrency, formatDate, formatPercent } from '@object-ui/fields'; | ||||||||||||||||||||||||||||||||
| import { getCellRenderer, formatCurrency, formatCompactCurrency, formatDate, formatPercent, humanizeLabel } from '@object-ui/fields'; | ||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||
| Badge, Button, NavigationOverlay, | ||||||||||||||||||||||||||||||||
| Popover, PopoverContent, PopoverTrigger, | ||||||||||||||||||||||||||||||||
|
|
@@ -508,9 +508,29 @@ export const ObjectGrid: React.FC<ObjectGridProps> = ({ | |||||||||||||||||||||||||||||||
| if (cols.length > 0 && typeof cols[0] === 'object' && cols[0] !== null) { | ||||||||||||||||||||||||||||||||
| const firstCol = cols[0] as any; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Already in data-table format - use as-is | ||||||||||||||||||||||||||||||||
| // Already in data-table format - apply type inference for columns without custom cell renderers | ||||||||||||||||||||||||||||||||
| if ('accessorKey' in firstCol) { | ||||||||||||||||||||||||||||||||
| return cols; | ||||||||||||||||||||||||||||||||
| return (cols as any[]).map((col) => { | ||||||||||||||||||||||||||||||||
| if (col.cell) return col; // already has custom renderer | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const syntheticCol: ListColumn = { field: col.accessorKey, label: col.header, type: col.type }; | ||||||||||||||||||||||||||||||||
| const inferredType = inferColumnType(syntheticCol); | ||||||||||||||||||||||||||||||||
| if (!inferredType) return col; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const CellRenderer = getCellRenderer(inferredType); | ||||||||||||||||||||||||||||||||
| const fieldMeta: Record<string, any> = { name: col.accessorKey, type: inferredType }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (inferredType === 'select') { | ||||||||||||||||||||||||||||||||
| const uniqueValues = Array.from(new Set(data.map(row => row[col.accessorKey]).filter(Boolean))); | ||||||||||||||||||||||||||||||||
| fieldMeta.options = uniqueValues.map((v: any) => ({ value: v, label: humanizeLabel(String(v)) })); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||
| ...col, | ||||||||||||||||||||||||||||||||
| headerIcon: getTypeIcon(inferredType), | ||||||||||||||||||||||||||||||||
|
Comment on lines
+527
to
+530
|
||||||||||||||||||||||||||||||||
| 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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the accessorKey branch, inferred columns always overwrite any existing
headerIconon the incoming column object. If a consumer provided a customheaderIcon(but no customcell), it will be lost. Consider only settingheaderIconwhen it’s not already present (e.g., prefercol.headerIconif defined).