@gpa-gemstone/react-table 1.2.70 → 1.2.72

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
- const u = new Map();
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 c = {
46
- Default: (_a = element.props.Default) !== null && _a !== void 0 ? _a : false,
47
- Label: (_b = element.props.Label) !== null && _b !== void 0 ? _b : element.props.Key,
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
- Key: element.props.Key,
50
- };
51
- c.Enabled = isEnabled(c);
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 u;
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 = Array.from(columns.keys()).filter((k) => { var _a; return (_a = columns.get(k)) === null || _a === void 0 ? void 0 : _a.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
- * * Determines if a column is enabled by default, required, or was saved in the users preferences
117
- * * @param c Column to check
118
- * * @param skipLocal If true, will return whether it is enabled as part of the default settings
119
- * */
120
- function isEnabled(c, skipLocal = false) {
121
- var _a;
122
- const isSort = props.SortKey === (c === null || c === void 0 ? void 0 : c.Key);
123
- const isLocal = checkLocal(c === null || c === void 0 ? void 0 : c.Key) && !skipLocal;
124
- return ((_a = c === null || c === void 0 ? void 0 : c.Default) !== null && _a !== void 0 ? _a : false) || isSort || isLocal;
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), true)) !== null && _a !== void 0 ? _a : true;
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.70",
3
+ "version": "1.2.72",
4
4
  "description": "Table for GPA web applications",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -43,9 +43,9 @@
43
43
  "typescript": "5.5.3"
44
44
  },
45
45
  "dependencies": {
46
- "@gpa-gemstone/gpa-symbols": "0.0.49",
46
+ "@gpa-gemstone/gpa-symbols": "0.0.50",
47
47
  "@gpa-gemstone/helper-functions": "0.0.40",
48
- "@gpa-gemstone/react-interactive": "1.0.148",
48
+ "@gpa-gemstone/react-interactive": "1.0.150",
49
49
  "@types/lodash": "^4.14.171",
50
50
  "@types/react": "^17.0.14",
51
51
  "lodash": "^4.17.21",