-
Notifications
You must be signed in to change notification settings - Fork 2
Add inline data support for ObjectTable and ObjectForm to fix documentation examples #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,8 +26,9 @@ export interface ObjectTableProps { | |||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * ObjectQL data source | ||||||||||||||||
| * Optional when inline data is provided in schema | ||||||||||||||||
| */ | ||||||||||||||||
| dataSource: ObjectQLDataSource; | ||||||||||||||||
| dataSource?: ObjectQLDataSource; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Additional CSS class | ||||||||||||||||
|
|
@@ -90,10 +91,24 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({ | |||||||||||||||
| const [columns, setColumns] = useState<TableColumn[]>([]); | ||||||||||||||||
| const [selectedRows, setSelectedRows] = useState<any[]>([]); | ||||||||||||||||
|
|
||||||||||||||||
| // Fetch object schema from ObjectQL | ||||||||||||||||
| // Check if using inline data | ||||||||||||||||
| const hasInlineData = Boolean(schema.data); | ||||||||||||||||
|
|
||||||||||||||||
| // Initialize with inline data if provided | ||||||||||||||||
| useEffect(() => { | ||||||||||||||||
| if (hasInlineData && schema.data) { | ||||||||||||||||
| setData(schema.data); | ||||||||||||||||
| setLoading(false); | ||||||||||||||||
| } | ||||||||||||||||
| }, [hasInlineData, schema.data]); | ||||||||||||||||
|
|
||||||||||||||||
| // Fetch object schema from ObjectQL (skip if using inline data) | ||||||||||||||||
| useEffect(() => { | ||||||||||||||||
| const fetchObjectSchema = async () => { | ||||||||||||||||
| try { | ||||||||||||||||
| if (!dataSource) { | ||||||||||||||||
| throw new Error('DataSource is required when using ObjectQL schema fetching (inline data not provided)'); | ||||||||||||||||
| } | ||||||||||||||||
| const schemaData = await dataSource.getObjectSchema(schema.objectName); | ||||||||||||||||
| setObjectSchema(schemaData); | ||||||||||||||||
| } catch (err) { | ||||||||||||||||
|
|
@@ -102,13 +117,43 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({ | |||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| if (schema.objectName && dataSource) { | ||||||||||||||||
| // Skip fetching schema if we have inline data and custom columns | ||||||||||||||||
| if (hasInlineData && schema.columns) { | ||||||||||||||||
| // Use a minimal schema for inline data with type safety | ||||||||||||||||
| setObjectSchema({ | ||||||||||||||||
| name: schema.objectName, | ||||||||||||||||
| fields: {} as Record<string, any>, | ||||||||||||||||
|
Comment on lines
+123
to
+125
|
||||||||||||||||
| setObjectSchema({ | |
| name: schema.objectName, | |
| fields: {} as Record<string, any>, | |
| const inlineFields: Record<string, unknown> = {}; | |
| setObjectSchema({ | |
| name: schema.objectName, | |
| fields: inlineFields, |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The header generation logic (capitalize first letter, replace underscores with spaces) is duplicated in the column generation logic elsewhere in the file. Consider extracting this into a helper function to improve maintainability.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -55,6 +55,13 @@ export interface ObjectTableSchema extends BaseSchema { | |||||
| */ | ||||||
| columns?: TableColumn[]; | ||||||
|
|
||||||
| /** | ||||||
| * Inline data for static/demo tables | ||||||
| * When provided, the table will use this data instead of fetching from a data source. | ||||||
| * Useful for documentation examples and prototyping. | ||||||
| */ | ||||||
| data?: any[]; | ||||||
|
||||||
| data?: any[]; | |
| data?: Record<string, unknown>[]; |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Record<string, any> type is too permissive. Consider using a generic type parameter or defining a more specific type to improve type safety for initial data values.
| initialData?: Record<string, any>; | |
| initialData?: Record<string, unknown>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an empty object with type assertion bypasses type safety. Consider using a more explicit type or ensuring this minimal schema has proper typing.