Skip to content

Commit e78925e

Browse files
Copilothotlong
andcommitted
Add comprehensive field type system and enhanced cell renderers
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent ccaf3c1 commit e78925e

5 files changed

Lines changed: 950 additions & 41 deletions

File tree

packages/plugin-object/src/ObjectTable.tsx

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import React, { useEffect, useState, useCallback } from 'react';
1717
import type { ObjectTableSchema, TableColumn, TableSchema, DataSource } from '@object-ui/types';
1818
import { SchemaRenderer } from '@object-ui/react';
19+
import { getCellRenderer } from './field-renderers';
1920

2021
export interface ObjectTableProps {
2122
/**
@@ -174,52 +175,17 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({
174175
if (customColumn) {
175176
generatedColumns.push(customColumn);
176177
} else {
177-
// Auto-generate column from field schema
178+
// Auto-generate column from field schema with type-aware cell renderer
179+
const CellRenderer = getCellRenderer(field.type);
180+
178181
const column: TableColumn = {
179182
header: field.label || fieldName,
180183
accessorKey: fieldName,
184+
cell: (value: any) => {
185+
return <CellRenderer value={value} field={field} />;
186+
},
181187
};
182188

183-
// Add field type-specific formatting hints
184-
if (field.type === 'date' || field.type === 'datetime') {
185-
column.type = 'date';
186-
} else if (field.type === 'boolean') {
187-
column.type = 'boolean';
188-
} else if (field.type === 'number' || field.type === 'currency' || field.type === 'percent') {
189-
column.type = 'number';
190-
} else if (field.type === 'image' || field.type === 'file') {
191-
// For file/image fields, display the name or count
192-
column.cell = (value: any) => {
193-
if (!value) return '-';
194-
if (Array.isArray(value)) {
195-
const count = value.length;
196-
const fileType = field.type === 'image' ? 'image' : 'file';
197-
return count === 1 ? `1 ${fileType}` : `${count} ${fileType}s`;
198-
}
199-
return value.name || value.original_name || 'File';
200-
};
201-
} else if (field.type === 'lookup' || field.type === 'master_detail') {
202-
// For relationship fields, display the name property if available
203-
column.cell = (value: any) => {
204-
if (!value) return '-';
205-
if (typeof value === 'object' && value !== null) {
206-
// Try common display properties first
207-
if (value.name) return value.name;
208-
if (value.label) return value.label;
209-
if (value._id) return value._id;
210-
// Fallback to object type indicator
211-
return '[Object]';
212-
}
213-
return String(value);
214-
};
215-
} else if (field.type === 'url') {
216-
// For URL fields, make them clickable
217-
column.cell = (value: any) => {
218-
if (!value) return '-';
219-
return value; // The table renderer should handle URL formatting
220-
};
221-
}
222-
223189
// Add sorting if field is sortable
224190
if (field.sortable !== false) {
225191
column.sortable = true;

0 commit comments

Comments
 (0)