@gpa-gemstone/react-table 1.2.70 → 1.2.71
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.
|
@@ -36,26 +36,29 @@ const ConfigurableColumn_1 = require("./ConfigurableColumn");
|
|
|
36
36
|
*/
|
|
37
37
|
function ConfigurableTable(props) {
|
|
38
38
|
const getKeyMappings = () => {
|
|
39
|
-
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
const updated = new Map();
|
|
41
|
+
const localKeys = (_c = (_b = localStorage.getItem((_a = props.LocalStorageKey) !== null && _a !== void 0 ? _a : '')) === null || _b === void 0 ? void 0 : _b.split(',')) !== null && _c !== void 0 ? _c : [];
|
|
40
42
|
React.Children.forEach(props.children, (element) => {
|
|
41
43
|
var _a, _b;
|
|
42
44
|
if (!React.isValidElement(element))
|
|
43
45
|
return;
|
|
44
46
|
if (element.type === ConfigurableColumn_1.default) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const key = element.props.Key;
|
|
48
|
+
const baseCol = {
|
|
49
|
+
Key: key,
|
|
50
|
+
Label: (_a = element.props.Label) !== null && _a !== void 0 ? _a : key,
|
|
51
|
+
Default: (_b = element.props.Default) !== null && _b !== void 0 ? _b : false,
|
|
48
52
|
Enabled: false,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
u.set(c.Key, c);
|
|
53
|
+
}; // use local if it has anything
|
|
54
|
+
baseCol.Enabled = localKeys.length > 0 ? localKeys.includes(key) : isEnabled(baseCol);
|
|
55
|
+
updated.set(key, baseCol);
|
|
53
56
|
}
|
|
54
57
|
});
|
|
55
|
-
return
|
|
58
|
+
return updated;
|
|
56
59
|
};
|
|
57
60
|
const [showSettings, setShowSettings] = React.useState(false);
|
|
58
|
-
const [columns, setColumns] = React.useState(getKeyMappings());
|
|
61
|
+
const [columns, setColumns] = React.useState(() => getKeyMappings());
|
|
59
62
|
const [hover, setHover] = React.useState(false);
|
|
60
63
|
const [guid] = React.useState((0, helper_functions_1.CreateGuid)());
|
|
61
64
|
const [widthDisabledAdd, setWidthDisabledAdd] = React.useState(false);
|
|
@@ -68,7 +71,7 @@ function ConfigurableTable(props) {
|
|
|
68
71
|
}
|
|
69
72
|
}, []);
|
|
70
73
|
React.useEffect(() => {
|
|
71
|
-
setColumns(getKeyMappings());
|
|
74
|
+
setColumns(() => getKeyMappings());
|
|
72
75
|
}, [props.children]);
|
|
73
76
|
React.useEffect(() => {
|
|
74
77
|
if (props.OnSettingsChange !== undefined)
|
|
@@ -81,12 +84,12 @@ function ConfigurableTable(props) {
|
|
|
81
84
|
if (props.LocalStorageKey === undefined)
|
|
82
85
|
return;
|
|
83
86
|
const currentState = localStorage.getItem(props.LocalStorageKey);
|
|
87
|
+
const allKeys = Array.from(columns.keys());
|
|
84
88
|
let currentKeys = [];
|
|
85
89
|
if (currentState !== null)
|
|
86
90
|
currentKeys = currentState.split(',');
|
|
87
|
-
const allKeys = Array.from(columns.keys());
|
|
88
91
|
currentKeys = currentKeys.filter((k) => !allKeys.includes(k));
|
|
89
|
-
const enabled =
|
|
92
|
+
const enabled = allKeys.filter((k) => { var _a; return (_a = columns.get(k)) === null || _a === void 0 ? void 0 : _a.Enabled; });
|
|
90
93
|
currentKeys.push(...enabled);
|
|
91
94
|
localStorage.setItem(props.LocalStorageKey, currentKeys.join(','));
|
|
92
95
|
}
|
|
@@ -113,15 +116,17 @@ function ConfigurableTable(props) {
|
|
|
113
116
|
return activeKeys.includes(key !== null && key !== void 0 ? key : '');
|
|
114
117
|
}
|
|
115
118
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
|
|
120
|
-
function isEnabled(c,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
119
|
+
* Returns true if a column is enabled by default, required as sortKey, or was saved in the users preferences
|
|
120
|
+
* @param c Column to check
|
|
121
|
+
* @param useLocal If true, will not consider if key is in localstorage
|
|
122
|
+
*/
|
|
123
|
+
function isEnabled(c, useLocal = true) {
|
|
124
|
+
if (c == undefined)
|
|
125
|
+
return false;
|
|
126
|
+
const isDefault = c.Default === true;
|
|
127
|
+
const isSortKey = props.SortKey === c.Key;
|
|
128
|
+
const isInLocal = useLocal && checkLocal(c.Key);
|
|
129
|
+
return isSortKey || isInLocal || isDefault;
|
|
125
130
|
}
|
|
126
131
|
return (React.createElement(React.Fragment, null,
|
|
127
132
|
React.createElement(Table_1.Table, Object.assign({}, props, { LastColumn: React.createElement("div", { style: { marginLeft: -5, marginBottom: 12, cursor: 'pointer' }, onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), id: guid + '-tooltip', onClick: () => setShowSettings(true) },
|
|
@@ -144,7 +149,7 @@ function ConfigurableTable(props) {
|
|
|
144
149
|
var _a;
|
|
145
150
|
const ref = u.get(k);
|
|
146
151
|
if (ref != null)
|
|
147
|
-
ref.Enabled = (_a = isEnabled(u.get(k),
|
|
152
|
+
ref.Enabled = (_a = isEnabled(u.get(k), false)) !== null && _a !== void 0 ? _a : true;
|
|
148
153
|
});
|
|
149
154
|
return u;
|
|
150
155
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gpa-gemstone/react-table",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.71",
|
|
4
4
|
"description": "Table for GPA web applications",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@gpa-gemstone/gpa-symbols": "0.0.49",
|
|
47
47
|
"@gpa-gemstone/helper-functions": "0.0.40",
|
|
48
|
-
"@gpa-gemstone/react-interactive": "1.0.
|
|
48
|
+
"@gpa-gemstone/react-interactive": "1.0.149",
|
|
49
49
|
"@types/lodash": "^4.14.171",
|
|
50
50
|
"@types/react": "^17.0.14",
|
|
51
51
|
"lodash": "^4.17.21",
|