cecomponent 2.0.48 → 2.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
+
import { CustomAction } from '../../../types/customActions';
|
|
2
3
|
export type ComponentType = "text-input" | "number-input" | "auto-suggest" | "date-picker" | "label-text" | "drop-down-input";
|
|
3
4
|
export interface ColumnConfig {
|
|
4
5
|
id: string;
|
|
@@ -104,6 +105,12 @@ interface CEDataGridDynamicTableProps {
|
|
|
104
105
|
* Receives the row data. If omitted, all rows are enabled.
|
|
105
106
|
*/
|
|
106
107
|
getRowDisabled?: (row: any) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Array of custom action icons to render in the action column.
|
|
110
|
+
* Developers can add their own icons with custom onclick functionality.
|
|
111
|
+
* @default []
|
|
112
|
+
*/
|
|
113
|
+
customActions?: CustomAction[];
|
|
107
114
|
}
|
|
108
115
|
declare const CEDataGridDynamicTable: React.FC<CEDataGridDynamicTableProps>;
|
|
109
116
|
export default CEDataGridDynamicTable;
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Actions Type Definitions for CEDataGridDynamicTable
|
|
3
|
+
*
|
|
4
|
+
* This file contains all type definitions needed to implement custom actions
|
|
5
|
+
* in the CEDataGridDynamicTable component.
|
|
6
|
+
*
|
|
7
|
+
* @author Development Team
|
|
8
|
+
* @version 1.0
|
|
9
|
+
* @date 2026-03-02
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for a custom action icon in the action column
|
|
13
|
+
*
|
|
14
|
+
* @template T - The row data type (defaults to any)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const action: CustomAction = {
|
|
18
|
+
* id: "export",
|
|
19
|
+
* icon: "/icons/export.svg",
|
|
20
|
+
* title: "Export Row",
|
|
21
|
+
* onClick: (row, rowIndex) => {
|
|
22
|
+
* console.log("Exporting row:", row);
|
|
23
|
+
* },
|
|
24
|
+
* };
|
|
25
|
+
*/
|
|
26
|
+
export interface CustomAction<T = any> {
|
|
27
|
+
/**
|
|
28
|
+
* Unique identifier for this action
|
|
29
|
+
*
|
|
30
|
+
* Used internally for React key rendering and debugging.
|
|
31
|
+
* Should be unique within the customActions array.
|
|
32
|
+
* Use kebab-case convention: "export-item", "send-email", etc.
|
|
33
|
+
*
|
|
34
|
+
* @example "export-row"
|
|
35
|
+
* @example "approve-item"
|
|
36
|
+
* @example "send-notification"
|
|
37
|
+
*/
|
|
38
|
+
id: string;
|
|
39
|
+
/**
|
|
40
|
+
* Path to the icon image
|
|
41
|
+
*
|
|
42
|
+
* Relative path to an icon file in the public folder.
|
|
43
|
+
* Supported formats: SVG (recommended), PNG, WebP, JPG
|
|
44
|
+
*
|
|
45
|
+
* Icons are rendered at 20x20 pixels.
|
|
46
|
+
* For best results, use SVG format for crisp scaling.
|
|
47
|
+
*
|
|
48
|
+
* @example "/icons/export.svg"
|
|
49
|
+
* @example "/icons/actions/approve.svg"
|
|
50
|
+
* @example "/public-assets/buttons/delete.png"
|
|
51
|
+
*/
|
|
52
|
+
icon: string;
|
|
53
|
+
/**
|
|
54
|
+
* Tooltip text shown on hover
|
|
55
|
+
*
|
|
56
|
+
* Should be concise and descriptive of what the action does.
|
|
57
|
+
* Displayed when user hovers over the icon.
|
|
58
|
+
* Keep to 1-3 words for better UX.
|
|
59
|
+
*
|
|
60
|
+
* @example "Export Row"
|
|
61
|
+
* @example "Send Email"
|
|
62
|
+
* @example "Archive Item"
|
|
63
|
+
* @example "Delete Permanently"
|
|
64
|
+
*/
|
|
65
|
+
title: string;
|
|
66
|
+
/**
|
|
67
|
+
* Click handler callback function
|
|
68
|
+
*
|
|
69
|
+
* Called when the user clicks the action icon.
|
|
70
|
+
*
|
|
71
|
+
* @param row - The complete row data object containing all column values
|
|
72
|
+
* @param rowIndex - The 0-based index of the row in the current page
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* onClick: (row, rowIndex) => {
|
|
76
|
+
* console.log(`Clicked row ${rowIndex}:`, row);
|
|
77
|
+
* }
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* onClick: async (row) => {
|
|
81
|
+
* await updateItemStatus(row.id, 'approved');
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* onClick: (row, rowIndex) => {
|
|
86
|
+
* setSelectedRow(row);
|
|
87
|
+
* setShowModal(true);
|
|
88
|
+
* }
|
|
89
|
+
*/
|
|
90
|
+
onClick: (row: T, rowIndex: number) => void | Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Optional condition to show/hide the action
|
|
93
|
+
*
|
|
94
|
+
* When provided, the action is only rendered if the condition returns true.
|
|
95
|
+
* Useful for role-based, status-based, or permission-based actions.
|
|
96
|
+
*
|
|
97
|
+
* Return type:
|
|
98
|
+
* - true: Action is displayed and clickable
|
|
99
|
+
* - false: Action is hidden (not rendered at all)
|
|
100
|
+
*
|
|
101
|
+
* Called for each row, so can be used to show different actions per row.
|
|
102
|
+
*
|
|
103
|
+
* @param row - The row data to evaluate
|
|
104
|
+
* @returns boolean - true to show the action, false to hide it
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* condition: (row) => row.status === "pending"
|
|
108
|
+
* // Only show for rows with pending status
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* condition: (row) => row.isOwner && row.draft === true
|
|
112
|
+
* // Show only if user is owner and row is draft
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* condition: (row) => !row.archived
|
|
116
|
+
* // Hide if row is already archived
|
|
117
|
+
*/
|
|
118
|
+
condition?: (row: T) => boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Array of custom actions for the data grid
|
|
122
|
+
* @type {CustomAction[]}
|
|
123
|
+
*/
|
|
124
|
+
export type CustomActions<T = any> = CustomAction<T>[];
|
|
125
|
+
/**
|
|
126
|
+
* Component props for custom actions feature
|
|
127
|
+
*
|
|
128
|
+
* This interface extends the CEDataGridDynamicTableProps
|
|
129
|
+
*/
|
|
130
|
+
export interface CustomActionsProps<T = any> {
|
|
131
|
+
/**
|
|
132
|
+
* Array of custom action configurations
|
|
133
|
+
*
|
|
134
|
+
* These actions will be rendered in the action column
|
|
135
|
+
* after the built-in action icons (Edit, Delete, Copy, View, etc.)
|
|
136
|
+
*
|
|
137
|
+
* Multiple custom actions are supported. Icons are arranged
|
|
138
|
+
* horizontally in the action cell using flexbox.
|
|
139
|
+
*
|
|
140
|
+
* @default []
|
|
141
|
+
* @example
|
|
142
|
+
* customActions={[
|
|
143
|
+
* {
|
|
144
|
+
* id: "export",
|
|
145
|
+
* icon: "/icons/export.svg",
|
|
146
|
+
* title: "Export",
|
|
147
|
+
* onClick: handleExport
|
|
148
|
+
* }
|
|
149
|
+
* ]}
|
|
150
|
+
*/
|
|
151
|
+
customActions?: CustomAction<T>[];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Extended CEDataGridDynamicTableProps including custom actions
|
|
155
|
+
*
|
|
156
|
+
* (This is a partial interface showing the custom actions property)
|
|
157
|
+
*/
|
|
158
|
+
export interface CEDataGridDynamicTablePropsWithCustomActions<T = any> extends CustomActionsProps<T> {
|
|
159
|
+
jsonData: T[];
|
|
160
|
+
columnList?: any[];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Handler function signature for custom action clicks
|
|
164
|
+
*
|
|
165
|
+
* @template T - The row data type
|
|
166
|
+
* @param row - The complete row object
|
|
167
|
+
* @param rowIndex - Zero-based index of the row
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* type CustomActionHandler<User> = (row: User, rowIndex: number) => void;
|
|
171
|
+
*
|
|
172
|
+
* const handleApprove: CustomActionHandler<User> = (user, idx) => {
|
|
173
|
+
* console.log(`Approving user ${user.id}`);
|
|
174
|
+
* };
|
|
175
|
+
*/
|
|
176
|
+
export type CustomActionHandler<T = any> = (row: T, rowIndex: number) => void | Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Condition predicate function signature
|
|
179
|
+
*
|
|
180
|
+
* @template T - The row data type
|
|
181
|
+
* @param row - The row to evaluate
|
|
182
|
+
* @returns boolean - true if action should be shown
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* type ActionCondition<User> = (row: User) => boolean;
|
|
186
|
+
*
|
|
187
|
+
* const isAdmin: ActionCondition<User> = (user) => user.role === 'admin';
|
|
188
|
+
*/
|
|
189
|
+
export type ActionCondition<T = any> = (row: T) => boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Builder helper for creating custom actions
|
|
192
|
+
*
|
|
193
|
+
* Provides type-safe way to build custom actions
|
|
194
|
+
*
|
|
195
|
+
* @template T - The row data type
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* class CustomActionBuilder<User> {
|
|
199
|
+
* private action: CustomAction<User> = { id: '', icon: '', title: '', onClick: () => {} };
|
|
200
|
+
*
|
|
201
|
+
* withId(id: string): this {
|
|
202
|
+
* this.action.id = id;
|
|
203
|
+
* return this;
|
|
204
|
+
* }
|
|
205
|
+
*
|
|
206
|
+
* build(): CustomAction<User> {
|
|
207
|
+
* return this.action;
|
|
208
|
+
* }
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* const action = new CustomActionBuilder<User>()
|
|
212
|
+
* .withId('approve')
|
|
213
|
+
* .build();
|
|
214
|
+
*/
|
|
215
|
+
declare class CustomActionBuilder<T = any> {
|
|
216
|
+
private action;
|
|
217
|
+
setId(id: string): this;
|
|
218
|
+
setIcon(icon: string): this;
|
|
219
|
+
setTitle(title: string): this;
|
|
220
|
+
setHandler(handler: CustomActionHandler<T>): this;
|
|
221
|
+
setCondition(condition: ActionCondition<T>): this;
|
|
222
|
+
build(): CustomAction<T>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Common icon paths
|
|
226
|
+
*
|
|
227
|
+
* Centralized constants for common action icons
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* import { ICON_PATHS } from './types';
|
|
231
|
+
*
|
|
232
|
+
* const action: CustomAction = {
|
|
233
|
+
* id: 'export',
|
|
234
|
+
* icon: ICON_PATHS.EXPORT,
|
|
235
|
+
* title: 'Export',
|
|
236
|
+
* onClick: handleExport,
|
|
237
|
+
* };
|
|
238
|
+
*/
|
|
239
|
+
declare const ICON_PATHS: {
|
|
240
|
+
readonly EXPORT: "/icons/actions/export.svg";
|
|
241
|
+
readonly IMPORT: "/icons/actions/import.svg";
|
|
242
|
+
readonly DUPLICATE: "/icons/actions/duplicate.svg";
|
|
243
|
+
readonly ARCHIVE: "/icons/actions/archive.svg";
|
|
244
|
+
readonly RESTORE: "/icons/actions/restore.svg";
|
|
245
|
+
readonly VIEW: "/icons/navigation/view.svg";
|
|
246
|
+
readonly EXPAND: "/icons/navigation/expand.svg";
|
|
247
|
+
readonly COLLAPSE: "/icons/navigation/collapse.svg";
|
|
248
|
+
readonly APPROVE: "/icons/status/approve.svg";
|
|
249
|
+
readonly REJECT: "/icons/status/reject.svg";
|
|
250
|
+
readonly PENDING: "/icons/status/pending.svg";
|
|
251
|
+
readonly EMAIL: "/icons/communication/email.svg";
|
|
252
|
+
readonly NOTIFY: "/icons/communication/notify.svg";
|
|
253
|
+
readonly SHARE: "/icons/communication/share.svg";
|
|
254
|
+
readonly COPY: "/icons/utility/copy.svg";
|
|
255
|
+
readonly PASTE: "/icons/utility/paste.svg";
|
|
256
|
+
readonly DOWNLOAD: "/icons/utility/download.svg";
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Common action conditions
|
|
260
|
+
*
|
|
261
|
+
* Pre-built condition functions for common scenarios
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* import { ACTION_CONDITIONS } from './types';
|
|
265
|
+
*
|
|
266
|
+
* const action: CustomAction = {
|
|
267
|
+
* id: 'approve',
|
|
268
|
+
* icon: ICON_PATHS.APPROVE,
|
|
269
|
+
* title: 'Approve',
|
|
270
|
+
* onClick: handleApprove,
|
|
271
|
+
* condition: ACTION_CONDITIONS.isPending,
|
|
272
|
+
* };
|
|
273
|
+
*/
|
|
274
|
+
declare const ACTION_CONDITIONS: {
|
|
275
|
+
/** Only show for pending items */
|
|
276
|
+
readonly isPending: (row: any) => boolean;
|
|
277
|
+
/** Only show for active items */
|
|
278
|
+
readonly isActive: (row: any) => boolean;
|
|
279
|
+
/** Only show for inactive items */
|
|
280
|
+
readonly isInactive: (row: any) => boolean;
|
|
281
|
+
/** Only show if not archived */
|
|
282
|
+
readonly isNotArchived: (row: any) => boolean;
|
|
283
|
+
/** Only show if archived */
|
|
284
|
+
readonly isArchived: (row: any) => boolean;
|
|
285
|
+
/** Only show if has ID */
|
|
286
|
+
readonly hasId: (row: any) => boolean;
|
|
287
|
+
/** Only show if draft */
|
|
288
|
+
readonly isDraft: (row: any) => boolean;
|
|
289
|
+
/** Only show if not draft */
|
|
290
|
+
readonly isNotDraft: (row: any) => boolean;
|
|
291
|
+
/** Always show */
|
|
292
|
+
readonly always: () => boolean;
|
|
293
|
+
/** Never show */
|
|
294
|
+
readonly never: () => boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Combine multiple conditions with AND logic
|
|
297
|
+
* @example
|
|
298
|
+
* condition: ACTION_CONDITIONS.and(
|
|
299
|
+
* ACTION_CONDITIONS.isPending,
|
|
300
|
+
* ACTION_CONDITIONS.isNotArchived
|
|
301
|
+
* )
|
|
302
|
+
*/
|
|
303
|
+
readonly and: (...conditions: ActionCondition[]) => (row: any) => boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Combine multiple conditions with OR logic
|
|
306
|
+
* @example
|
|
307
|
+
* condition: ACTION_CONDITIONS.or(
|
|
308
|
+
* (r) => r.status === 'pending',
|
|
309
|
+
* (r) => r.status === 'draft'
|
|
310
|
+
* )
|
|
311
|
+
*/
|
|
312
|
+
readonly or: (...conditions: ActionCondition[]) => (row: any) => boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Negate a condition
|
|
315
|
+
* @example
|
|
316
|
+
* condition: ACTION_CONDITIONS.not(ACTION_CONDITIONS.isArchived)
|
|
317
|
+
*/
|
|
318
|
+
readonly not: (condition: ActionCondition) => (row: any) => boolean;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Utility functions for custom actions
|
|
322
|
+
*/
|
|
323
|
+
declare const CustomActionUtils: {
|
|
324
|
+
/**
|
|
325
|
+
* Create a simple action without condition
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* const action = CustomActionUtils.create({
|
|
329
|
+
* id: 'export',
|
|
330
|
+
* icon: '/icons/export.svg',
|
|
331
|
+
* title: 'Export',
|
|
332
|
+
* onClick: (row) => console.log(row),
|
|
333
|
+
* });
|
|
334
|
+
*/
|
|
335
|
+
create<T = any>(config: Omit<CustomAction<T>, "condition">): CustomAction<T>;
|
|
336
|
+
/**
|
|
337
|
+
* Create a conditional action
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const action = CustomActionUtils.createConditional({
|
|
341
|
+
* id: 'approve',
|
|
342
|
+
* icon: '/icons/approve.svg',
|
|
343
|
+
* title: 'Approve',
|
|
344
|
+
* onClick: (row) => approve(row),
|
|
345
|
+
* condition: (row) => row.status === 'pending',
|
|
346
|
+
* });
|
|
347
|
+
*/
|
|
348
|
+
createConditional<T = any>(config: CustomAction<T>): CustomAction<T>;
|
|
349
|
+
/**
|
|
350
|
+
* Filter actions based on a condition
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* const visibleActions = CustomActionUtils.filterByCondition(
|
|
354
|
+
* customActions,
|
|
355
|
+
* currentRow
|
|
356
|
+
* );
|
|
357
|
+
*/
|
|
358
|
+
filterByCondition<T = any>(actions: CustomAction<T>[], row: T): CustomAction<T>[];
|
|
359
|
+
/**
|
|
360
|
+
* Check if an action should be shown for a specific row
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* if (CustomActionUtils.shouldShow(action, row)) {
|
|
364
|
+
* // Render action
|
|
365
|
+
* }
|
|
366
|
+
*/
|
|
367
|
+
shouldShow<T = any>(action: CustomAction<T>, row: T): boolean;
|
|
368
|
+
/**
|
|
369
|
+
* Validate all required fields are set
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* CustomActionUtils.validate(action); // throws if invalid
|
|
373
|
+
*/
|
|
374
|
+
validate<T = any>(action: CustomAction<T>): void;
|
|
375
|
+
/**
|
|
376
|
+
* Validate all actions in an array
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* CustomActionUtils.validateAll(customActions);
|
|
380
|
+
*/
|
|
381
|
+
validateAll<T = any>(actions: CustomAction<T>[]): void;
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Export utilities (types are already exported inline via export interface/type)
|
|
385
|
+
*/
|
|
386
|
+
export { CustomActionBuilder, ICON_PATHS, ACTION_CONDITIONS, CustomActionUtils, };
|
package/package.json
CHANGED