@@ -25,8 +25,10 @@ import {
2525 ChevronRight ,
2626 ArrowUpDown ,
2727} from 'lucide-react' ;
28- import type { DataSource } from '@object-ui/types' ;
28+ import type { DataSource , FieldMetadata } from '@object-ui/types' ;
29+ import { getCellRenderer } from '@object-ui/fields' ;
2930import { useDetailTranslation } from './useDetailTranslation' ;
31+ import { useSafeFieldLabel } from '@object-ui/react' ;
3032
3133export interface RelatedListProps {
3234 title : string ;
@@ -37,6 +39,8 @@ export interface RelatedListProps {
3739 columns ?: any [ ] ;
3840 className ?: string ;
3941 dataSource ?: DataSource ;
42+ /** Object name for i18n field label resolution */
43+ objectName ?: string ;
4044 /** Callback when "New" button is clicked */
4145 onNew ?: ( ) => void ;
4246 /** Callback when "View All" button is clicked */
@@ -62,6 +66,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
6266 columns,
6367 className,
6468 dataSource,
69+ objectName,
6570 onNew,
6671 onViewAll,
6772 onRowEdit,
@@ -78,6 +83,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
7883 const [ filterText , setFilterText ] = React . useState ( '' ) ;
7984 const [ objectSchema , setObjectSchema ] = React . useState < any > ( null ) ;
8085 const { t } = useDetailTranslation ( ) ;
86+ const { fieldLabel : resolveFieldLabel } = useSafeFieldLabel ( ) ;
8187
8288 // Sync internal state when data prop changes (e.g., parent fetches async data)
8389 React . useEffect ( ( ) => {
@@ -180,13 +186,40 @@ export const RelatedList: React.FC<RelatedListProps> = ({
180186 const effectiveColumns = React . useMemo ( ( ) => {
181187 if ( columns && columns . length > 0 ) return columns ;
182188 if ( ! objectSchema ?. fields ) return [ ] ;
189+ const resolvedObjectName = objectName || api || '' ;
183190 return Object . entries ( objectSchema . fields )
184191 . filter ( ( [ key ] ) => ! key . startsWith ( '_' ) )
185- . map ( ( [ key , def ] : [ string , any ] ) => ( {
186- accessorKey : key ,
187- header : def . label || key ,
188- } ) ) ;
189- } , [ columns , objectSchema ] ) ;
192+ . map ( ( [ key , def ] : [ string , any ] ) => {
193+ const col : any = {
194+ accessorKey : key ,
195+ header : resolveFieldLabel ( resolvedObjectName , key , def . label || key ) ,
196+ } ;
197+ // Add type-aware cell renderer for typed fields
198+ if ( def . type ) {
199+ const CellRenderer = getCellRenderer ( def . type ) ;
200+ if ( CellRenderer ) {
201+ const fieldMeta : FieldMetadata = {
202+ name : key ,
203+ label : def . label || key ,
204+ type : def . type ,
205+ ...( def . options && { options : def . options } ) ,
206+ ...( def . currency && { currency : def . currency } ) ,
207+ ...( def . precision !== undefined && { precision : def . precision } ) ,
208+ ...( def . format && { format : def . format } ) ,
209+ ...( ( def . reference_to || def . reference ) && { reference_to : def . reference_to || def . reference } ) ,
210+ ...( def . reference_field && { reference_field : def . reference_field } ) ,
211+ } ;
212+ col . cell = ( value : any ) => {
213+ if ( value === null || value === undefined ) {
214+ return React . createElement ( 'span' , { className : 'text-muted-foreground/50 text-xs italic' } , '—' ) ;
215+ }
216+ return React . createElement ( CellRenderer , { value, field : fieldMeta } ) ;
217+ } ;
218+ }
219+ }
220+ return col ;
221+ } ) ;
222+ } , [ columns , objectSchema , objectName , api , resolveFieldLabel ] ) ;
190223
191224 const viewSchema = React . useMemo ( ( ) => {
192225 if ( schema ) return schema ;
@@ -258,9 +291,9 @@ export const RelatedList: React.FC<RelatedListProps> = ({
258291 ) }
259292
260293 { /* Sortable column headers */ }
261- { sortable && columns && columns . length > 0 && relatedData . length > 0 && (
294+ { sortable && effectiveColumns && effectiveColumns . length > 0 && relatedData . length > 0 && (
262295 < div className = "flex flex-wrap gap-1 mb-3" >
263- { columns . map ( ( col : any ) => {
296+ { effectiveColumns . map ( ( col : any ) => {
264297 const field = col . accessorKey || col . field || col . name ;
265298 if ( ! field ) return null ;
266299 const label = col . header || col . label || field ;
0 commit comments