@monolith-forensics/monolith-ui 1.3.22 → 1.3.24

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.
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { createContext, useEffect, useMemo, useState } from "react";
13
+ import { createContext, useMemo, useState } from "react";
14
14
  import StateStorage from "./StateStorage";
15
15
  import { resolveColumnResize, syncColumnState } from "./Utils";
16
16
  import TableDefaults from "./TableDefaults";
@@ -54,6 +54,16 @@ const TableProvider = (_a) => {
54
54
  const getColumnState = (dataField) => {
55
55
  return columnState.find((col) => col.dataField === dataField);
56
56
  };
57
+ const updateColumnState = (columnState) => {
58
+ var _a;
59
+ setColumnState(columnState);
60
+ (_a = props.onColumnStateChange) === null || _a === void 0 ? void 0 : _a.call(props, columnState);
61
+ if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
62
+ if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
63
+ StateStorage.setColumnState(stateStorage.key, columnState);
64
+ }
65
+ }
66
+ };
57
67
  const handleColumnReorder = (dragColumn, dropColumn) => {
58
68
  var _a, _b, _c;
59
69
  if (!dragColumn || !dropColumn)
@@ -77,47 +87,73 @@ const TableProvider = (_a) => {
77
87
  return col;
78
88
  })
79
89
  .sort((a, b) => a.orderValue - b.orderValue);
80
- setColumnState(newColumnState);
90
+ updateColumnState(newColumnState);
81
91
  (_c = props.onColumnReorder) === null || _c === void 0 ? void 0 : _c.call(props, {
82
92
  columnState: newColumnState,
83
93
  column: dragColumn,
84
94
  });
85
95
  };
86
96
  const handleColumnHeaderClick = (column) => {
87
- var _a;
97
+ var _a, _b;
88
98
  if (props.enableSorting === true || column.enableSorting === true) {
89
- setSortState((prevSortState) => {
90
- var _a;
91
- let newSortState = {
92
- dataField: column.dataField,
93
- dir: "asc",
94
- };
95
- if ((prevSortState === null || prevSortState === void 0 ? void 0 : prevSortState.dataField) === column.dataField) {
96
- if (prevSortState.dir === "desc") {
97
- newSortState = null;
98
- }
99
- else {
100
- if (newSortState) {
101
- newSortState.dir = prevSortState.dir === "asc" ? "desc" : "asc";
102
- }
99
+ let newSortState = {
100
+ dataField: column.dataField,
101
+ dir: "asc",
102
+ };
103
+ if ((sortState === null || sortState === void 0 ? void 0 : sortState.dataField) === column.dataField) {
104
+ if (sortState.dir === "desc") {
105
+ newSortState = null;
106
+ }
107
+ else {
108
+ if (newSortState) {
109
+ newSortState.dir = sortState.dir === "asc" ? "desc" : "asc";
103
110
  }
104
111
  }
105
- (_a = props.onColumnHeaderClick) === null || _a === void 0 ? void 0 : _a.call(props, { column, sort: newSortState });
106
- return newSortState;
107
- });
112
+ }
113
+ (_a = props.onColumnHeaderClick) === null || _a === void 0 ? void 0 : _a.call(props, { column, sort: newSortState });
114
+ updateSortState(newSortState);
108
115
  }
109
116
  else {
110
- (_a = props.onColumnHeaderClick) === null || _a === void 0 ? void 0 : _a.call(props, { column, sort: null });
117
+ (_b = props.onColumnHeaderClick) === null || _b === void 0 ? void 0 : _b.call(props, { column, sort: null });
118
+ updateSortState(null);
111
119
  }
112
120
  };
113
121
  const handleFilterChange = (query) => {
114
122
  setFilterState(query);
123
+ if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
124
+ if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
125
+ StateStorage.setFilterState(stateStorage.key, filterState);
126
+ }
127
+ }
128
+ };
129
+ const updateSearchState = (searchState) => {
130
+ var _a, _b, _c;
131
+ setSearch(searchState);
132
+ (_c = (_b = (_a = props.tableMenuOptions) === null || _a === void 0 ? void 0 : _a.searchOptions) === null || _b === void 0 ? void 0 : _b.onSearch) === null || _c === void 0 ? void 0 : _c.call(_b, searchState);
133
+ if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
134
+ if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
135
+ StateStorage.setSearchState(stateStorage.key, searchState);
136
+ }
137
+ }
115
138
  };
116
139
  const runSearch = (searchText) => {
117
- setSearch(searchText);
140
+ updateSearchState(searchText);
118
141
  };
119
142
  const clearSearch = () => {
120
- setSearch("");
143
+ updateSearchState("");
144
+ };
145
+ const updateSortState = (sortState) => {
146
+ var _a, _b;
147
+ setSortState(sortState);
148
+ (_a = props.onSort) === null || _a === void 0 ? void 0 : _a.call(props, {
149
+ column: (_b = columnState.find((col) => col.dataField === (sortState === null || sortState === void 0 ? void 0 : sortState.dataField))) !== null && _b !== void 0 ? _b : {},
150
+ sort: sortState,
151
+ });
152
+ if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
153
+ if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
154
+ StateStorage.setSortState(stateStorage.key, sortState);
155
+ }
156
+ }
121
157
  };
122
158
  const sortData = (sortState) => {
123
159
  // sort data
@@ -316,14 +352,13 @@ const TableProvider = (_a) => {
316
352
  return processedData;
317
353
  };
318
354
  const toggleColumnVisibility = (dataField) => {
319
- setColumnState((prevColumnState) => {
320
- return prevColumnState.map((col) => {
321
- if (col.dataField === dataField) {
322
- return Object.assign(Object.assign({}, col), { visible: !col.visible });
323
- }
324
- return col;
325
- });
355
+ const newColumnState = columnState.map((col) => {
356
+ if (col.dataField === dataField) {
357
+ return Object.assign(Object.assign({}, col), { visible: !col.visible });
358
+ }
359
+ return col;
326
360
  });
361
+ updateColumnState(newColumnState);
327
362
  };
328
363
  const toggleCompact = () => {
329
364
  setCompactState((prev) => !prev);
@@ -464,60 +499,24 @@ const TableProvider = (_a) => {
464
499
  return 0;
465
500
  }
466
501
  };
467
- useEffect(() => {
468
- var _a;
469
- (_a = props.onColumnStateChange) === null || _a === void 0 ? void 0 : _a.call(props, columnState);
470
- if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
471
- if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
472
- StateStorage.setColumnState(stateStorage.key, columnState);
473
- }
474
- }
475
- if (tableInstanceRef) {
476
- tableInstanceRef.current = {
477
- columnState,
478
- setColumnState,
479
- getColumnState,
480
- toggleColumnVisibility,
481
- getColumnVisibility,
482
- getSelectedRows,
483
- getSelectedRowKeys,
484
- selectRow,
485
- deselectRow,
486
- selectAllRows,
487
- clearSelections,
488
- runSearch,
489
- clearSearch,
490
- };
491
- }
492
- }, [columnState]);
493
- useEffect(() => {
494
- var _a, _b;
495
- if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
496
- if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
497
- StateStorage.setSortState(stateStorage.key, sortState);
498
- }
499
- }
500
- (_a = props.onSort) === null || _a === void 0 ? void 0 : _a.call(props, {
501
- column: (_b = columnState.find((col) => col.dataField === (sortState === null || sortState === void 0 ? void 0 : sortState.dataField))) !== null && _b !== void 0 ? _b : {},
502
- sort: sortState,
503
- });
504
- }, [sortState]);
505
- useEffect(() => {
506
- var _a, _b, _c;
507
- if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
508
- if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
509
- StateStorage.setSearchState(stateStorage.key, search);
510
- }
511
- }
512
- (_c = (_b = (_a = props.tableMenuOptions) === null || _a === void 0 ? void 0 : _a.searchOptions) === null || _b === void 0 ? void 0 : _b.onSearch) === null || _c === void 0 ? void 0 : _c.call(_b, search);
513
- }, [search]);
514
- useEffect(() => {
515
- if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
516
- if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
517
- StateStorage.setFilterState(stateStorage.key, filterState);
518
- }
519
- }
520
- }, [filterState]);
502
+ if (tableInstanceRef) {
503
+ tableInstanceRef.current = {
504
+ columnState,
505
+ setColumnState: updateColumnState,
506
+ getColumnState,
507
+ toggleColumnVisibility,
508
+ getColumnVisibility,
509
+ getSelectedRows,
510
+ getSelectedRowKeys,
511
+ getSelectionTotal: getCalculatedSelectionTotal,
512
+ selectRow,
513
+ deselectRow,
514
+ selectAllRows,
515
+ clearSelections,
516
+ runSearch,
517
+ clearSearch,
518
+ };
519
+ }
521
520
  const _data = useMemo(() => {
522
521
  let processedData = props.data;
523
522
  if (props.manualSorting !== true) {
@@ -91,12 +91,12 @@ export type TableDimensions = {
91
91
  };
92
92
  export type TableContextType = {
93
93
  columnState: ColumnState[];
94
+ setColumnState: React.Dispatch<React.SetStateAction<ColumnState[]>>;
94
95
  sortState?: SortState | null;
95
96
  filterState?: Query | null;
96
97
  searchState?: string | null;
97
98
  data: any[];
98
99
  totalRecords?: number;
99
- setColumnState: React.Dispatch<React.SetStateAction<ColumnState[]>>;
100
100
  keyField?: string;
101
101
  tableHeight?: number;
102
102
  tableMaxHeight?: number;
@@ -307,7 +307,7 @@ export interface TableProps {
307
307
  }
308
308
  export type TableInstance = {
309
309
  columnState: ColumnState[];
310
- setColumnState: React.Dispatch<React.SetStateAction<ColumnState[]>>;
310
+ setColumnState: (e: ColumnState[]) => void;
311
311
  getColumnState: (dataField: string) => ColumnState | undefined;
312
312
  onColumnResize?: (e: OnColumnChangeProps) => void;
313
313
  onColumnReorder?: (e: OnColumnChangeProps) => void;
@@ -316,6 +316,7 @@ export type TableInstance = {
316
316
  getColumnVisibility: (dataField: string) => boolean;
317
317
  getSelectedRows: () => any[];
318
318
  getSelectedRowKeys: () => string[];
319
+ getSelectionTotal: () => number;
319
320
  selectRow: (row: any) => void;
320
321
  deselectRow: (row: any) => void;
321
322
  selectAllRows: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.3.22",
3
+ "version": "1.3.24",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",