@@ -13,10 +13,11 @@ import { DetailSection } from './DetailSection';
1313import { DetailTabs } from './DetailTabs' ;
1414import { RelatedList } from './RelatedList' ;
1515import { SchemaRenderer } from '@object-ui/react' ;
16- import type { DetailViewSchema } from '@object-ui/types' ;
16+ import type { DetailViewSchema , DataSource } from '@object-ui/types' ;
1717
1818export interface DetailViewProps {
1919 schema : DetailViewSchema ;
20+ dataSource ?: DataSource ;
2021 className ?: string ;
2122 onEdit ?: ( ) => void ;
2223 onDelete ?: ( ) => void ;
@@ -25,17 +26,34 @@ export interface DetailViewProps {
2526
2627export const DetailView : React . FC < DetailViewProps > = ( {
2728 schema,
29+ dataSource,
2830 className,
2931 onEdit,
3032 onDelete,
3133 onBack,
3234} ) => {
33- const [ data ] = React . useState ( schema . data ) ;
34- const [ loading , setLoading ] = React . useState ( ! schema . data && ! ! schema . api ) ;
35+ const [ data , setData ] = React . useState < any > ( schema . data ) ;
36+ const [ loading , setLoading ] = React . useState ( ! schema . data && ! ! ( ( schema . api && schema . resourceId ) || ( dataSource && schema . objectName && schema . resourceId ) ) ) ;
3537
36- // Fetch data if API provided
38+ // Fetch data if API or DataSource provided
3739 React . useEffect ( ( ) => {
38- if ( schema . api && schema . resourceId ) {
40+ // If inline data provided, use it
41+ if ( schema . data ) {
42+ setData ( schema . data ) ;
43+ setLoading ( false ) ;
44+ return ;
45+ }
46+
47+ if ( dataSource && schema . objectName && schema . resourceId ) {
48+ setLoading ( true ) ;
49+ dataSource . findOne ( schema . objectName , schema . resourceId ) . then ( ( result ) => {
50+ setData ( result ) ;
51+ setLoading ( false ) ;
52+ } ) . catch ( ( err ) => {
53+ console . error ( 'Failed to fetch detail data:' , err ) ;
54+ setLoading ( false ) ;
55+ } ) ;
56+ } else if ( schema . api && schema . resourceId ) {
3957 setLoading ( true ) ;
4058 // TODO: Fetch from API
4159 // This would integrate with the data provider
0 commit comments