@monolith-forensics/monolith-ui 1.3.24 → 1.3.25
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.
- package/dist/Table/TableProvider.js +35 -17
- package/dist/Table/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -51,6 +51,28 @@ const TableProvider = (_a) => {
|
|
|
51
51
|
const [selectionStatus, setSelectionStatus] = useState((savedSelectionState === null || savedSelectionState === void 0 ? void 0 : savedSelectionState.selectionStatus) || SelectionStatus.None);
|
|
52
52
|
const [excludedRowKeys, setExcludedRowKeys] = useState((savedSelectionState === null || savedSelectionState === void 0 ? void 0 : savedSelectionState.excludedRowKeys) || []);
|
|
53
53
|
const [selectedRowKeys, setSelectedRowKeys] = useState((savedSelectionState === null || savedSelectionState === void 0 ? void 0 : savedSelectionState.selectedRowKeys) || []);
|
|
54
|
+
const calculateSelectionTotal = (selectionState, totalRecords, dataLength = 0) => {
|
|
55
|
+
switch (selectionState.selectionStatus) {
|
|
56
|
+
case SelectionStatus.All:
|
|
57
|
+
return totalRecords || dataLength;
|
|
58
|
+
case SelectionStatus.SomeIncluded:
|
|
59
|
+
return selectionState.selectedRowKeys.length;
|
|
60
|
+
case SelectionStatus.SomeExcluded:
|
|
61
|
+
return totalRecords
|
|
62
|
+
? totalRecords - selectionState.excludedRowKeys.length
|
|
63
|
+
: dataLength - selectionState.excludedRowKeys.length;
|
|
64
|
+
default:
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const getCalculatedSelectionTotal = () => {
|
|
69
|
+
return calculateSelectionTotal({
|
|
70
|
+
selectedRowKeys,
|
|
71
|
+
excludedRowKeys,
|
|
72
|
+
selectionStatus,
|
|
73
|
+
totalSelected: 0,
|
|
74
|
+
}, props === null || props === void 0 ? void 0 : props.totalRecords, props.data.length);
|
|
75
|
+
};
|
|
54
76
|
const getColumnState = (dataField) => {
|
|
55
77
|
return columnState.find((col) => col.dataField === dataField);
|
|
56
78
|
};
|
|
@@ -382,6 +404,7 @@ const TableProvider = (_a) => {
|
|
|
382
404
|
selectedRowKeys,
|
|
383
405
|
excludedRowKeys,
|
|
384
406
|
selectionStatus,
|
|
407
|
+
totalSelected: 0,
|
|
385
408
|
};
|
|
386
409
|
if (props.data.length === selectedRowKeys.length + 1) {
|
|
387
410
|
newSelectionState.selectionStatus = SelectionStatus.All;
|
|
@@ -395,11 +418,12 @@ const TableProvider = (_a) => {
|
|
|
395
418
|
];
|
|
396
419
|
newSelectionState.excludedRowKeys =
|
|
397
420
|
newSelectionState.excludedRowKeys.filter((k) => k !== key);
|
|
421
|
+
newSelectionState.totalSelected = calculateSelectionTotal(newSelectionState, props === null || props === void 0 ? void 0 : props.totalRecords, props.data.length);
|
|
398
422
|
setSelectionStatus(newSelectionState.selectionStatus);
|
|
399
423
|
setSelectedRowKeys(newSelectionState.selectedRowKeys);
|
|
400
424
|
setExcludedRowKeys(newSelectionState.excludedRowKeys);
|
|
401
|
-
(_a = props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, newSelectionState);
|
|
402
425
|
saveSelectionState(newSelectionState);
|
|
426
|
+
(_a = props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, newSelectionState);
|
|
403
427
|
};
|
|
404
428
|
const deselectRow = (row) => {
|
|
405
429
|
var _a;
|
|
@@ -408,6 +432,7 @@ const TableProvider = (_a) => {
|
|
|
408
432
|
selectedRowKeys,
|
|
409
433
|
excludedRowKeys,
|
|
410
434
|
selectionStatus,
|
|
435
|
+
totalSelected: 0,
|
|
411
436
|
};
|
|
412
437
|
if (selectionStatus === SelectionStatus.All ||
|
|
413
438
|
selectionStatus === SelectionStatus.SomeExcluded) {
|
|
@@ -422,11 +447,12 @@ const TableProvider = (_a) => {
|
|
|
422
447
|
}
|
|
423
448
|
newSelectionState.selectedRowKeys =
|
|
424
449
|
newSelectionState.selectedRowKeys.filter((k) => k !== row[key]);
|
|
450
|
+
newSelectionState.totalSelected = calculateSelectionTotal(newSelectionState, props === null || props === void 0 ? void 0 : props.totalRecords, props.data.length);
|
|
425
451
|
setSelectionStatus(newSelectionState.selectionStatus);
|
|
426
452
|
setSelectedRowKeys(newSelectionState.selectedRowKeys);
|
|
427
453
|
setExcludedRowKeys(newSelectionState.excludedRowKeys);
|
|
428
|
-
(_a = props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, newSelectionState);
|
|
429
454
|
saveSelectionState(newSelectionState);
|
|
455
|
+
(_a = props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, newSelectionState);
|
|
430
456
|
};
|
|
431
457
|
const selectAllRows = () => {
|
|
432
458
|
var _a, _b;
|
|
@@ -435,15 +461,17 @@ const TableProvider = (_a) => {
|
|
|
435
461
|
selectedRowKeys,
|
|
436
462
|
excludedRowKeys,
|
|
437
463
|
selectionStatus,
|
|
464
|
+
totalSelected: 0,
|
|
438
465
|
};
|
|
439
466
|
newSelectionState.selectedRowKeys = keys;
|
|
440
467
|
newSelectionState.excludedRowKeys = [];
|
|
441
468
|
newSelectionState.selectionStatus = SelectionStatus.All;
|
|
469
|
+
newSelectionState.totalSelected = calculateSelectionTotal(newSelectionState, props === null || props === void 0 ? void 0 : props.totalRecords, props.data.length);
|
|
442
470
|
setSelectionStatus(newSelectionState.selectionStatus);
|
|
443
471
|
setSelectedRowKeys(newSelectionState.selectedRowKeys);
|
|
444
472
|
setExcludedRowKeys(newSelectionState.excludedRowKeys);
|
|
445
|
-
(_b = props.onSelectionChange) === null || _b === void 0 ? void 0 : _b.call(props, newSelectionState);
|
|
446
473
|
saveSelectionState(newSelectionState);
|
|
474
|
+
(_b = props.onSelectionChange) === null || _b === void 0 ? void 0 : _b.call(props, newSelectionState);
|
|
447
475
|
};
|
|
448
476
|
const clearSelections = () => {
|
|
449
477
|
var _a;
|
|
@@ -451,10 +479,12 @@ const TableProvider = (_a) => {
|
|
|
451
479
|
selectedRowKeys,
|
|
452
480
|
excludedRowKeys,
|
|
453
481
|
selectionStatus,
|
|
482
|
+
totalSelected: 0,
|
|
454
483
|
};
|
|
455
484
|
newSelectionState.selectedRowKeys = [];
|
|
456
485
|
newSelectionState.excludedRowKeys = [];
|
|
457
486
|
newSelectionState.selectionStatus = SelectionStatus.None;
|
|
487
|
+
newSelectionState.totalSelected = calculateSelectionTotal(newSelectionState, props === null || props === void 0 ? void 0 : props.totalRecords, props.data.length);
|
|
458
488
|
setSelectionStatus(newSelectionState.selectionStatus);
|
|
459
489
|
setSelectedRowKeys(newSelectionState.selectedRowKeys);
|
|
460
490
|
setExcludedRowKeys(newSelectionState.excludedRowKeys);
|
|
@@ -485,21 +515,8 @@ const TableProvider = (_a) => {
|
|
|
485
515
|
return false;
|
|
486
516
|
}
|
|
487
517
|
};
|
|
488
|
-
const getCalculatedSelectionTotal = () => {
|
|
489
|
-
switch (selectionStatus) {
|
|
490
|
-
case SelectionStatus.All:
|
|
491
|
-
return (props === null || props === void 0 ? void 0 : props.totalRecords) || props.data.length;
|
|
492
|
-
case SelectionStatus.SomeIncluded:
|
|
493
|
-
return selectedRowKeys.length;
|
|
494
|
-
case SelectionStatus.SomeExcluded:
|
|
495
|
-
return (props === null || props === void 0 ? void 0 : props.totalRecords)
|
|
496
|
-
? props.totalRecords - excludedRowKeys.length
|
|
497
|
-
: props.data.length - excludedRowKeys.length;
|
|
498
|
-
default:
|
|
499
|
-
return 0;
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
518
|
if (tableInstanceRef) {
|
|
519
|
+
console.log("set table instance ref");
|
|
503
520
|
tableInstanceRef.current = {
|
|
504
521
|
columnState,
|
|
505
522
|
setColumnState: updateColumnState,
|
|
@@ -537,6 +554,7 @@ const TableProvider = (_a) => {
|
|
|
537
554
|
selectedRowKeys,
|
|
538
555
|
excludedRowKeys,
|
|
539
556
|
selectionStatus,
|
|
557
|
+
totalSelected: getCalculatedSelectionTotal(),
|
|
540
558
|
}, selectRow,
|
|
541
559
|
deselectRow,
|
|
542
560
|
isRowSelected,
|
package/dist/Table/types.d.ts
CHANGED