@gpa-gemstone/react-table 1.2.73 → 1.2.74

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.
@@ -39,6 +39,8 @@ function ConfigurableTable(props) {
39
39
  var _a, _b, _c;
40
40
  const updated = new Map();
41
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 : [];
42
+ if (localKeys[0] == '')
43
+ localKeys.pop(); // if localstorage is empty, set the array to an empty array. [''] by default
42
44
  React.Children.forEach(props.children, (element) => {
43
45
  var _a, _b;
44
46
  if (!React.isValidElement(element))
@@ -91,7 +93,7 @@ function ConfigurableTable(props) {
91
93
  currentKeys = currentKeys.filter((k) => !allKeys.includes(k));
92
94
  const enabled = allKeys.filter((k) => { var _a; return (_a = columns.get(k)) === null || _a === void 0 ? void 0 : _a.Enabled; });
93
95
  currentKeys.push(...enabled);
94
- (currentKeys.length == 0 && currentState == null) ? null : localStorage.setItem(props.LocalStorageKey, currentKeys.join(','));
96
+ localStorage.setItem(props.LocalStorageKey, currentKeys.join(','));
95
97
  }
96
98
  function changeColumns(key) {
97
99
  setColumns((d) => {
@@ -177,18 +179,26 @@ function ConfigurableTable(props) {
177
179
  } }, "Reset Defaults"))))) : null));
178
180
  }
179
181
  function ColumnSelection(props) {
180
- const [showAlert, setShowAlert] = React.useState(true);
182
+ const enabledCols = props.columns.filter((column) => column.Enabled);
183
+ const isOnlyOneEnabled = enabledCols.length === 1;
184
+ const helpMessage = (col) => {
185
+ if (col.Key === props.sortKey)
186
+ return 'The Table is currently sorted by this column, so it cannot be hidden.';
187
+ if (isOnlyOneEnabled && col.Enabled)
188
+ return 'The Table must have one column visible at all times, so it cannot be hidden.';
189
+ return undefined;
190
+ };
181
191
  return (React.createElement(React.Fragment, null,
182
192
  React.createElement("div", { className: "row" },
183
- React.createElement("div", { className: "col-4" }, props.columns.map((c, i) => i % 3 == 0 ? (React.createElement(react_forms_1.CheckBox, { Label: c.Label, Field: 'Enabled', Record: c, Setter: () => props.onChange(c.Key), key: c.Key, Disabled: c.Key == props.sortKey || (props.disableAdd && !c.Enabled), Help: c.Key == props.sortKey
184
- ? 'The Table is currently sorted by this column so it cannot be hidden.'
185
- : undefined })) : null)),
186
- React.createElement("div", { className: "col-4" }, props.columns.map((c, i) => i % 3 == 1 ? (React.createElement(react_forms_1.CheckBox, { Label: c.Label, Field: 'Enabled', Record: c, Setter: () => props.onChange(c.Key), key: c.Key, Disabled: c.Key == props.sortKey || (props.disableAdd && !c.Enabled), Help: c.Key == props.sortKey
187
- ? 'The Table is currently sorted by this column so it cannot be hidden.'
188
- : undefined })) : null)),
189
- React.createElement("div", { className: "col-4" }, props.columns.map((c, i) => i % 3 == 2 ? (React.createElement(react_forms_1.CheckBox, { Label: c.Label, Field: 'Enabled', Record: c, Setter: () => props.onChange(c.Key), key: c.Key, Disabled: c.Key == props.sortKey || (props.disableAdd && !c.Enabled), Help: c.Key == props.sortKey
190
- ? 'The Table is currently sorted by this column so it cannot be hidden.'
191
- : undefined })) : null))),
193
+ React.createElement("div", { className: "col-4" }, props.columns.map((c, i) => i % 3 == 0 ? (React.createElement(react_forms_1.CheckBox, { Label: c.Label, Field: 'Enabled', Record: c, Setter: () => props.onChange(c.Key), key: c.Key, Disabled: c.Key === props.sortKey ||
194
+ (props.disableAdd && !c.Enabled) ||
195
+ (isOnlyOneEnabled && c.Enabled), Help: helpMessage(c) })) : null)),
196
+ React.createElement("div", { className: "col-4" }, props.columns.map((c, i) => i % 3 == 1 ? (React.createElement(react_forms_1.CheckBox, { Label: c.Label, Field: 'Enabled', Record: c, Setter: () => props.onChange(c.Key), key: c.Key, Disabled: c.Key === props.sortKey ||
197
+ (props.disableAdd && !c.Enabled) ||
198
+ (isOnlyOneEnabled && c.Enabled), Help: helpMessage(c) })) : null)),
199
+ React.createElement("div", { className: "col-4" }, props.columns.map((c, i) => i % 3 == 2 ? (React.createElement(react_forms_1.CheckBox, { Label: c.Label, Field: 'Enabled', Record: c, Setter: () => props.onChange(c.Key), key: c.Key, Disabled: c.Key === props.sortKey ||
200
+ (props.disableAdd && !c.Enabled) ||
201
+ (isOnlyOneEnabled && c.Enabled), Help: helpMessage(c) })) : null))),
192
202
  props.disableAdd ?
193
203
  React.createElement(react_interactive_1.Alert, { Class: 'alert-primary', Style: { marginBottom: 0, marginTop: '0.5em' } }, "Additional columns disabled due to table size.")
194
204
  : null));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-table",
3
- "version": "1.2.73",
3
+ "version": "1.2.74",
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.51",
47
- "@gpa-gemstone/helper-functions": "0.0.41",
48
- "@gpa-gemstone/react-interactive": "1.0.151",
46
+ "@gpa-gemstone/gpa-symbols": "0.0.52",
47
+ "@gpa-gemstone/helper-functions": "0.0.42",
48
+ "@gpa-gemstone/react-interactive": "1.0.152",
49
49
  "@types/lodash": "^4.14.171",
50
50
  "@types/react": "^17.0.14",
51
51
  "lodash": "^4.17.21",