@@ -76,13 +76,23 @@ export const RelatedList: React.FC<RelatedListProps> = ({
7676 const [ sortField , setSortField ] = React . useState < string | null > ( null ) ;
7777 const [ sortDirection , setSortDirection ] = React . useState < 'asc' | 'desc' > ( 'asc' ) ;
7878 const [ filterText , setFilterText ] = React . useState ( '' ) ;
79+ const [ objectSchema , setObjectSchema ] = React . useState < any > ( null ) ;
7980 const { t } = useDetailTranslation ( ) ;
8081
8182 // Sync internal state when data prop changes (e.g., parent fetches async data)
8283 React . useEffect ( ( ) => {
8384 setRelatedData ( data ) ;
8485 } , [ data ] ) ;
8586
87+ // Auto-fetch object schema when api/dataSource available but columns missing
88+ React . useEffect ( ( ) => {
89+ if ( api && dataSource ?. getObjectSchema && ! columns ?. length ) {
90+ dataSource . getObjectSchema ( api ) . then ( setObjectSchema ) . catch ( ( err : unknown ) => {
91+ console . warn ( `[RelatedList] Failed to fetch schema for ${ api } :` , err ) ;
92+ } ) ;
93+ }
94+ } , [ api , dataSource , columns ] ) ;
95+
8696 React . useEffect ( ( ) => {
8797 if ( api && ! data . length ) {
8898 setLoading ( true ) ;
@@ -166,6 +176,18 @@ export const RelatedList: React.FC<RelatedListProps> = ({
166176 }
167177 } , [ onRowDelete , t ] ) ;
168178
179+ // Generate effective columns from explicit prop or object schema fields
180+ const effectiveColumns = React . useMemo ( ( ) => {
181+ if ( columns && columns . length > 0 ) return columns ;
182+ if ( ! objectSchema ?. fields ) return [ ] ;
183+ return Object . entries ( objectSchema . fields )
184+ . filter ( ( [ key ] ) => ! key . startsWith ( '_' ) )
185+ . map ( ( [ key , def ] : [ string , any ] ) => ( {
186+ accessorKey : key ,
187+ header : def . label || key ,
188+ } ) ) ;
189+ } , [ columns , objectSchema ] ) ;
190+
169191 const viewSchema = React . useMemo ( ( ) => {
170192 if ( schema ) return schema ;
171193
@@ -176,7 +198,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
176198 return {
177199 type : 'data-table' ,
178200 data : paginatedData ,
179- columns : columns || [ ] ,
201+ columns : effectiveColumns ,
180202 pagination : false , // We handle pagination ourselves
181203 pageSize : effectivePageSize || 10 ,
182204 } ;
@@ -188,7 +210,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
188210 default :
189211 return { type : 'div' , children : 'No view configured' } ;
190212 }
191- } , [ type , paginatedData , columns , schema , effectivePageSize ] ) ;
213+ } , [ type , paginatedData , effectiveColumns , schema , effectivePageSize ] ) ;
192214
193215 const recordCountText = relatedData . length === 1
194216 ? t ( 'detail.relatedRecordOne' , { count : relatedData . length } )
0 commit comments