Skip to content

Commit 9ac7575

Browse files
Copilothotlong
andcommitted
Update Storybook examples with enhanced editing demonstrations
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 35cdc0b commit 9ac7575

2 files changed

Lines changed: 115 additions & 16 deletions

File tree

packages/components/src/stories-json/data-table.stories.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const FullFeatures: Story = {
6262
export const EditableTable: Story = {
6363
args: {
6464
type: 'data-table',
65-
caption: 'Editable Product Inventory',
65+
caption: 'Editable Product Inventory - Simple Cell Editing',
6666
searchable: false,
6767
pagination: false,
6868
editable: true,
@@ -86,3 +86,40 @@ export const EditableTable: Story = {
8686
render: (args) => <SchemaRenderer schema={args} />
8787
};
8888

89+
export const BatchEditTable: Story = {
90+
args: {
91+
type: 'data-table',
92+
caption: 'Batch Edit Mode - Edit Multiple Rows & Save Together',
93+
searchable: false,
94+
pagination: false,
95+
editable: true,
96+
rowActions: true,
97+
columns: [
98+
{ header: 'ID', accessorKey: 'id', width: '60px', editable: false },
99+
{ header: 'Product Name', accessorKey: 'name' },
100+
{ header: 'Category', accessorKey: 'category' },
101+
{ header: 'Price', accessorKey: 'price' },
102+
{ header: 'Stock', accessorKey: 'stock' }
103+
],
104+
data: [
105+
{ id: 1, name: 'Wireless Mouse', category: 'Electronics', price: '$29.99', stock: 50 },
106+
{ id: 2, name: 'USB-C Cable', category: 'Accessories', price: '$12.99', stock: 100 },
107+
{ id: 3, name: 'Laptop Stand', category: 'Accessories', price: '$45.99', stock: 25 },
108+
{ id: 4, name: 'Webcam HD', category: 'Electronics', price: '$79.99', stock: 15 },
109+
{ id: 5, name: 'Desk Lamp', category: 'Furniture', price: '$34.99', stock: 30 }
110+
],
111+
onRowSave: async (rowIndex: number, changes: Record<string, any>, row: any) => {
112+
console.log('Saving single row:', { rowIndex, changes, row });
113+
await new Promise(resolve => setTimeout(resolve, 500));
114+
alert(`✓ Saved changes for "${row.name}":\n${JSON.stringify(changes, null, 2)}`);
115+
},
116+
onBatchSave: async (allChanges: Array<{ rowIndex: number; changes: Record<string, any>; row: any }>) => {
117+
console.log('Batch saving all rows:', allChanges);
118+
await new Promise(resolve => setTimeout(resolve, 800));
119+
const summary = allChanges.map(c => `${c.row.name}: ${Object.keys(c.changes).length} field(s)`).join('\n');
120+
alert(`✓ Batch saved ${allChanges.length} rows:\n\n${summary}`);
121+
}
122+
},
123+
render: (args) => <SchemaRenderer schema={args} />
124+
};
125+

packages/components/src/stories-json/object-grid.stories.tsx

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ export const OpportunitiesGrid: Story = {
157157
};
158158

159159
/**
160-
* Editable Grid - Inline cell editing example
160+
* Editable Grid - Simple Inline Cell Editing
161161
*
162-
* This story demonstrates inline editing capabilities:
162+
* This story demonstrates basic inline editing capabilities:
163163
* - Double-click or press Enter to edit a cell
164164
* - Press Enter to save, Escape to cancel
165165
* - ID column is read-only (editable: false)
166+
* - Changes are immediately reported via onCellChange callback
166167
*/
167168
export const EditableGrid: Story = {
168169
render: renderStory,
@@ -179,27 +180,30 @@ export const EditableGrid: Story = {
179180
data: [
180181
{ id: 1, name: 'John Doe', email: 'john@example.com', role: 'Admin', status: 'Active' },
181182
{ id: 2, name: 'Jane Smith', email: 'jane@example.com', role: 'User', status: 'Active' },
182-
{ id: 3, name: 'Bob Johnson', email: 'bob@example.com', role: 'User', status: 'Inactive' }
183+
{ id: 3, name: 'Bob Johnson', email: 'bob@example.com', role: 'User', status: 'Inactive' },
184+
{ id: 4, name: 'Alice Williams', email: 'alice@example.com', role: 'User', status: 'Active' }
183185
],
184186
editable: true,
185187
pagination: false,
186188
className: 'w-full',
187189
onCellChange: (rowIndex: number, columnKey: string, newValue: any, row: any) => {
188190
console.log('Cell changed:', { rowIndex, columnKey, newValue, row });
189-
// In a real application, you would update your data source here
190-
// Example: await dataSource.update(row.id, { [columnKey]: newValue });
191+
alert(`✓ Cell updated immediately:\n${columnKey} = "${newValue}"`);
191192
}
192193
} as any,
193194
};
194195

195196
/**
196-
* Batch Edit Grid - Multi-row editing with batch save
197+
* Batch Edit Grid - Multi-Row Editing with Batch Save
197198
*
198-
* This story demonstrates batch editing capabilities:
199+
* This story demonstrates advanced batch editing capabilities:
199200
* - Edit multiple cells across multiple rows
200-
* - Modified rows are highlighted
201-
* - Save individual rows or batch save all changes
201+
* - Modified rows are highlighted with amber background
202+
* - Modified cells shown in bold amber text
203+
* - Save individual rows using row-level save buttons
204+
* - Batch save all changes at once using "Save All" button
202205
* - Cancel changes per row or all at once
206+
* - Toolbar shows count of modified rows
203207
*/
204208
export const BatchEditGrid: Story = {
205209
render: renderStory,
@@ -209,14 +213,16 @@ export const BatchEditGrid: Story = {
209213
columns: [
210214
{ field: 'sku', header: 'SKU', width: 120, editable: false },
211215
{ field: 'name', header: 'Product Name', sortable: true },
216+
{ field: 'category', header: 'Category', sortable: true },
212217
{ field: 'price', header: 'Price', sortable: true },
213218
{ field: 'stock', header: 'Stock', sortable: true }
214219
],
215220
data: [
216-
{ sku: 'PROD-001', name: 'Laptop', price: '$1299.99', stock: 15 },
217-
{ sku: 'PROD-002', name: 'Mouse', price: '$29.99', stock: 120 },
218-
{ sku: 'PROD-003', name: 'Keyboard', price: '$79.99', stock: 45 },
219-
{ sku: 'PROD-004', name: 'Monitor', price: '$399.99', stock: 22 }
221+
{ sku: 'PROD-001', name: 'Laptop', category: 'Electronics', price: '$1299.99', stock: 15 },
222+
{ sku: 'PROD-002', name: 'Mouse', category: 'Electronics', price: '$29.99', stock: 120 },
223+
{ sku: 'PROD-003', name: 'Keyboard', category: 'Accessories', price: '$79.99', stock: 45 },
224+
{ sku: 'PROD-004', name: 'Monitor', category: 'Electronics', price: '$399.99', stock: 22 },
225+
{ sku: 'PROD-005', name: 'USB Cable', category: 'Accessories', price: '$12.99', stock: 200 }
220226
],
221227
editable: true,
222228
pagination: false,
@@ -226,13 +232,69 @@ export const BatchEditGrid: Story = {
226232
console.log('Saving row:', { rowIndex, changes, row });
227233
// Simulate API call
228234
await new Promise(resolve => setTimeout(resolve, 500));
229-
alert(`Saved changes for ${row.name}: ${JSON.stringify(changes)}`);
235+
const changeList = Object.entries(changes).map(([k, v]) => ` ${k}: "${v}"`).join('\n');
236+
alert(`✓ Saved changes for "${row.name}":\n\n${changeList}`);
230237
},
231238
onBatchSave: async (allChanges: Array<{ rowIndex: number; changes: Record<string, any>; row: any }>) => {
232239
console.log('Batch saving:', allChanges);
233240
// Simulate API call
234241
await new Promise(resolve => setTimeout(resolve, 1000));
235-
alert(`Batch saved ${allChanges.length} rows`);
242+
const summary = allChanges.map(c =>
243+
`${c.row.name}: ${Object.keys(c.changes).join(', ')}`
244+
).join('\n');
245+
alert(`✓ Batch saved ${allChanges.length} rows:\n\n${summary}`);
246+
}
247+
} as any,
248+
};
249+
250+
/**
251+
* Advanced Batch Editing - Real-World Inventory Management
252+
*
253+
* This example shows a complete workflow:
254+
* - Large dataset with pagination
255+
* - Multiple editable fields
256+
* - Read-only columns (ID, SKU)
257+
* - Both row-level and batch save operations
258+
* - Search and filter capabilities
259+
*/
260+
export const AdvancedBatchEdit: Story = {
261+
render: renderStory,
262+
args: {
263+
type: 'object-grid',
264+
objectName: 'Inventory',
265+
columns: [
266+
{ field: 'id', header: 'ID', width: 60, editable: false },
267+
{ field: 'sku', header: 'SKU', width: 100, editable: false },
268+
{ field: 'name', header: 'Product Name', sortable: true },
269+
{ field: 'category', header: 'Category', sortable: true },
270+
{ field: 'price', header: 'Price ($)', sortable: true },
271+
{ field: 'stock', header: 'Stock', sortable: true },
272+
{ field: 'reorderLevel', header: 'Reorder At', sortable: true }
273+
],
274+
data: [
275+
{ id: 1, sku: 'ELEC-001', name: 'Wireless Mouse', category: 'Electronics', price: '29.99', stock: 45, reorderLevel: 20 },
276+
{ id: 2, sku: 'ELEC-002', name: 'USB Keyboard', category: 'Electronics', price: '49.99', stock: 32, reorderLevel: 15 },
277+
{ id: 3, sku: 'FURN-001', name: 'Desk Lamp', category: 'Furniture', price: '34.99', stock: 18, reorderLevel: 10 },
278+
{ id: 4, sku: 'ELEC-003', name: 'Webcam HD', category: 'Electronics', price: '79.99', stock: 12, reorderLevel: 10 },
279+
{ id: 5, sku: 'ACC-001', name: 'HDMI Cable', category: 'Accessories', price: '15.99', stock: 150, reorderLevel: 50 },
280+
{ id: 6, sku: 'FURN-002', name: 'Monitor Stand', category: 'Furniture', price: '45.99', stock: 28, reorderLevel: 12 },
281+
{ id: 7, sku: 'ELEC-004', name: 'USB Hub', category: 'Electronics', price: '24.99', stock: 65, reorderLevel: 25 },
282+
{ id: 8, sku: 'ACC-002', name: 'Mouse Pad', category: 'Accessories', price: '9.99', stock: 200, reorderLevel: 75 }
283+
],
284+
editable: true,
285+
pagination: true,
286+
pageSize: 5,
287+
rowActions: true,
288+
className: 'w-full',
289+
onRowSave: async (rowIndex: number, changes: Record<string, any>, row: any) => {
290+
console.log('Saving inventory row:', { rowIndex, changes, row });
291+
await new Promise(resolve => setTimeout(resolve, 600));
292+
alert(`✓ Updated inventory for "${row.name}"\n\nChanges:\n${JSON.stringify(changes, null, 2)}`);
293+
},
294+
onBatchSave: async (allChanges: Array<{ rowIndex: number; changes: Record<string, any>; row: any }>) => {
295+
console.log('Batch updating inventory:', allChanges);
296+
await new Promise(resolve => setTimeout(resolve, 1200));
297+
alert(`✓ Batch updated ${allChanges.length} inventory items\n\nProcessed successfully!`);
236298
}
237299
} as any,
238300
};

0 commit comments

Comments
 (0)