Skip to content

Commit 964fa93

Browse files
committed
Add RecordDetailView component and integrate with routing; enhance ListView schema handling for default view type
1 parent f292ca1 commit 964fa93

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

apps/console/src/App.tsx

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,56 @@ import { ObjectView } from './components/ObjectView';
1414
import { DashboardView } from './components/DashboardView';
1515
import { PageView } from './components/PageView';
1616

17+
import { DetailView } from '@object-ui/plugin-detail';
18+
import { useParams } from 'react-router-dom';
19+
20+
// ... existing imports ...
21+
22+
// Detail View Component
23+
function RecordDetailView({ dataSource, objects, onEdit }: any) {
24+
const { objectName, recordId } = useParams();
25+
const objectDef = objects.find((o: any) => o.name === objectName);
26+
27+
if (!objectDef) {
28+
return (
29+
<div className="flex h-full items-center justify-center p-4">
30+
<Empty>
31+
<EmptyTitle>Object Not Found</EmptyTitle>
32+
<p>Object "{objectName}" definition missing.</p>
33+
</Empty>
34+
</div>
35+
);
36+
}
37+
38+
return (
39+
<div className="h-full bg-background overflow-auto">
40+
<DetailView
41+
schema={{
42+
type: 'detail-view',
43+
objectName: objectDef.name,
44+
resourceId: recordId,
45+
showBack: true,
46+
onBack: 'history',
47+
showEdit: true,
48+
sections: [
49+
{
50+
title: 'Details',
51+
fields: Object.keys(objectDef.fields || {}).map(key => ({
52+
name: key,
53+
label: objectDef.fields[key].label,
54+
type: objectDef.fields[key].type
55+
})),
56+
columns: 2
57+
}
58+
]
59+
}}
60+
dataSource={dataSource}
61+
onEdit={() => onEdit({ _id: recordId, id: recordId })}
62+
/>
63+
</div>
64+
)
65+
}
66+
1767
export function AppContent() {
1868
const [client, setClient] = useState<ObjectStackClient | null>(null);
1969
const [dataSource, setDataSource] = useState<ObjectStackDataSource | null>(null);
@@ -75,6 +125,14 @@ export function AppContent() {
75125
setEditingRecord(record);
76126
setIsDialogOpen(true);
77127
};
128+
129+
const handleRowClick = (record: any) => {
130+
// Check for both string ID and Mongo/ObjectQL _id
131+
const id = record._id || record.id;
132+
if (id && currentObjectDef) {
133+
navigate(`/${currentObjectDef.name}/${id}`);
134+
}
135+
};
78136

79137
const handleAppChange = (appName: string) => {
80138
setActiveAppName(appName);
@@ -112,7 +170,15 @@ export function AppContent() {
112170
<Navigate to={findFirstRoute(activeApp.navigation)} replace />
113171
} />
114172
<Route path="/:objectName" element={
115-
<ObjectView dataSource={dataSource} objects={allObjects} onEdit={handleEdit} />
173+
<ObjectView
174+
dataSource={dataSource}
175+
objects={allObjects}
176+
onEdit={handleEdit}
177+
onRowClick={handleRowClick}
178+
/>
179+
} />
180+
<Route path="/:objectName/:recordId" element={
181+
<RecordDetailView dataSource={dataSource} objects={allObjects} onEdit={handleEdit} />
116182
} />
117183
<Route path="/dashboard/:dashboardName" element={
118184
<DashboardView />

packages/plugin-list/src/ListView.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ function convertFilterGroupToAST(group: FilterGroup): any[] {
5959
}
6060

6161
export const ListView: React.FC<ListViewProps> = ({
62-
schema,
62+
schema: propSchema,
6363
className,
6464
onViewChange,
6565
onFilterChange,
6666
onSortChange,
6767
onSearchChange,
6868
...props
6969
}) => {
70+
// Kernel level default: Ensure viewType is always defined (default to 'grid')
71+
const schema = React.useMemo(() => ({
72+
...propSchema,
73+
viewType: propSchema.viewType || 'grid'
74+
}), [propSchema]);
75+
7076
const [currentView, setCurrentView] = React.useState<ViewType>(
71-
(schema.viewType as ViewType) || 'grid'
77+
(schema.viewType as ViewType)
7278
);
7379
const [searchTerm, setSearchTerm] = React.useState('');
7480

0 commit comments

Comments
 (0)