@gpa-gemstone/react-table 1.2.58 → 1.2.60

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.
Files changed (32) hide show
  1. package/lib/ConfigurableTable/ConfigurableTable.d.ts +4 -0
  2. package/lib/ConfigurableTable/ConfigurableTable.js +3 -0
  3. package/lib/Table/Table.js +35 -10
  4. package/package.json +56 -56
  5. package/lib/AdjustableTable/Column.d.ts +0 -20
  6. package/lib/AdjustableTable/Column.js +0 -77
  7. package/lib/AdjustableTable/Table.d.ts +0 -3
  8. package/lib/AdjustableTable/Table.js +0 -470
  9. package/lib/AdjustableTable/Types.d.ts +0 -148
  10. package/lib/AdjustableTable/Types.js +0 -24
  11. package/lib/DynamicTable.d.ts +0 -37
  12. package/lib/DynamicTable.js +0 -44
  13. package/lib/FilterableTable/BooleanFilter.d.ts +0 -26
  14. package/lib/FilterableTable/BooleanFilter.js +0 -68
  15. package/lib/FilterableTable/DateTimeFilters.d.ts +0 -10
  16. package/lib/FilterableTable/DateTimeFilters.js +0 -321
  17. package/lib/FilterableTable/EnumFilter.d.ts +0 -37
  18. package/lib/FilterableTable/EnumFilter.js +0 -89
  19. package/lib/FilterableTable/FilterableColumn.d.ts +0 -20
  20. package/lib/FilterableTable/FilterableColumn.js +0 -34
  21. package/lib/FilterableTable/FilterableTable.d.ts +0 -12
  22. package/lib/FilterableTable/FilterableTable.js +0 -95
  23. package/lib/FilterableTable/NumberFilter.d.ts +0 -19
  24. package/lib/FilterableTable/NumberFilter.js +0 -160
  25. package/lib/FilterableTable/TextFilter.d.ts +0 -14
  26. package/lib/FilterableTable/TextFilter.js +0 -78
  27. package/lib/SearchableTable.d.ts +0 -15
  28. package/lib/SearchableTable.js +0 -40
  29. package/lib/SelectTable.d.ts +0 -19
  30. package/lib/SelectTable.js +0 -102
  31. package/lib/Table.d.ts +0 -99
  32. package/lib/Table.js +0 -94
@@ -17,6 +17,10 @@ interface ITableProps<T> extends ReactTableProps.ITable<T> {
17
17
  * The key used to store columns in local storage
18
18
  */
19
19
  LocalStorageKey?: string;
20
+ /**
21
+ * Optional flag to show helper alert for configuring table columns
22
+ */
23
+ ShowColumnHelper?: boolean;
20
24
  }
21
25
  /**
22
26
  * Table with modal to show and hide columns
@@ -35,6 +35,7 @@ const ConfigurableColumn_1 = require("./ConfigurableColumn");
35
35
  * Table with modal to show and hide columns
36
36
  */
37
37
  function ConfigurableTable(props) {
38
+ var _a;
38
39
  const getKeyMappings = () => {
39
40
  const u = new Map();
40
41
  React.Children.forEach(props.children, (element) => {
@@ -59,6 +60,7 @@ function ConfigurableTable(props) {
59
60
  const [hover, setHover] = React.useState(false);
60
61
  const [guid] = React.useState((0, helper_functions_1.CreateGuid)());
61
62
  const [widthDisabledAdd, setWidthDisabledAdd] = React.useState(false);
63
+ const [showHelperAlert, setShowHelperAlert] = React.useState(true);
62
64
  const handleReduceWidthCallback = React.useCallback((hiddenKeys) => {
63
65
  if (hiddenKeys.length !== 0) {
64
66
  setWidthDisabledAdd(true);
@@ -125,6 +127,7 @@ function ConfigurableTable(props) {
125
127
  return ((_a = c === null || c === void 0 ? void 0 : c.Default) !== null && _a !== void 0 ? _a : false) || isSort || isLocal;
126
128
  }
127
129
  return (React.createElement(React.Fragment, null,
130
+ ((_a = props.ShowColumnHelper) !== null && _a !== void 0 ? _a : false) ? React.createElement(react_interactive_1.Alert, { AlertColor: "alert-info", Show: showHelperAlert, SetShow: setShowHelperAlert }, "Use the gear at the far right of the header row to choose columns to show or hide.") : null,
128
131
  React.createElement(Table_1.Table, Object.assign({}, props, { LastColumn: React.createElement("div", { style: { marginLeft: -5, marginBottom: 12 }, onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), id: guid + '-tooltip', onClick: () => setShowSettings(true) },
129
132
  React.createElement(gpa_symbols_1.ReactIcons.Settings, null)), ReduceWidthCallback: handleReduceWidthCallback }), React.Children.map(props.children, (element) => {
130
133
  var _a, _b;
@@ -76,6 +76,8 @@ const IsColumnAdjustable = (props) => {
76
76
  return propValue;
77
77
  return false;
78
78
  };
79
+ const scrollBarWidth = getScrollbarWidth();
80
+ const lastColumnWidth = 17;
79
81
  function Table(props) {
80
82
  const bodyRef = React.useRef(null);
81
83
  const colWidthsRef = React.useRef(new Map());
@@ -119,7 +121,7 @@ function Table(props) {
119
121
  if (React.isValidElement(element) && IsColumnProps(element.props)) {
120
122
  if (newMap.get(element.props.Key) != null)
121
123
  console.error("Multiple of the same key detected in table, this will cause issues.");
122
- newMap.set(element.props.Key, { minWidth: 100, maxWidth: 1000, width: 100 });
124
+ newMap.set(element.props.Key, { minWidth: 10, maxWidth: 1000, width: 100 });
123
125
  }
124
126
  });
125
127
  // If width is the same and keys are identical, we can skip the operation
@@ -162,11 +164,12 @@ function Table(props) {
162
164
  let autoSpace = currentTableWidth;
163
165
  measureKeys.forEach(key => {
164
166
  const element = document.getElementById(key + "_measurement");
165
- if (element != null) {
167
+ const elementWidth = element === null || element === void 0 ? void 0 : element.getBoundingClientRect().width;
168
+ if (elementWidth != null) {
166
169
  const widthObj = newMap.get(key);
167
170
  if (widthObj != null) {
168
- autoSpace -= element.clientWidth;
169
- widthObj[type] = element.clientWidth;
171
+ autoSpace -= elementWidth;
172
+ widthObj[type] = elementWidth;
170
173
  }
171
174
  else
172
175
  console.error("Could not find width object for Key: " + key);
@@ -177,7 +180,7 @@ function Table(props) {
177
180
  document.body.removeChild(widthsContainer);
178
181
  // Handle Autos (width type only)
179
182
  if (type === 'width' && autoKeys.length > 0) {
180
- const spacePerElement = Math.floor(autoSpace / autoKeys.length);
183
+ const spacePerElement = autoSpace / autoKeys.length;
181
184
  autoKeys.forEach(key => {
182
185
  const widthObj = newMap.get(key);
183
186
  if (widthObj != null)
@@ -223,12 +226,17 @@ function Table(props) {
223
226
  return;
224
227
  // Note: certain body classes may break this check if they set overflow to scroll
225
228
  let newScroll = false;
226
- if (((_a = props.TbodyStyle) === null || _a === void 0 ? void 0 : _a.overflowY) === 'scroll' || ((_b = props.TbodyStyle) === null || _b === void 0 ? void 0 : _b.overflow) === 'scroll')
229
+ const dims = (_a = bodyRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(); //use getBoundClientRect() to get un rounded values
230
+ if (((_b = props.TbodyStyle) === null || _b === void 0 ? void 0 : _b.overflowY) === 'scroll' || ((_c = props.TbodyStyle) === null || _c === void 0 ? void 0 : _c.overflow) === 'scroll')
227
231
  newScroll = true;
228
232
  else
229
- newScroll = bodyRef.current.clientHeight < bodyRef.current.scrollHeight;
233
+ newScroll = (dims === null || dims === void 0 ? void 0 : dims.height) < bodyRef.current.scrollHeight;
230
234
  setScrolled(newScroll);
231
- setCurrentTableWidth(((_d = (_c = bodyRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : 17) - (newScroll ? 0 : 17));
235
+ // Pick whichever is larger so we dont double subtract
236
+ const scrollbar = newScroll ? scrollBarWidth : 0;
237
+ const last = props.LastColumn !== undefined ? lastColumnWidth : 0;
238
+ const spacer = Math.max(scrollbar, last);
239
+ setCurrentTableWidth(((_d = dims.width) !== null && _d !== void 0 ? _d : 17) - spacer);
232
240
  }, 100), []);
233
241
  React.useEffect(() => {
234
242
  let resizeObserver;
@@ -258,7 +266,7 @@ function Table(props) {
258
266
  React.createElement("tr", { style: props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {} }, props.LastRow))) : null));
259
267
  }
260
268
  function Rows(props) {
261
- const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, props.BodyStyle), { paddingRight: (props.BodyScrolled ? 0 : 17), display: "block" })), [props.BodyStyle, props.BodyScrolled]);
269
+ const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, props.BodyStyle), { display: "block" })), [props.BodyStyle]);
262
270
  const onClick = React.useCallback((e, item, index) => {
263
271
  if (props.OnClick !== undefined)
264
272
  props.OnClick({
@@ -494,5 +502,22 @@ function Header(props) {
494
502
  ((_r = element.props.children) !== null && _r !== void 0 ? _r : element.props.Key),
495
503
  ' '));
496
504
  }),
497
- React.createElement("th", { style: { width: 17, padding: 0, maxWidth: 17 } }, props.LastColumn))));
505
+ props.LastColumn !== undefined ?
506
+ React.createElement("th", { style: { width: lastColumnWidth, padding: 0, maxWidth: lastColumnWidth } }, props.LastColumn)
507
+ : null)));
508
+ }
509
+ function getScrollbarWidth() {
510
+ // Creating invisible container
511
+ const outer = document.createElement('div');
512
+ outer.style.visibility = 'hidden';
513
+ outer.style.overflow = 'scroll'; // forcing scrollbar to appear
514
+ document.body.appendChild(outer);
515
+ // Creating inner element and placing it in the container
516
+ const inner = document.createElement('div');
517
+ outer.appendChild(inner);
518
+ // Calculating difference between container's full width and the child width
519
+ const scrollbarWidth = (outer.offsetWidth - inner.offsetWidth);
520
+ // Removing temporary elements from the DOM
521
+ outer.parentNode.removeChild(outer);
522
+ return scrollbarWidth;
498
523
  }
package/package.json CHANGED
@@ -1,57 +1,57 @@
1
- {
2
- "name": "@gpa-gemstone/react-table",
3
- "version": "1.2.58",
4
- "description": "Table for GPA web applications",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "files": ["lib"],
8
- "scripts": {
9
- "test": "jest --config jestconfig.json",
10
- "build": "tsc",
11
- "format": "prettier --write \"src/**/*.tsx\"",
12
- "lint": "eslint . --ext .ts,.tsx",
13
- "prepare": "npm run build",
14
- "prepublishOnly": "npm test && npm run lint",
15
- "preversion": "npm run lint",
16
- "version": "npm run format && git add -A src",
17
- "postversion": "git push && git push --tags"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/GridProtectionAlliance/gpa-gemstone.git"
22
- },
23
- "keywords": [
24
- "React",
25
- "Table",
26
- "GSF",
27
- "Gemstone",
28
- "GridProtectionAlliance"
29
- ],
30
- "author": "GridProtectionAlliance",
31
- "license": "MIT",
32
- "bugs": {"url": "https://github.com/GridProtectionAlliance/gpa-gemstone/issues"},
33
- "homepage": "https://github.com/GridProtectionAlliance/gpa-gemstone#readme",
34
- "devDependencies": {
35
- "@types/jest": "^27.0.0",
36
- "@typescript-eslint/eslint-plugin": "^5.60.0",
37
- "@typescript-eslint/parser": "^5.60.0",
38
- "@types/react-portal": "4.0.4",
39
- "eslint": "^8.43.0",
40
- "jest": "^29.0.0",
41
- "prettier": "^2.3.2",
42
- "ts-jest": "^29.0.0",
43
- "typescript": "5.5.3"
44
- },
45
- "dependencies": {
46
- "@gpa-gemstone/gpa-symbols": "0.0.45",
47
- "@gpa-gemstone/helper-functions": "0.0.36",
48
- "@gpa-gemstone/react-interactive": "1.0.137",
49
- "@types/lodash": "^4.14.171",
50
- "@types/react": "^17.0.14",
51
- "lodash": "^4.17.21",
52
- "react": "^18.2.0",
53
- "react-dom": "18.2.0",
54
- "react-portal": "4.2.2"
55
- },
56
- "publishConfig": {"access": "public"}
1
+ {
2
+ "name": "@gpa-gemstone/react-table",
3
+ "version": "1.2.60",
4
+ "description": "Table for GPA web applications",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": ["lib"],
8
+ "scripts": {
9
+ "test": "jest --config jestconfig.json",
10
+ "build": "tsc",
11
+ "format": "prettier --write \"src/**/*.tsx\"",
12
+ "lint": "eslint . --ext .ts,.tsx",
13
+ "prepare": "npm run build",
14
+ "prepublishOnly": "npm test && npm run lint",
15
+ "preversion": "npm run lint",
16
+ "version": "npm run format && git add -A src",
17
+ "postversion": "git push && git push --tags"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/GridProtectionAlliance/gpa-gemstone.git"
22
+ },
23
+ "keywords": [
24
+ "React",
25
+ "Table",
26
+ "GSF",
27
+ "Gemstone",
28
+ "GridProtectionAlliance"
29
+ ],
30
+ "author": "GridProtectionAlliance",
31
+ "license": "MIT",
32
+ "bugs": {"url": "https://github.com/GridProtectionAlliance/gpa-gemstone/issues"},
33
+ "homepage": "https://github.com/GridProtectionAlliance/gpa-gemstone#readme",
34
+ "devDependencies": {
35
+ "@types/jest": "^27.0.0",
36
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
37
+ "@typescript-eslint/parser": "^5.60.0",
38
+ "@types/react-portal": "4.0.4",
39
+ "eslint": "^8.43.0",
40
+ "jest": "^29.0.0",
41
+ "prettier": "^2.3.2",
42
+ "ts-jest": "^29.0.0",
43
+ "typescript": "5.5.3"
44
+ },
45
+ "dependencies": {
46
+ "@gpa-gemstone/gpa-symbols": "0.0.46",
47
+ "@gpa-gemstone/helper-functions": "0.0.37",
48
+ "@gpa-gemstone/react-interactive": "1.0.139",
49
+ "@types/lodash": "^4.14.171",
50
+ "@types/react": "^17.0.14",
51
+ "lodash": "^4.17.21",
52
+ "react": "^18.2.0",
53
+ "react-dom": "18.2.0",
54
+ "react-portal": "4.2.2"
55
+ },
56
+ "publishConfig": {"access": "public"}
57
57
  }
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import * as ReactTableProps from './Types';
3
- export declare function AdjustableColumn<T>(props: React.PropsWithChildren<ReactTableProps.IColumn<T>>): JSX.Element;
4
- export declare function Column<T>(props: React.PropsWithChildren<ReactTableProps.IColumn<T>>): JSX.Element;
5
- export interface IHeaderWrapperProps {
6
- onSort: React.MouseEventHandler<HTMLTableCellElement>;
7
- startAdjustment?: React.MouseEventHandler<HTMLDivElement>;
8
- sorted: boolean;
9
- asc: boolean;
10
- style: React.CSSProperties;
11
- allowSort?: boolean;
12
- colKey: string;
13
- }
14
- export declare function ColumnHeaderWrapper(props: React.PropsWithChildren<IHeaderWrapperProps>): JSX.Element;
15
- export interface IDataWrapperProps {
16
- dragStart?: (e: React.DragEvent) => void;
17
- onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
18
- style: React.CSSProperties;
19
- }
20
- export declare function ColumnDataWrapper(props: React.PropsWithChildren<IDataWrapperProps>): JSX.Element;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // Column.tsx - Gbtc
4
- //
5
- // Copyright © 2018, Grid Protection Alliance. All Rights Reserved.
6
- //
7
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
- // file except in compliance with the License. You may obtain a copy of the License at:
11
- //
12
- // http://opensource.org/licenses/MIT
13
- //
14
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
- // License for the specific language governing permissions and limitations.
17
- //
18
- // Code Modification History:
19
- // ----------------------------------------------------------------------------------------------------
20
- // 08/02/2018 - Billy Ernest
21
- // Generated original version of source code.
22
- // 05/31/2024 - C. Lackner
23
- // Refactored to fix sizing issues.
24
- // 12/04/2024 - G. Santos
25
- // Refactored to fix performance issues.
26
- //
27
- // ******************************************************************************************************
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.AdjustableColumn = AdjustableColumn;
30
- exports.Column = Column;
31
- exports.ColumnHeaderWrapper = ColumnHeaderWrapper;
32
- exports.ColumnDataWrapper = ColumnDataWrapper;
33
- const gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
34
- const React = require("react");
35
- function AdjustableColumn(props) {
36
- return React.createElement(React.Fragment, null, props.children);
37
- }
38
- function Column(props) {
39
- return React.createElement(React.Fragment, null, props.children);
40
- }
41
- function ColumnHeaderWrapper(props) {
42
- var _a;
43
- const [showBorder, setShowBorder] = React.useState(false);
44
- const onHover = React.useCallback(() => { setShowBorder(true); }, []);
45
- const onLeave = React.useCallback(() => { setShowBorder(false); }, []);
46
- const onClickBorder = React.useCallback((e) => {
47
- if (props.startAdjustment != null)
48
- props.startAdjustment(e);
49
- }, [props.startAdjustment]);
50
- const onClick = React.useCallback((e) => {
51
- var _a;
52
- if ((_a = props.allowSort) !== null && _a !== void 0 ? _a : true)
53
- props.onSort(e);
54
- }, [props.onSort, props.allowSort]);
55
- const preventPropagation = React.useCallback((e) => {
56
- e.stopPropagation();
57
- }, []);
58
- return React.createElement("th", { style: props.style, onClick: onClick, onDrag: (e) => { e.stopPropagation(); }, id: props.colKey },
59
- props.startAdjustment == null ? React.createElement(React.Fragment, null) :
60
- React.createElement("div", { style: {
61
- width: 5,
62
- height: '100%',
63
- position: 'absolute',
64
- top: 0,
65
- left: 0,
66
- opacity: showBorder ? 1 : 0,
67
- background: '#e9ecef',
68
- cursor: 'col-resize',
69
- }, onMouseEnter: onHover, onMouseLeave: onLeave, onMouseDown: onClickBorder, onClick: preventPropagation }),
70
- props.sorted ? React.createElement("div", { style: { position: 'absolute', width: 25 } }, props.asc ? React.createElement(gpa_symbols_1.ReactIcons.ArrowDropUp, null) : React.createElement(gpa_symbols_1.ReactIcons.ArrowDropDown, null)) : null,
71
- React.createElement("div", { style: {
72
- marginLeft: (props.sorted ? 25 : 0),
73
- } }, (_a = props.children) !== null && _a !== void 0 ? _a : props.colKey));
74
- }
75
- function ColumnDataWrapper(props) {
76
- return (React.createElement("td", { style: props.style, onClick: props.onClick, draggable: props.dragStart !== undefined, onDragStart: props.dragStart }, props.children));
77
- }
@@ -1,3 +0,0 @@
1
- import * as React from 'react';
2
- import * as ReactTableProps from './Types';
3
- export declare function AdjustableTable<T>(props: React.PropsWithChildren<ReactTableProps.ITable<T>>): JSX.Element;