hi-tm 0.11.4 → 0.11.7

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.
@@ -372,18 +372,62 @@ pageIndex = 0, // Default to first page (0-indexed)
372
372
  const isSelected = (rowId) => {
373
373
  return selectedRows.includes(rowId);
374
374
  };
375
+ // const handleCheckboxChange = (id: number) => {
376
+ // // Call your existing handleSelectionChange function
377
+ // // This will handle the hierarchical selection logic
378
+ // if (onSelectionChange) {
379
+ // onSelectionChange(id);
380
+ // } else {
381
+ // // Fallback to simple selection if no onSelectionChange is provided
382
+ // const updatedSelection = selectedRows.includes(id)
383
+ // ? selectedRows.filter((rowId) => rowId !== id)
384
+ // : [...selectedRows, id];
385
+ // setSelectedRows(updatedSelection);
386
+ // }
387
+ // };
375
388
  const handleCheckboxChange = (id) => {
376
- // Call your existing handleSelectionChange function
377
- // This will handle the hierarchical selection logic
378
- if (onSelectionChange) {
379
- onSelectionChange(id);
389
+ const findRowById = (rows, targetId) => {
390
+ for (const row of rows) {
391
+ if (row.id === targetId)
392
+ return row;
393
+ if (row.hasChildren && row.childRows) {
394
+ const found = findRowById(row.childRows, targetId);
395
+ if (found)
396
+ return found;
397
+ }
398
+ }
399
+ return null;
400
+ };
401
+ const getAllDescendantIds = (row) => {
402
+ let ids = [];
403
+ if (row.hasChildren && row.childRows) {
404
+ for (const child of row.childRows) {
405
+ ids.push(child.id);
406
+ ids = [...ids, ...getAllDescendantIds(child)];
407
+ }
408
+ }
409
+ return ids;
410
+ };
411
+ const updatedSelection = [...selectedRows];
412
+ const row = findRowById(rows, id);
413
+ if (!row)
414
+ return;
415
+ const descendantIds = getAllDescendantIds(row);
416
+ if (selectedRows.includes(id)) {
417
+ // Remove parent + all descendants
418
+ const idsToRemove = [id, ...descendantIds];
419
+ setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
380
420
  }
381
421
  else {
382
- // Fallback to simple selection if no onSelectionChange is provided
383
- const updatedSelection = selectedRows.includes(id)
384
- ? selectedRows.filter((rowId) => rowId !== id)
385
- : [...selectedRows, id];
386
- setSelectedRows(updatedSelection);
422
+ // Add parent + all descendants
423
+ const idsToAdd = [id, ...descendantIds];
424
+ setSelectedRows([
425
+ ...updatedSelection,
426
+ ...idsToAdd.filter((i) => !updatedSelection.includes(i)),
427
+ ]);
428
+ }
429
+ if (onSelectionChange) {
430
+ onSelectionChange(id);
387
431
  }
388
432
  };
389
433
  // Extract title and subtitle from row data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.11.4",
3
+ "version": "0.11.7",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {