|
23 | 23 |
|
24 | 24 | import React, { useEffect, useState, useCallback, useMemo } from 'react'; |
25 | 25 | import type { ObjectGridSchema, DataSource, ListColumn, ViewData } from '@object-ui/types'; |
| 26 | +import type { I18nLabel } from '@objectstack/spec/ui'; |
26 | 27 | import { SchemaRenderer, useDataScope, useNavigationOverlay, useAction, useObjectTranslation, useSafeFieldLabel } from '@object-ui/react'; |
27 | 28 | import { getCellRenderer, formatCurrency, formatCompactCurrency, formatDate, formatPercent, humanizeLabel } from '@object-ui/fields'; |
28 | 29 | import { |
@@ -90,6 +91,13 @@ function useGridTranslation() { |
90 | 91 | } |
91 | 92 | } |
92 | 93 |
|
| 94 | +/** Resolve an I18nLabel (string | {key, defaultValue}) to a plain string. */ |
| 95 | +function resolveColumnLabel(label: string | I18nLabel | undefined): string | undefined { |
| 96 | + if (label == null) return undefined; |
| 97 | + if (typeof label === 'string') return label; |
| 98 | + return label.defaultValue || label.key; |
| 99 | +} |
| 100 | + |
93 | 101 | export interface ObjectGridProps { |
94 | 102 | schema: ObjectGridSchema; |
95 | 103 | dataSource?: DataSource; |
@@ -619,8 +627,7 @@ export const ObjectGrid: React.FC<ObjectGridProps> = ({ |
619 | 627 | return (cols as ListColumn[]) |
620 | 628 | .filter((col) => col?.field && typeof col.field === 'string' && !col.hidden) |
621 | 629 | .map((col, colIndex) => { |
622 | | - const rawLabel = col.label; |
623 | | - const rawHeader = (typeof rawLabel === 'string' ? rawLabel : typeof rawLabel === 'object' && rawLabel ? (rawLabel as any).defaultValue || (rawLabel as any).key : null) || col.field.charAt(0).toUpperCase() + col.field.slice(1).replace(/_/g, ' '); |
| 630 | + const rawHeader = resolveColumnLabel(col.label) || col.field.charAt(0).toUpperCase() + col.field.slice(1).replace(/_/g, ' '); |
624 | 631 | const header = schema.objectName ? resolveFieldLabel(schema.objectName, col.field, rawHeader) : rawHeader; |
625 | 632 |
|
626 | 633 | // Build custom cell renderer based on column configuration |
|
0 commit comments