@gpa-gemstone/react-table 1.2.69 → 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);
|
|
@@ -67,6 +70,9 @@ function ConfigurableTable(props) {
|
|
|
67
70
|
setWidthDisabledAdd(false);
|
|
68
71
|
}
|
|
69
72
|
}, []);
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
setColumns(() => getKeyMappings());
|
|
75
|
+
}, [props.children]);
|
|
70
76
|
React.useEffect(() => {
|
|
71
77
|
if (props.OnSettingsChange !== undefined)
|
|
72
78
|
props.OnSettingsChange(showSettings);
|
|
@@ -74,20 +80,16 @@ function ConfigurableTable(props) {
|
|
|
74
80
|
React.useEffect(() => {
|
|
75
81
|
saveLocal();
|
|
76
82
|
}, [columns]);
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @returns
|
|
80
|
-
*/
|
|
81
83
|
function saveLocal() {
|
|
82
84
|
if (props.LocalStorageKey === undefined)
|
|
83
85
|
return;
|
|
84
86
|
const currentState = localStorage.getItem(props.LocalStorageKey);
|
|
87
|
+
const allKeys = Array.from(columns.keys());
|
|
85
88
|
let currentKeys = [];
|
|
86
89
|
if (currentState !== null)
|
|
87
90
|
currentKeys = currentState.split(',');
|
|
88
|
-
const allKeys = Array.from(columns.keys());
|
|
89
91
|
currentKeys = currentKeys.filter((k) => !allKeys.includes(k));
|
|
90
|
-
const enabled =
|
|
92
|
+
const enabled = allKeys.filter((k) => { var _a; return (_a = columns.get(k)) === null || _a === void 0 ? void 0 : _a.Enabled; });
|
|
91
93
|
currentKeys.push(...enabled);
|
|
92
94
|
localStorage.setItem(props.LocalStorageKey, currentKeys.join(','));
|
|
93
95
|
}
|
|
@@ -114,15 +116,17 @@ function ConfigurableTable(props) {
|
|
|
114
116
|
return activeKeys.includes(key !== null && key !== void 0 ? key : '');
|
|
115
117
|
}
|
|
116
118
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
|
|
121
|
-
function isEnabled(c,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
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;
|
|
126
130
|
}
|
|
127
131
|
return (React.createElement(React.Fragment, null,
|
|
128
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) },
|
|
@@ -145,7 +149,7 @@ function ConfigurableTable(props) {
|
|
|
145
149
|
var _a;
|
|
146
150
|
const ref = u.get(k);
|
|
147
151
|
if (ref != null)
|
|
148
|
-
ref.Enabled = (_a = isEnabled(u.get(k),
|
|
152
|
+
ref.Enabled = (_a = isEnabled(u.get(k), false)) !== null && _a !== void 0 ? _a : true;
|
|
149
153
|
});
|
|
150
154
|
return u;
|
|
151
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",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@gpa-gemstone/gpa-symbols": "0.0.49",
|
|
47
|
-
"@gpa-gemstone/helper-functions": "0.0.
|
|
48
|
-
"@gpa-gemstone/react-interactive": "1.0.
|
|
47
|
+
"@gpa-gemstone/helper-functions": "0.0.40",
|
|
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",
|