hi-tm 0.19.0 → 0.19.2
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.
|
@@ -66,7 +66,7 @@ mobileCardConfig = {
|
|
|
66
66
|
}, showModalIcon = true, actionButtonsStyle, gridClassName, isMobileView = false, // Default to false
|
|
67
67
|
mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
|
|
68
68
|
pageIndex = 0, // Default to first page (0-indexed)
|
|
69
|
-
}) => {
|
|
69
|
+
largeDatasetThreshold = 200, }) => {
|
|
70
70
|
// Track which rows are expanded to show their children
|
|
71
71
|
const [expandedRows, setExpandedRows] = (0, react_2.useState)([]);
|
|
72
72
|
const [activeModal, setActiveModal] = (0, react_2.useState)(null);
|
|
@@ -214,87 +214,6 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
214
214
|
(0, react_2.useEffect)(() => {
|
|
215
215
|
setSelectedRows(selectedItems || []);
|
|
216
216
|
}, [selectedItems]);
|
|
217
|
-
// Handle checkbox change for row selection
|
|
218
|
-
// const handleCheckboxChange = (id: number) => {
|
|
219
|
-
// console.log(`Processing ID: ${id}`);
|
|
220
|
-
// // Create a new copy of the current selection
|
|
221
|
-
// let updatedSelection = [...selectedRows];
|
|
222
|
-
// // Check if the row is currently selected
|
|
223
|
-
// const isSelected = updatedSelection.includes(id);
|
|
224
|
-
// console.log(`ID ${id} is currently selected: ${isSelected}`);
|
|
225
|
-
// // Find the item in the rows data
|
|
226
|
-
// const findItemById = (items: TableRowData[] | undefined, itemId: number): TableRowData | null => {
|
|
227
|
-
// if (!items) return null;
|
|
228
|
-
// for (const item of items) {
|
|
229
|
-
// if (item.id === itemId) {
|
|
230
|
-
// return item;
|
|
231
|
-
// }
|
|
232
|
-
// if (item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
233
|
-
// const foundInChildren = findItemById(item.childRows, itemId);
|
|
234
|
-
// if (foundInChildren) return foundInChildren;
|
|
235
|
-
// }
|
|
236
|
-
// }
|
|
237
|
-
// return null;
|
|
238
|
-
// };
|
|
239
|
-
// const item = findItemById(rows!, id);
|
|
240
|
-
// console.log(`Found item for ID ${id}:`, item);
|
|
241
|
-
// if (isSelected) {
|
|
242
|
-
// // DESELECTION LOGIC
|
|
243
|
-
// console.log(`Deselecting ID ${id}`);
|
|
244
|
-
// // Remove the item itself
|
|
245
|
-
// updatedSelection = updatedSelection.filter(itemId => itemId !== id);
|
|
246
|
-
// // If item exists and has children, remove all children too
|
|
247
|
-
// if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
248
|
-
// // Function to collect all descendant IDs
|
|
249
|
-
// const getAllDescendantIds = (items: TableRowData[]): number[] => {
|
|
250
|
-
// let allIds: number[] = [];
|
|
251
|
-
// for (const childItem of items) {
|
|
252
|
-
// allIds.push(childItem.id);
|
|
253
|
-
// if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
|
|
254
|
-
// allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
|
|
255
|
-
// }
|
|
256
|
-
// }
|
|
257
|
-
// return allIds;
|
|
258
|
-
// };
|
|
259
|
-
// const descendantIds = getAllDescendantIds(item.childRows);
|
|
260
|
-
// console.log(`Descendant IDs to remove:`, descendantIds);
|
|
261
|
-
// // Remove all descendant IDs from the selection
|
|
262
|
-
// updatedSelection = updatedSelection.filter(itemId => !descendantIds.includes(itemId));
|
|
263
|
-
// }
|
|
264
|
-
// } else {
|
|
265
|
-
// // SELECTION LOGIC
|
|
266
|
-
// console.log(`Selecting ID ${id}`);
|
|
267
|
-
// // Add the item itself
|
|
268
|
-
// updatedSelection.push(id);
|
|
269
|
-
// // If item exists and has children, add all children too
|
|
270
|
-
// if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
271
|
-
// // Function to collect all descendant IDs
|
|
272
|
-
// const getAllDescendantIds = (items: TableRowData[]): number[] => {
|
|
273
|
-
// let allIds: number[] = [];
|
|
274
|
-
// for (const childItem of items) {
|
|
275
|
-
// allIds.push(childItem.id);
|
|
276
|
-
// if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
|
|
277
|
-
// allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
|
|
278
|
-
// }
|
|
279
|
-
// }
|
|
280
|
-
// return allIds;
|
|
281
|
-
// };
|
|
282
|
-
// const descendantIds = getAllDescendantIds(item.childRows);
|
|
283
|
-
// console.log(`Descendant IDs to add:`, descendantIds);
|
|
284
|
-
// // Add all descendant IDs to the selection if not already included
|
|
285
|
-
// for (const descendantId of descendantIds) {
|
|
286
|
-
// if (!updatedSelection.includes(descendantId)) {
|
|
287
|
-
// updatedSelection.push(descendantId);
|
|
288
|
-
// }
|
|
289
|
-
// }
|
|
290
|
-
// }
|
|
291
|
-
// }
|
|
292
|
-
// console.log("New selection:", updatedSelection);
|
|
293
|
-
// setSelectedRows(updatedSelection);
|
|
294
|
-
// if (onSelectionChange) {
|
|
295
|
-
// onSelectionChange([...updatedSelection]);
|
|
296
|
-
// }
|
|
297
|
-
// };
|
|
298
217
|
// Function to determine if a row has any descendants selected (not just direct children)
|
|
299
218
|
const isIndeterminate = (rowId) => {
|
|
300
219
|
// Find the row in the data
|
|
@@ -363,7 +282,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
363
282
|
};
|
|
364
283
|
// const handleCheckboxChange = (id: number) => {
|
|
365
284
|
// // Call your existing handleSelectionChange function
|
|
366
|
-
//
|
|
285
|
+
// // This will handle the hierarchical selection logic
|
|
367
286
|
// if (onSelectionChange) {
|
|
368
287
|
// onSelectionChange(id);
|
|
369
288
|
// } else {
|
|
@@ -376,7 +295,13 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
376
295
|
// };
|
|
377
296
|
const [isProcessing, setIsProcessing] = (0, react_2.useState)(false);
|
|
378
297
|
const handleCheckboxChange = async (id) => {
|
|
379
|
-
|
|
298
|
+
// Determine dataset size up-front to decide UX behavior
|
|
299
|
+
const totalRows = Array.isArray(rows) ? rows.length : 0;
|
|
300
|
+
const isLargeDataset = totalRows >= largeDatasetThreshold;
|
|
301
|
+
// Only show processing state for large datasets
|
|
302
|
+
if (isLargeDataset) {
|
|
303
|
+
setIsProcessing(true);
|
|
304
|
+
}
|
|
380
305
|
try {
|
|
381
306
|
const findRowById = (rows, targetId) => {
|
|
382
307
|
for (const row of rows) {
|
|
@@ -401,28 +326,36 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
401
326
|
return ids;
|
|
402
327
|
};
|
|
403
328
|
const updatedSelection = [...selectedRows];
|
|
404
|
-
const row = findRowById(rows, id);
|
|
329
|
+
const row = rows ? findRowById(rows, id) : null;
|
|
405
330
|
if (!row)
|
|
406
331
|
return;
|
|
407
332
|
const descendantIds = getAllDescendantIds(row);
|
|
408
|
-
|
|
333
|
+
// Apply artificial delay only for large datasets to avoid blocking small lists
|
|
334
|
+
if (isLargeDataset) {
|
|
335
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
336
|
+
}
|
|
337
|
+
let nextSelected = [];
|
|
409
338
|
if (selectedRows.includes(id)) {
|
|
410
339
|
const idsToRemove = [id, ...descendantIds];
|
|
411
|
-
|
|
340
|
+
nextSelected = updatedSelection.filter((itemId) => !idsToRemove.includes(itemId));
|
|
341
|
+
setSelectedRows(nextSelected);
|
|
412
342
|
}
|
|
413
343
|
else {
|
|
414
344
|
const idsToAdd = [id, ...descendantIds];
|
|
415
|
-
|
|
345
|
+
nextSelected = [
|
|
416
346
|
...updatedSelection,
|
|
417
347
|
...idsToAdd.filter((i) => !updatedSelection.includes(i)),
|
|
418
|
-
]
|
|
348
|
+
];
|
|
349
|
+
setSelectedRows(nextSelected);
|
|
419
350
|
}
|
|
420
351
|
if (onSelectionChange) {
|
|
421
|
-
onSelectionChange(id);
|
|
352
|
+
onSelectionChange(id, { totalRows, selectedIds: nextSelected, isLargeDataset });
|
|
422
353
|
}
|
|
423
354
|
}
|
|
424
355
|
finally {
|
|
425
|
-
|
|
356
|
+
if (isLargeDataset) {
|
|
357
|
+
setIsProcessing(false);
|
|
358
|
+
}
|
|
426
359
|
}
|
|
427
360
|
};
|
|
428
361
|
// Extract title and subtitle from row data
|
|
@@ -71,7 +71,11 @@ export interface ModernTableProps {
|
|
|
71
71
|
onView?: (id: number) => void;
|
|
72
72
|
onAction?: (actionId: number, rowId: number) => void;
|
|
73
73
|
selectable: boolean;
|
|
74
|
-
onSelectionChange?: (id: number | number[]
|
|
74
|
+
onSelectionChange?: (id: number | number[], context?: {
|
|
75
|
+
totalRows: number;
|
|
76
|
+
selectedIds: number[];
|
|
77
|
+
isLargeDataset: boolean;
|
|
78
|
+
}) => void;
|
|
75
79
|
checkBoxDisable?: boolean;
|
|
76
80
|
actions?: boolean;
|
|
77
81
|
actionModalTopClassName?: string;
|
|
@@ -107,4 +111,9 @@ export interface ModernTableProps {
|
|
|
107
111
|
* @default 0
|
|
108
112
|
*/
|
|
109
113
|
pageIndex?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Threshold above which datasets are considered large for selection logic context
|
|
116
|
+
* @default 200
|
|
117
|
+
*/
|
|
118
|
+
largeDatasetThreshold?: number;
|
|
110
119
|
}
|