Skip to content

Commit d98c17c

Browse files
Copilothotlong
andcommitted
fix(plugin-aggrid): Address all PR review feedback
- Fix handleExportCSV to guard on gridRef.current?.api (issue #1) - Add dedicated onContextMenuAction callback instead of overloading onCellClicked (issue #2) - Remove icon property from customItems to prevent HTML injection (issue #3) - Remove validation claim from README - only basic AG Grid editing (issue #4) - Add test assertions for all new inputs (editable, exportConfig, etc.) (issue #5) - Fix onExport type to only support 'csv' format (issue #6) - Remove unused ColumnConfig properties (autoSize, groupable) (issue #9) - Type schema props with proper interfaces instead of 'any' (issue #10) - Update export description to only mention CSV (issue #11) - Add AG Grid Community vs Enterprise section to docs (issue #8) - Update README and docs with new callback and clarifications All tests pass (8/8), lint clean (0 errors) Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a830395 commit d98c17c

6 files changed

Lines changed: 51 additions & 27 deletions

File tree

content/docs/plugins/plugin-aggrid.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,14 @@ Note: `ag-grid-community` and `ag-grid-react` are peer dependencies and must be
365365
},
366366
height: 450
367367
}}
368-
title="Enterprise Features"
369-
description="Full-featured grid with editing, export, status bar, context menu, and more"
368+
title="Advanced Features"
369+
description="Full-featured grid with editing, export, status bar, context menu, and more (AG Grid Community)"
370370
/>
371371

372+
## AG Grid Community vs Enterprise
373+
374+
This plugin uses **AG Grid Community Edition** which is free and open source. All features shown in the examples above work with the Community edition. Some advanced features like integrated charting (`enableCharts`) may require AG Grid Enterprise (commercial license). See [AG Grid Pricing](https://www.ag-grid.com/license-pricing/) for details.
375+
372376
## Features
373377

374378
- **Lazy Loading**: AG Grid libraries are loaded on-demand for optimal performance

packages/plugin-aggrid/README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A lazy-loaded data grid component for Object UI based on AG Grid Community Editi
99
- **Automatic Registration**: Components auto-register with the ComponentRegistry
1010
- **Skeleton Loading**: Shows a skeleton while AG Grid loads
1111
- **Full AG Grid Features**: Sorting, filtering, pagination, cell rendering, and more
12-
- **Cell & Row Editing**: Inline editing with validation support
12+
- **Cell & Row Editing**: Inline editing using AG Grid's built-in editors
1313
- **CSV Export**: Built-in data export functionality
1414
- **Event Callbacks**: Handle cell clicks, selection changes, and value updates
1515
- **Status Bar**: Display aggregations (count, sum, avg, min, max)
@@ -19,6 +19,10 @@ A lazy-loaded data grid component for Object UI based on AG Grid Community Editi
1919
- **Multiple Themes**: Support for Quartz, Alpine, Balham, and Material themes
2020
- **Customizable**: Full access to AG Grid's GridOptions for advanced configuration
2121

22+
## AG Grid Community vs Enterprise
23+
24+
This plugin uses **AG Grid Community Edition** which is free and open source. Most features (sorting, filtering, editing, CSV export, basic context menu) work with the Community edition. Some advanced features like integrated charting may require AG Grid Enterprise (commercial license). See [AG Grid Pricing](https://www.ag-grid.com/license-pricing/) for details.
25+
2226
## Installation
2327

2428
```bash
@@ -160,7 +164,8 @@ const schema: AgGridSchema = {
160164
onRowClicked?: (event) => void, // Row click handler
161165
onSelectionChanged?: (event) => void, // Selection change handler
162166
onCellValueChanged?: (event) => void, // Cell value change handler
163-
onExport?: (data, format) => void // Export handler
167+
onExport?: (data, format) => void, // Export handler (CSV only)
168+
onContextMenuAction?: (action, rowData) => void // Context menu action handler
164169
},
165170

166171
// Column Configuration
@@ -363,15 +368,24 @@ const schema = {
363368
{
364369
name: 'Delete Row',
365370
action: 'delete',
366-
icon: '🗑️',
367371
disabled: false
368372
},
369373
{
370374
name: 'View Details',
371-
action: 'view',
372-
icon: '👁️'
375+
action: 'view'
373376
}
374377
]
378+
},
379+
callbacks: {
380+
onContextMenuAction: (action, rowData) => {
381+
console.log(`Action: ${action}`, rowData);
382+
// Handle custom menu actions
383+
if (action === 'delete') {
384+
deleteRow(rowData);
385+
} else if (action === 'view') {
386+
viewDetails(rowData);
387+
}
388+
}
375389
}
376390
};
377391
```

packages/plugin-aggrid/src/AgGridImpl.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default function AgGridImpl({
9494

9595
// CSV Export handler
9696
const handleExportCSV = useCallback(() => {
97-
if (!gridRef.current) return;
97+
if (!gridRef.current?.api) return;
9898

9999
const params = {
100100
fileName: exportConfig?.fileName || 'export.csv',
@@ -158,17 +158,11 @@ export default function AgGridImpl({
158158
contextMenu.customItems.forEach(customItem => {
159159
items.push({
160160
name: customItem.name,
161-
icon: customItem.icon,
162161
disabled: customItem.disabled,
163162
action: () => {
164-
// Trigger callback if defined
165-
if (callbacks?.onCellClicked) {
166-
// Invoke with the menu item action and row data
167-
const syntheticEvent = {
168-
...params,
169-
customAction: customItem.action,
170-
} as any;
171-
callbacks.onCellClicked(syntheticEvent);
163+
// Trigger dedicated context menu action callback
164+
if (callbacks?.onContextMenuAction) {
165+
callbacks.onContextMenuAction(customItem.action, params.node?.data);
172166
}
173167
},
174168
});

packages/plugin-aggrid/src/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('Plugin AgGrid', () => {
3535
const config = ComponentRegistry.getConfig('aggrid');
3636
const inputNames = config?.inputs?.map((input: any) => input.name) || [];
3737

38+
// Original inputs
3839
expect(inputNames).toContain('rowData');
3940
expect(inputNames).toContain('columnDefs');
4041
expect(inputNames).toContain('pagination');
@@ -46,6 +47,17 @@ describe('Plugin AgGrid', () => {
4647
expect(inputNames).toContain('animateRows');
4748
expect(inputNames).toContain('gridOptions');
4849
expect(inputNames).toContain('className');
50+
51+
// New inputs for enterprise features
52+
expect(inputNames).toContain('editable');
53+
expect(inputNames).toContain('singleClickEdit');
54+
expect(inputNames).toContain('exportConfig');
55+
expect(inputNames).toContain('statusBar');
56+
expect(inputNames).toContain('callbacks');
57+
expect(inputNames).toContain('columnConfig');
58+
expect(inputNames).toContain('enableRangeSelection');
59+
expect(inputNames).toContain('enableCharts');
60+
expect(inputNames).toContain('contextMenu');
4961
});
5062

5163
it('should have rowData and columnDefs as required inputs', () => {

packages/plugin-aggrid/src/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import 'ag-grid-community/styles/ag-theme-material.css';
2121
// Export types for external use
2222
export type { AgGridSchema, SimpleColumnDef, AgGridCallbacks, ExportConfig, StatusBarConfig, ColumnConfig, ContextMenuConfig } from './types';
2323

24+
import type { AgGridCallbacks, ExportConfig, StatusBarConfig, ColumnConfig, ContextMenuConfig } from './types';
25+
2426
// 🚀 Lazy load the implementation file
2527
// This ensures AG Grid is only loaded when the component is actually rendered
2628
const LazyAgGrid = React.lazy(() => import('./AgGridImpl'));
@@ -44,13 +46,13 @@ export interface AgGridRendererProps {
4446
editType?: 'fullRow';
4547
singleClickEdit?: boolean;
4648
stopEditingWhenCellsLoseFocus?: boolean;
47-
exportConfig?: any;
48-
statusBar?: any;
49-
callbacks?: any;
50-
columnConfig?: any;
49+
exportConfig?: ExportConfig;
50+
statusBar?: StatusBarConfig;
51+
callbacks?: AgGridCallbacks;
52+
columnConfig?: ColumnConfig;
5153
enableRangeSelection?: boolean;
5254
enableCharts?: boolean;
53-
contextMenu?: any;
55+
contextMenu?: ContextMenuConfig;
5456
};
5557
}
5658

@@ -194,7 +196,7 @@ ComponentRegistry.register(
194196
name: 'exportConfig',
195197
type: 'code',
196198
label: 'Export Config (JSON)',
197-
description: 'Configure CSV/Excel export: { enabled: true, fileName: "data.csv" }',
199+
description: 'Configure CSV export: { enabled: true, fileName: "data.csv" }',
198200
advanced: true
199201
},
200202
{

packages/plugin-aggrid/src/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export interface AgGridCallbacks {
1616
onRowClicked?: (event: RowClickedEvent) => void;
1717
onSelectionChanged?: (event: SelectionChangedEvent) => void;
1818
onCellValueChanged?: (event: CellValueChangedEvent) => void;
19-
onExport?: (data: any[], format: 'csv' | 'excel') => void;
19+
onExport?: (data: any[], format: 'csv') => void;
20+
onContextMenuAction?: (action: string, rowData: any) => void;
2021
}
2122

2223
/**
@@ -42,11 +43,9 @@ export interface StatusBarConfig {
4243
* Column configuration enhancements
4344
*/
4445
export interface ColumnConfig {
45-
autoSize?: boolean;
4646
resizable?: boolean;
4747
sortable?: boolean;
4848
filterable?: boolean;
49-
groupable?: boolean;
5049
}
5150

5251
/**
@@ -58,7 +57,6 @@ export interface ContextMenuConfig {
5857
customItems?: Array<{
5958
name: string;
6059
action: string;
61-
icon?: string;
6260
disabled?: boolean;
6361
}>;
6462
}

0 commit comments

Comments
 (0)