Skip to content

Commit 65b9618

Browse files
Copilothotlong
andcommitted
Fix TypeScript errors and successfully build data-object package
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent ddb75b8 commit 65b9618

File tree

4 files changed

+37
-91
lines changed

4 files changed

+37
-91
lines changed

packages/data-object/src/ObjectForm.tsx

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77

88
import React, { useEffect, useState, useCallback } from 'react';
9-
import type { ObjectFormSchema, FormField } from '@object-ui/types';
9+
import type { ObjectFormSchema, FormField, FormSchema } from '@object-ui/types';
1010
import type { ObjectQLDataSource } from '@object-ui/data-objectql';
11-
import { Form } from '@object-ui/components';
11+
import { SchemaRenderer } from '@object-ui/react';
1212

1313
export interface ObjectFormProps {
1414
/**
@@ -48,7 +48,6 @@ export interface ObjectFormProps {
4848
export const ObjectForm: React.FC<ObjectFormProps> = ({
4949
schema,
5050
dataSource,
51-
className,
5251
}) => {
5352
const [objectSchema, setObjectSchema] = useState<any>(null);
5453
const [formFields, setFormFields] = useState<FormField[]>([]);
@@ -60,7 +59,6 @@ export const ObjectForm: React.FC<ObjectFormProps> = ({
6059
useEffect(() => {
6160
const fetchObjectSchema = async () => {
6261
try {
63-
// TODO: Implement actual schema fetching from ObjectQL
6462
const schemaData = await dataSource.getObjectSchema(schema.objectName);
6563
setObjectSchema(schemaData);
6664
} catch (err) {
@@ -144,24 +142,6 @@ export const ObjectForm: React.FC<ObjectFormProps> = ({
144142
formField.maxLength = field.maxLength;
145143
}
146144

147-
// Add validation rules
148-
if (field.required) {
149-
formField.validation = formField.validation || [];
150-
formField.validation.push({
151-
type: 'required',
152-
message: `${field.label || fieldName} is required`,
153-
});
154-
}
155-
156-
if (field.pattern) {
157-
formField.validation = formField.validation || [];
158-
formField.validation.push({
159-
type: 'pattern',
160-
pattern: field.pattern,
161-
message: field.patternErrorMessage || `Invalid ${field.label || fieldName} format`,
162-
});
163-
}
164-
165145
generatedFields.push(formField);
166146
}
167147
});
@@ -228,37 +208,35 @@ export const ObjectForm: React.FC<ObjectFormProps> = ({
228208
);
229209
}
230210

231-
// Convert to Form schema and render
232-
const formSchema = {
233-
type: 'form' as const,
234-
title: schema.title,
235-
description: schema.description,
211+
// Convert to FormSchema
212+
const formSchema: FormSchema = {
213+
type: 'form',
236214
fields: formFields,
237-
layout: schema.layout || 'vertical',
215+
layout: schema.layout === 'grid' || schema.layout === 'inline' ? 'vertical' : schema.layout || 'vertical',
238216
columns: schema.columns,
239-
submitText: schema.submitText || (schema.mode === 'create' ? 'Create' : 'Update'),
240-
cancelText: schema.cancelText,
217+
submitLabel: schema.submitText || (schema.mode === 'create' ? 'Create' : 'Update'),
218+
cancelLabel: schema.cancelText,
241219
showSubmit: schema.showSubmit !== false && schema.mode !== 'view',
242220
showCancel: schema.showCancel !== false,
243-
showReset: schema.showReset,
221+
resetOnSubmit: schema.showReset,
222+
defaultValues: initialData,
223+
onSubmit: handleSubmit,
224+
onCancel: handleCancel,
244225
className: schema.className,
245226
};
246227

247228
return (
248-
<Form
249-
schema={formSchema}
250-
initialValues={initialData}
251-
onSubmit={handleSubmit}
252-
onCancel={handleCancel}
253-
/>
229+
<div className="w-full">
230+
<SchemaRenderer schema={formSchema} />
231+
</div>
254232
);
255233
};
256234

257235
/**
258236
* Map ObjectQL field type to form field type
259237
*/
260-
function mapFieldTypeToFormType(fieldType: string): FormField['type'] {
261-
const typeMap: Record<string, FormField['type']> = {
238+
function mapFieldTypeToFormType(fieldType: string): string {
239+
const typeMap: Record<string, string> = {
262240
text: 'input',
263241
textarea: 'textarea',
264242
number: 'input',

packages/data-object/src/ObjectTable.tsx

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
*/
77

88
import React, { useEffect, useState, useCallback } from 'react';
9-
import type { ObjectTableSchema } from '@object-ui/types';
9+
import type { ObjectTableSchema, TableColumn, TableSchema } from '@object-ui/types';
1010
import type { ObjectQLDataSource } from '@object-ui/data-objectql';
11-
import { Table } from '@object-ui/components';
12-
import type { TableColumn } from '@object-ui/types';
11+
import { SchemaRenderer } from '@object-ui/react';
1312

1413
export interface ObjectTableProps {
1514
/**
@@ -48,7 +47,6 @@ export interface ObjectTableProps {
4847
export const ObjectTable: React.FC<ObjectTableProps> = ({
4948
schema,
5049
dataSource,
51-
className,
5250
}) => {
5351
const [data, setData] = useState<any[]>([]);
5452
const [loading, setLoading] = useState(true);
@@ -60,8 +58,6 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({
6058
useEffect(() => {
6159
const fetchObjectSchema = async () => {
6260
try {
63-
// TODO: Implement actual schema fetching from ObjectQL
64-
// For now, we'll use a placeholder
6561
const schemaData = await dataSource.getObjectSchema(schema.objectName);
6662
setObjectSchema(schemaData);
6763
} catch (err) {
@@ -89,18 +85,15 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({
8985
if (!field) return;
9086

9187
// Check if there's a custom column configuration
92-
const customColumn = schema.columns?.find(col => col.name === fieldName);
88+
const customColumn = schema.columns?.find(col => col.accessorKey === fieldName);
9389

9490
if (customColumn) {
9591
generatedColumns.push(customColumn);
9692
} else {
9793
// Auto-generate column from field schema
9894
const column: TableColumn = {
99-
name: fieldName,
100-
label: field.label || fieldName,
101-
type: mapFieldTypeToColumnType(field.type),
102-
sortable: field.sortable !== false,
103-
filterable: field.filterable !== false,
95+
header: field.label || fieldName,
96+
accessorKey: fieldName,
10497
};
10598

10699
generatedColumns.push(column);
@@ -134,7 +127,7 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({
134127
}
135128

136129
const result = await dataSource.find(schema.objectName, params);
137-
setData(Array.isArray(result) ? result : result.value || []);
130+
setData(result.data || []);
138131
} catch (err) {
139132
console.error('Failed to fetch data:', err);
140133
setError(err as Error);
@@ -174,44 +167,18 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({
174167
);
175168
}
176169

177-
// Convert to Table schema and render
178-
const tableSchema = {
179-
type: 'table' as const,
180-
title: schema.title,
181-
description: schema.description,
170+
// Convert to TableSchema
171+
const tableSchema: TableSchema = {
172+
type: 'table',
173+
caption: schema.title,
182174
columns,
183175
data,
184-
pagination: schema.showPagination !== false ? {
185-
pageSize: schema.pageSize || 10,
186-
} : undefined,
187-
searchable: schema.showSearch !== false,
188-
filterable: schema.showFilters !== false,
189-
selectable: schema.selectable || false,
190176
className: schema.className,
191177
};
192178

193-
return <Table schema={tableSchema} onRefresh={handleRefresh} />;
179+
return (
180+
<div className="w-full">
181+
<SchemaRenderer schema={tableSchema} onAction={handleRefresh} />
182+
</div>
183+
);
194184
};
195-
196-
/**
197-
* Map ObjectQL field type to table column type
198-
*/
199-
function mapFieldTypeToColumnType(fieldType: string): TableColumn['type'] {
200-
const typeMap: Record<string, TableColumn['type']> = {
201-
text: 'text',
202-
number: 'number',
203-
currency: 'currency',
204-
percent: 'percent',
205-
date: 'date',
206-
datetime: 'datetime',
207-
boolean: 'boolean',
208-
email: 'link',
209-
url: 'link',
210-
image: 'image',
211-
select: 'badge',
212-
lookup: 'link',
213-
master_detail: 'link',
214-
};
215-
216-
return typeMap[fieldType] || 'text';
217-
}

packages/data-object/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "./dist",
5-
"rootDir": "./src",
65
"declaration": true,
76
"declarationMap": true
87
},

packages/data-objectql/src/ObjectQLDataSource.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
APIError
1919
} from '@object-ui/types';
2020

21-
import { DataApiClient } from '@objectql/sdk';
21+
import { DataApiClient, MetadataApiClient } from '@objectql/sdk';
2222
import type {
2323
DataApiClientConfig,
2424
DataApiListParams,
@@ -131,10 +131,12 @@ export interface ObjectQLConfig extends DataApiClientConfig {
131131
*/
132132
export class ObjectQLDataSource<T = any> implements DataSource<T> {
133133
private client: DataApiClient;
134+
private metadataClient: MetadataApiClient;
134135

135136
constructor(config: ObjectQLConfig) {
136137
// Initialize the official ObjectQL SDK client
137138
this.client = new DataApiClient(config);
139+
this.metadataClient = new MetadataApiClient(config);
138140
}
139141

140142
/**
@@ -373,8 +375,8 @@ export class ObjectQLDataSource<T = any> implements DataSource<T> {
373375
*/
374376
async getObjectSchema(objectName: string): Promise<any> {
375377
try {
376-
// Use the ObjectQL SDK to fetch object metadata
377-
const response = await this.client.getObjectMetadata(objectName);
378+
// Use the Metadata API client to fetch object metadata
379+
const response = await this.metadataClient.getObject(objectName);
378380
return response;
379381
} catch (err: any) {
380382
throw {

0 commit comments

Comments
 (0)