@monolith-forensics/monolith-ui 1.3.24 → 1.3.26

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.
@@ -29,6 +29,16 @@ export const TR = styled.div `
29
29
  visibility: visible;
30
30
  }
31
31
 
32
+ &[data-focused="true"] {
33
+ border-left: 1px solid ${({ theme }) => theme.palette.primary.main};
34
+ border-right: 1px solid ${({ theme }) => theme.palette.primary.main};
35
+
36
+ .mfui-td {
37
+ border-top: 1px solid ${({ theme }) => theme.palette.primary.main};
38
+ border-bottom: 1px solid ${({ theme }) => theme.palette.primary.main};
39
+ }
40
+ }
41
+
32
42
  &:hover > .mfui-td {
33
43
  background-color: ${({ theme }) => theme.palette.action.hover};
34
44
  }
@@ -19,7 +19,7 @@ import { SelectionStatus } from "./enums";
19
19
  import moment from "moment";
20
20
  export const TableContext = createContext(null);
21
21
  const TableProvider = (_a) => {
22
- var { children, columns, tableInstanceRef, stateStorage, height, maxHeight, minHeight } = _a, props = __rest(_a, ["children", "columns", "tableInstanceRef", "stateStorage", "height", "maxHeight", "minHeight"]);
22
+ var { children, columns, tableInstanceRef, stateStorage, height, maxHeight, minHeight, focusedRowId } = _a, props = __rest(_a, ["children", "columns", "tableInstanceRef", "stateStorage", "height", "maxHeight", "minHeight", "focusedRowId"]);
23
23
  const _columns = columns
24
24
  .map((child, index) => {
25
25
  if (child.dataField === "__key") {
@@ -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,19 +515,9 @@ 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
- }
518
+ const isRowFocused = (row) => {
519
+ const key = !!props.keyField ? row[props.keyField] : row.__key;
520
+ return focusedRowId === key;
501
521
  };
502
522
  if (tableInstanceRef) {
503
523
  tableInstanceRef.current = {
@@ -537,9 +557,11 @@ const TableProvider = (_a) => {
537
557
  selectedRowKeys,
538
558
  excludedRowKeys,
539
559
  selectionStatus,
560
+ totalSelected: getCalculatedSelectionTotal(),
540
561
  }, selectRow,
541
562
  deselectRow,
542
563
  isRowSelected,
564
+ isRowFocused,
543
565
  selectedRowKeys,
544
566
  getSelectedRowKeys,
545
567
  selectAllRows,
@@ -8,12 +8,13 @@ import ActionButton from "./ActionButton";
8
8
  import CheckBox from "../CheckBox";
9
9
  import { LoadingCellIndicator } from "./LoadingCellIndicator";
10
10
  const TableRow = ({ rowData, loading, rowStyle }) => {
11
- const { columnState, enableActionButton, onActionButtonClick, actionButtonIcon: Icon, enableSelection, selectRow, deselectRow, isRowSelected, onRowUpdated, } = useTable();
11
+ const { columnState, enableActionButton, onActionButtonClick, actionButtonIcon: Icon, enableSelection, selectRow, deselectRow, isRowSelected, isRowFocused, onRowUpdated, } = useTable();
12
12
  const selected = isRowSelected(rowData);
13
+ const focused = isRowFocused(rowData);
13
14
  const handleSelectionChange = (e) => {
14
15
  e === true ? selectRow(rowData) : deselectRow(rowData);
15
16
  };
16
- return (_jsxs(TR, { className: "mfui-tr", style: rowStyle, "data-key": rowData.__key, "data-selected": selected, children: [enableSelection && (_jsx(ActionCell, { className: `mfui-td column-select`, children: _jsx(InnerCellContent, { className: "mfui inner-cell-content row-action", children: _jsx(CheckBox, { className: `mfui-checkbox`, value: selected, onChange: (e) => handleSelectionChange(e) }) }) })), enableActionButton && (_jsx(ActionCell, { className: `mfui-td column-action`, children: _jsx(InnerCellContent, { className: "mfui inner-cell-content row-action", children: _jsx(ActionButton, { variant: "subtle", onClick: () => onActionButtonClick === null || onActionButtonClick === void 0 ? void 0 : onActionButtonClick(rowData), children: Icon ? _jsx(Icon, { size: 14 }) : _jsx(Maximize2Icon, { size: 14 }) }) }) })), columnState.map((column, index) => {
17
+ return (_jsxs(TR, { className: "mfui-tr", style: rowStyle, "data-key": rowData.__key, "data-selected": selected, "data-focused": focused, children: [enableSelection && (_jsx(ActionCell, { className: `mfui-td column-select`, children: _jsx(InnerCellContent, { className: "mfui inner-cell-content row-action", children: _jsx(CheckBox, { className: `mfui-checkbox`, value: selected, onChange: (e) => handleSelectionChange(e) }) }) })), enableActionButton && (_jsx(ActionCell, { className: `mfui-td column-action`, children: _jsx(InnerCellContent, { className: "mfui inner-cell-content row-action", children: _jsx(ActionButton, { variant: "subtle", onClick: () => onActionButtonClick === null || onActionButtonClick === void 0 ? void 0 : onActionButtonClick(rowData), children: Icon ? _jsx(Icon, { size: 14 }) : _jsx(Maximize2Icon, { size: 14 }) }) }) })), columnState.map((column, index) => {
17
18
  if (column.visible === false)
18
19
  return null;
19
20
  if (loading) {
@@ -40,6 +40,7 @@ export type SelectionState = {
40
40
  selectedRowKeys: string[];
41
41
  excludedRowKeys: string[];
42
42
  selectionStatus: SelectionStatus;
43
+ totalSelected: number;
43
44
  };
44
45
  export type SortState = {
45
46
  dataField: string;
@@ -125,6 +126,7 @@ export type TableContextType = {
125
126
  manualSearch?: boolean;
126
127
  manualExport?: boolean;
127
128
  compactState: boolean;
129
+ focusedRowId?: string | number;
128
130
  toggleCompact: () => void;
129
131
  toggleColumnVisibility: (dataField: string) => void;
130
132
  runSearch: (query: string) => void;
@@ -133,6 +135,7 @@ export type TableContextType = {
133
135
  selectAllRows: () => void;
134
136
  clearSelections: () => void;
135
137
  isRowSelected: (row: any) => boolean;
138
+ isRowFocused: (row: any) => boolean;
136
139
  onSelectionChange?: onSelectionChangeFn;
137
140
  selectRow: (row: any) => void;
138
141
  deselectRow: (row: any) => void;
@@ -179,6 +182,7 @@ export interface TableProviderProps {
179
182
  manualExport?: boolean;
180
183
  enableSorting?: boolean;
181
184
  tableMenuOptions?: TableMenuOptions;
185
+ focusedRowId?: string | number;
182
186
  onSelectionChange?: onSelectionChangeFn;
183
187
  onActionButtonClick?: (rowData: any) => void;
184
188
  onColumnResize?: (e: OnColumnChangeProps) => void;
@@ -285,6 +289,7 @@ export interface TableProps {
285
289
  manualFiltering?: boolean;
286
290
  manualExport?: boolean;
287
291
  tableMenuOptions?: TableMenuOptions;
292
+ focusedRowId?: string | number;
288
293
  children?: React.ReactNode;
289
294
  onRowUpdated?: () => void;
290
295
  onSelectionChange?: onSelectionChangeFn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.3.24",
3
+ "version": "1.3.26",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",