Skip to content

Commit 1942f73

Browse files
Copilothotlong
andcommitted
Unify table and grid modes into single ObjectTableSchema
Merged ObjectGridSchema properties into ObjectTableSchema for a unified schema: - Single type accepts both 'object-table' and 'object-grid' - Grid features (editable, keyboardNavigation, frozenColumns, resizableColumns) are now optional properties in ObjectTableSchema - ObjectGridSchema kept as deprecated type for backward compatibility - Simplified component implementation with single schema type - Updated documentation to show unified approach Benefits: - Simpler API - one schema type instead of two - Cleaner mental model - same type with optional grid features - Easier migration - just add editable: true for grid mode - Backward compatible - object-grid type still works Example: ```typescript // Traditional table { type: 'object-table', objectName: 'users', ... } // Grid mode (inline editing) { type: 'object-table', objectName: 'products', editable: true, ... } ``` Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 66f21c8 commit 1942f73

File tree

5 files changed

+129
-97
lines changed

5 files changed

+129
-97
lines changed

content/docs/plugins/plugin-object/index.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ The plugin provides three main components for building CRUD interfaces:
2020

2121
### ObjectTable
2222

23-
Enterprise-grade table component with dual modes: traditional CRUD operations and spreadsheet-like inline editing. Built on data-table foundation with automatic field type rendering.
23+
Enterprise-grade table component with unified schema supporting both traditional CRUD and spreadsheet-like inline editing. Built on data-table foundation with automatic field type rendering.
2424

2525
**Features:**
2626
- Auto-generated columns from ObjectQL schema
2727
- 20+ specialized field renderers (currency, percent, date, select badges, etc.)
2828
- Multi-column sorting, search, pagination, row selection
2929
- CSV export, column resizing, column reordering
30-
- Grid mode: inline editing, keyboard navigation, frozen columns
30+
- Optional grid mode: inline editing, keyboard navigation, frozen columns (set `editable: true`)
3131

32-
**Modes:**
33-
- `object-table`: Traditional table with CRUD operations
34-
- `object-grid`: Spreadsheet-like inline editing
32+
**Single unified schema:**
33+
- `type: 'object-table'` - Supports both traditional and grid modes
34+
- `type: 'object-grid'` - Deprecated, use `object-table` with `editable: true`
3535

3636
[Learn more about ObjectTable →](/docs/plugins/plugin-object/object-table)
3737

@@ -89,7 +89,6 @@ const dataSource = new ObjectQLDataSource({
8989
```typescript
9090
import type {
9191
ObjectTableSchema,
92-
ObjectGridSchema,
9392
ObjectFormSchema,
9493
ObjectViewSchema
9594
} from '@object-ui/plugin-object';
@@ -108,12 +107,12 @@ const tableSchema: ObjectTableSchema = {
108107
pageSize: 20
109108
};
110109

111-
// Object Grid (Inline Editing)
112-
const gridSchema: ObjectGridSchema = {
113-
type: 'object-grid',
110+
// Object Table (Grid Mode with inline editing)
111+
const gridSchema: ObjectTableSchema = {
112+
type: 'object-table',
114113
objectName: 'inventory',
115114
fields: ['sku', 'name', 'quantity', 'price'],
116-
editable: true,
115+
editable: true, // Enable grid mode
117116
keyboardNavigation: true,
118117
frozenColumns: 1
119118
};

content/docs/plugins/plugin-object/object-table.mdx

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ A specialized table component that automatically fetches and displays data from
1010

1111
## Overview
1212

13-
ObjectTable supports two modes:
14-
- **Table Mode** (`type: 'object-table'`): Traditional CRUD operations with auto-generated columns
15-
- **Grid Mode** (`type: 'object-grid'`): Spreadsheet-like inline editing with keyboard navigation
13+
ObjectTable is a single unified component that supports:
14+
- **Traditional Table Mode**: CRUD operations with search, filters, and pagination (default)
15+
- **Grid Mode**: Spreadsheet-like inline editing with keyboard navigation (set `editable: true`)
1616

17-
Both modes inherit all data-table features: sorting, filtering, pagination, row selection, CSV export, column resizing, and reordering.
17+
Both modes use the same `object-table` schema type and inherit all data-table features: sorting, filtering, pagination, row selection, CSV export, column resizing, and reordering.
1818

1919
## Interactive Demo
2020

@@ -39,11 +39,11 @@ Both modes inherit all data-table features: sorting, filtering, pagination, row
3939
export: true
4040
}
4141
}}
42-
title="ObjectTable - Table Mode"
42+
title="ObjectTable - Traditional Mode"
4343
description="Auto-generated columns with type-aware rendering and CRUD operations"
4444
/>
4545

46-
## Table Mode - Basic Usage
46+
## Traditional Mode - Basic Usage
4747

4848
```tsx
4949
import { ObjectTable } from '@object-ui/plugin-object';
@@ -74,17 +74,20 @@ function UsersTable() {
7474

7575
## Grid Mode - Inline Editing
7676

77+
Enable spreadsheet-like editing by setting `editable: true`:
78+
7779
```tsx
7880
function InventoryGrid() {
7981
return (
8082
<ObjectTable
8183
schema={{
82-
type: 'object-grid',
84+
type: 'object-table',
8385
objectName: 'inventory',
8486
fields: ['sku', 'name', 'quantity', 'price', 'status'],
85-
editable: true,
86-
keyboardNavigation: true,
87-
frozenColumns: 2,
87+
// Grid mode features
88+
editable: true, // Enable inline editing
89+
keyboardNavigation: true, // Arrow keys, Tab, Enter
90+
frozenColumns: 2, // Freeze first 2 columns
8891
resizableColumns: true
8992
}}
9093
dataSource={dataSource}
@@ -129,14 +132,16 @@ ObjectTable automatically uses specialized renderers based on field types:
129132

130133
| Property | Type | Default | Description |
131134
|----------|------|---------|-------------|
132-
| `type` | `'object-table'` \| `'object-grid'` | Required | Component mode |
135+
| `type` | `'object-table'` \| `'object-grid'`* | Required | Component type |
133136
| `objectName` | string | Required | Name of the ObjectQL object |
134137
| `fields` | string[] | All fields | Fields to display as columns |
135138
| `data` | any[] | - | Inline data (optional) |
136139
| `pageSize` | number | `10` | Rows per page |
137140
| `selectable` | boolean \| `'single'` \| `'multiple'` | `false` | Row selection mode |
138141

139-
### Table Mode Properties
142+
*Note: Both `object-table` and `object-grid` types are supported for backward compatibility, but they now use the same unified implementation.
143+
144+
### Traditional Table Properties
140145

141146
| Property | Type | Description |
142147
|----------|------|-------------|
@@ -147,15 +152,19 @@ ObjectTable automatically uses specialized renderers based on field types:
147152

148153
### Grid Mode Properties
149154

150-
| Property | Type | Description |
151-
|----------|------|-------------|
152-
| `editable` | boolean | Enable inline cell editing |
153-
| `keyboardNavigation` | boolean | Arrow keys, Tab, Enter navigation |
154-
| `frozenColumns` | number | Number of left-pinned columns |
155-
| `resizableColumns` | boolean | Enable column resizing |
155+
Add these properties to enable spreadsheet-like behavior:
156+
157+
| Property | Type | Default | Description |
158+
|----------|------|---------|-------------|
159+
| `editable` | boolean | `false` | Enable inline cell editing |
160+
| `keyboardNavigation` | boolean | `true` | Arrow keys, Tab, Enter navigation |
161+
| `frozenColumns` | number | `0` | Number of left-pinned columns |
162+
| `resizableColumns` | boolean | `false` | Enable column resizing |
156163

157164
## Keyboard Shortcuts (Grid Mode)
158165

166+
When `editable` and `keyboardNavigation` are enabled:
167+
159168
| Shortcut | Action |
160169
|----------|--------|
161170
| `` `` `` `` | Navigate between cells |
@@ -164,20 +173,70 @@ ObjectTable automatically uses specialized renderers based on field types:
164173
| `Enter` | Start editing selected cell |
165174
| `Escape` | Cancel editing |
166175

167-
## Migration from ObjectGrid
176+
## Examples
168177

169-
ObjectGrid has been merged into ObjectTable:
178+
### CRM Contact Table
179+
180+
```tsx
181+
<ObjectTable
182+
schema={{
183+
type: 'object-table',
184+
objectName: 'contacts',
185+
title: 'Contact Management',
186+
fields: ['fullName', 'email', 'phone', 'company', 'status', 'owner'],
187+
operations: {
188+
create: true,
189+
update: true,
190+
delete: true,
191+
export: true
192+
},
193+
showSearch: true,
194+
selectable: 'multiple',
195+
pageSize: 25,
196+
defaultSort: {
197+
field: 'fullName',
198+
order: 'asc'
199+
}
200+
}}
201+
dataSource={dataSource}
202+
/>
203+
```
204+
205+
### Editable Product Grid
206+
207+
```tsx
208+
<ObjectTable
209+
schema={{
210+
type: 'object-table',
211+
objectName: 'products',
212+
fields: ['sku', 'name', 'category', 'price', 'stock', 'status'],
213+
editable: true,
214+
keyboardNavigation: true,
215+
frozenColumns: 2,
216+
resizableColumns: true,
217+
pageSize: 50
218+
}}
219+
dataSource={dataSource}
220+
onCellChange={(rowIndex, columnKey, newValue) => {
221+
updateProduct(rowIndex, columnKey, newValue);
222+
}}
223+
/>
224+
```
225+
226+
## Migration
227+
228+
### From ObjectGrid (deprecated type)
229+
230+
The `object-grid` type is still supported but deprecated. For new code, use `object-table` with `editable: true`:
170231

171232
**Before:**
172233
```tsx
173-
import { ObjectGrid } from '@object-ui/plugin-object';
174-
<ObjectGrid schema={{ type: 'object-grid', ... }} />
234+
<ObjectTable schema={{ type: 'object-grid', editable: true, ... }} />
175235
```
176236

177-
**After:**
237+
**After (recommended):**
178238
```tsx
179-
import { ObjectTable } from '@object-ui/plugin-object';
180-
<ObjectTable schema={{ type: 'object-grid', ... }} />
239+
<ObjectTable schema={{ type: 'object-table', editable: true, ... }} />
181240
```
182241

183242
## Related Components

packages/plugin-object/src/ObjectTable.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
*/
1616

1717
import React, { useEffect, useState, useCallback } from 'react';
18-
import type { ObjectTableSchema, ObjectGridSchema, DataSource } from '@object-ui/types';
18+
import type { ObjectTableSchema, DataSource } from '@object-ui/types';
1919
import { SchemaRenderer } from '@object-ui/react';
2020
import { getCellRenderer } from './field-renderers';
2121

22-
export type ObjectTableOrGridSchema = ObjectTableSchema | ObjectGridSchema;
23-
2422
export interface ObjectTableProps {
25-
schema: ObjectTableOrGridSchema;
23+
schema: ObjectTableSchema;
2624
dataSource?: DataSource;
2725
className?: string;
2826
onRowClick?: (record: any) => void;
@@ -198,7 +196,7 @@ export const ObjectTable: React.FC<ObjectTableProps> = ({
198196
sortable: true,
199197
exportable: operations?.export,
200198
rowActions: hasActions,
201-
resizableColumns: schema.type === 'object-grid' && 'resizableColumns' in schema ? schema.resizableColumns : true,
199+
resizableColumns: schema.resizableColumns !== undefined ? schema.resizableColumns : true,
202200
className: schema.className,
203201
onSelectionChange: onRowSelect,
204202
};

packages/plugin-object/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import React from 'react';
2020
import { ComponentRegistry } from '@object-ui/core';
2121

2222
export { ObjectTable } from './ObjectTable';
23-
export type { ObjectTableProps, ObjectTableOrGridSchema } from './ObjectTable';
23+
export type { ObjectTableProps } from './ObjectTable';
2424

2525
export { ObjectForm } from './ObjectForm';
2626
export type { ObjectFormProps } from './ObjectForm';

packages/types/src/objectql.ts

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ import type { FormField } from './form';
2424
* ObjectTable Schema
2525
* A specialized table component that automatically fetches and displays data from ObjectQL objects.
2626
* It reads the object schema from ObjectQL and generates columns automatically.
27+
*
28+
* Supports two modes:
29+
* - Traditional table mode: CRUD operations with search, filters, pagination
30+
* - Grid mode: Spreadsheet-like inline editing with keyboard navigation (set editable: true)
2731
*/
2832
export interface ObjectTableSchema extends BaseSchema {
29-
type: 'object-table';
33+
type: 'object-table' | 'object-grid';
3034

3135
/**
3236
* ObjectQL object name (e.g., 'users', 'accounts', 'contacts')
@@ -157,85 +161,57 @@ export interface ObjectTableSchema extends BaseSchema {
157161
batchActions?: string[];
158162

159163
/**
160-
* Custom CSS class
161-
*/
162-
className?: string;
163-
}
164-
165-
/**
166-
* ObjectGrid Schema
167-
* Enhanced table component with Airtable-like features:
168-
* - Inline cell editing
169-
* - Keyboard navigation
170-
* - Column resizing
171-
* - Column freezing
172-
* - Advanced row selection
173-
*/
174-
export interface ObjectGridSchema extends BaseSchema {
175-
type: 'object-grid';
176-
177-
/**
178-
* ObjectQL object name
179-
*/
180-
objectName: string;
181-
182-
/**
183-
* Optional title
184-
*/
185-
title?: string;
186-
187-
/**
188-
* Fields to display
189-
*/
190-
fields?: string[];
191-
192-
/**
193-
* Custom column configurations
194-
*/
195-
columns?: TableColumn[];
196-
197-
/**
198-
* Inline data
199-
*/
200-
data?: any[];
201-
202-
/**
203-
* Enable inline editing
164+
* Enable inline cell editing (Grid mode)
165+
* When true, cells become editable on double-click or Enter key
204166
* @default false
205167
*/
206168
editable?: boolean;
207169

208170
/**
209-
* Enable keyboard navigation (arrow keys, Tab, Enter)
210-
* @default true
171+
* Enable keyboard navigation (Grid mode)
172+
* Arrow keys, Tab, Enter for cell navigation
173+
* @default true when editable is true
211174
*/
212175
keyboardNavigation?: boolean;
213176

214177
/**
215178
* Enable column resizing
179+
* Allows users to drag column borders to resize
216180
* @default false
217181
*/
218182
resizableColumns?: boolean;
219183

220184
/**
221185
* Number of columns to freeze (left-pin)
186+
* Useful for keeping certain columns visible while scrolling
222187
* @default 0
223188
*/
224189
frozenColumns?: number;
225190

226191
/**
227-
* Enable row selection
192+
* Custom CSS class
228193
*/
194+
className?: string;
195+
}
196+
197+
/**
198+
* ObjectGrid Schema
199+
* @deprecated Use ObjectTableSchema with editable: true instead
200+
* This type is kept for backward compatibility
201+
*/
202+
export interface ObjectGridSchema extends BaseSchema {
203+
type: 'object-grid';
204+
objectName: string;
205+
title?: string;
206+
fields?: string[];
207+
columns?: TableColumn[];
208+
data?: any[];
209+
editable?: boolean;
210+
keyboardNavigation?: boolean;
211+
resizableColumns?: boolean;
212+
frozenColumns?: number;
229213
selectable?: boolean | 'single' | 'multiple';
230-
231-
/**
232-
* Page size
233-
*/
234214
pageSize?: number;
235-
236-
/**
237-
* Custom CSS class
238-
*/
239215
className?: string;
240216
}
241217

0 commit comments

Comments
 (0)