@gpa-gemstone/react-table 1.2.57 → 1.2.59

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 (36) hide show
  1. package/lib/ConfigurableTable/ConfigurableColumn.d.ts +11 -0
  2. package/lib/{SearchableTable.js → ConfigurableTable/ConfigurableColumn.js} +7 -16
  3. package/lib/ConfigurableTable/ConfigurableTable.d.ts +25 -0
  4. package/lib/ConfigurableTable/ConfigurableTable.js +189 -0
  5. package/lib/Filters/BooleanFilter.d.ts +26 -0
  6. package/lib/Filters/BooleanFilter.js +68 -0
  7. package/lib/Filters/DateTimeFilters.d.ts +10 -0
  8. package/lib/Filters/DateTimeFilters.js +321 -0
  9. package/lib/Filters/EnumFilter.d.ts +37 -0
  10. package/lib/Filters/EnumFilter.js +89 -0
  11. package/lib/Filters/NumberFilter.d.ts +19 -0
  12. package/lib/Filters/NumberFilter.js +160 -0
  13. package/lib/Filters/TextFilter.d.ts +14 -0
  14. package/lib/Filters/TextFilter.js +78 -0
  15. package/lib/Table/Column.d.ts +19 -0
  16. package/lib/Table/Column.js +73 -0
  17. package/lib/Table/FilterableColumn.d.ts +20 -0
  18. package/lib/Table/FilterableColumn.js +74 -0
  19. package/lib/Table/Table.d.ts +3 -0
  20. package/lib/Table/Table.js +498 -0
  21. package/lib/{AdjustableTable/Table.d.ts → Table/Types.d.ts} +72 -4
  22. package/lib/{DynamicTable.js → Table/Types.js} +3 -23
  23. package/lib/index.d.ts +7 -14
  24. package/lib/index.js +13 -19
  25. package/package.json +8 -4
  26. package/lib/AdjustableTable/AdjustableColumn.d.ts +0 -18
  27. package/lib/AdjustableTable/AdjustableColumn.js +0 -187
  28. package/lib/AdjustableTable/Column.d.ts +0 -59
  29. package/lib/AdjustableTable/Column.js +0 -98
  30. package/lib/AdjustableTable/Table.js +0 -488
  31. package/lib/DynamicTable.d.ts +0 -37
  32. package/lib/SearchableTable.d.ts +0 -15
  33. package/lib/SelectTable.d.ts +0 -19
  34. package/lib/SelectTable.js +0 -102
  35. package/lib/Table.d.ts +0 -99
  36. package/lib/Table.js +0 -94
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ Default?: boolean;
4
+ Label?: string;
5
+ Key: string;
6
+ }
7
+ /**
8
+ * Wrapper to make any column configurable
9
+ */
10
+ export default function ConfigurableColumn(props: React.PropsWithChildren<IProps>): JSX.Element;
11
+ export {};
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  // ******************************************************************************************************
3
- // SearchableTable.tsx - Gbtc
3
+ // ConfigurableColumn.tsx - Gbtc
4
4
  //
5
- // Copyright © 2021, Grid Protection Alliance. All Rights Reserved.
5
+ // Copyright © 2023, Grid Protection Alliance. All Rights Reserved.
6
6
  //
7
7
  // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
8
  // the NOTICE file distributed with this work for additional information regarding copyright ownership.
@@ -17,24 +17,15 @@
17
17
  //
18
18
  // Code Modification History:
19
19
  // ----------------------------------------------------------------------------------------------------
20
- // 07/12/2021 - C. Lackner
20
+ // 11/18/2023 - Christoph Lackner
21
21
  // Generated original version of source code.
22
- //
23
22
  // ******************************************************************************************************
24
23
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.SearchableTable = SearchableTable;
24
+ exports.default = ConfigurableColumn;
26
25
  const React = require("react");
27
- const Table_1 = require("./Table");
28
26
  /**
29
- * A Table with an input Field to search on top
27
+ * Wrapper to make any column configurable
30
28
  */
31
- function SearchableTable(props) {
32
- const [data, setData] = React.useState(props.data);
33
- const [searchTextAS, setSearchTextAS] = React.useState('');
34
- React.useEffect(() => {
35
- setData(props.data.filter(s => props.matchSearch(s, searchTextAS)));
36
- }, [props.data, searchTextAS]);
37
- return React.createElement(React.Fragment, null,
38
- React.createElement("input", { className: "form-control", placeholder: "Search filter for select box ...", value: searchTextAS, onChange: (e) => setSearchTextAS(e.target.value) }),
39
- React.createElement(Table_1.default, Object.assign({}, props, { data: data })));
29
+ function ConfigurableColumn(props) {
30
+ return React.createElement(React.Fragment, null, props.children);
40
31
  }
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ import * as ReactTableProps from '../Table/Types';
3
+ interface ITableProps<T> extends ReactTableProps.ITable<T> {
4
+ /**
5
+ * Optional ZIndex for the configurable column modal
6
+ */
7
+ ModalZIndex?: number;
8
+ /**
9
+ * ID of the Portal used for tunneling Collumn settings
10
+ */
11
+ SettingsPortal?: string;
12
+ /**
13
+ * Callback when Settings modal opens or closes
14
+ */
15
+ OnSettingsChange?: (open: boolean) => void;
16
+ /**
17
+ * The key used to store columns in local storage
18
+ */
19
+ LocalStorageKey?: string;
20
+ }
21
+ /**
22
+ * Table with modal to show and hide columns
23
+ */
24
+ export default function ConfigurableTable<T>(props: React.PropsWithChildren<ITableProps<T>>): JSX.Element;
25
+ export {};
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // ConfigurableTable.tsx - Gbtc
4
+ //
5
+ // Copyright © 2021, 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
+ // 09/15/2021 - Christoph Lackner
21
+ // Generated original version of source code.
22
+ // ******************************************************************************************************
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.default = ConfigurableTable;
25
+ const React = require("react");
26
+ const Table_1 = require("../Table/Table");
27
+ const gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
28
+ const react_interactive_1 = require("@gpa-gemstone/react-interactive");
29
+ const react_portal_1 = require("react-portal");
30
+ const helper_functions_1 = require("@gpa-gemstone/helper-functions");
31
+ const react_forms_1 = require("@gpa-gemstone/react-forms");
32
+ const _ = require("lodash");
33
+ const ConfigurableColumn_1 = require("./ConfigurableColumn");
34
+ /**
35
+ * Table with modal to show and hide columns
36
+ */
37
+ function ConfigurableTable(props) {
38
+ const getKeyMappings = () => {
39
+ const u = new Map();
40
+ React.Children.forEach(props.children, (element) => {
41
+ var _a, _b;
42
+ if (!React.isValidElement(element))
43
+ return;
44
+ 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,
48
+ Enabled: false,
49
+ Key: element.props.Key,
50
+ };
51
+ c.Enabled = isEnabled(c);
52
+ u.set(c.Key, c);
53
+ }
54
+ });
55
+ return u;
56
+ };
57
+ const [showSettings, setShowSettings] = React.useState(false);
58
+ const [columns, setColumns] = React.useState(getKeyMappings());
59
+ const [hover, setHover] = React.useState(false);
60
+ const [guid] = React.useState((0, helper_functions_1.CreateGuid)());
61
+ const [widthDisabledAdd, setWidthDisabledAdd] = React.useState(false);
62
+ const handleReduceWidthCallback = React.useCallback((hiddenKeys) => {
63
+ if (hiddenKeys.length !== 0) {
64
+ setWidthDisabledAdd(true);
65
+ }
66
+ else {
67
+ setWidthDisabledAdd(false);
68
+ }
69
+ }, []);
70
+ React.useEffect(() => {
71
+ if (props.OnSettingsChange !== undefined)
72
+ props.OnSettingsChange(showSettings);
73
+ }, [showSettings]);
74
+ React.useEffect(() => {
75
+ saveLocal();
76
+ }, [columns]);
77
+ /**
78
+ *
79
+ * @returns
80
+ */
81
+ function saveLocal() {
82
+ if (props.LocalStorageKey === undefined)
83
+ return;
84
+ const currentState = localStorage.getItem(props.LocalStorageKey);
85
+ let currentKeys = [];
86
+ if (currentState !== null)
87
+ currentKeys = currentState.split(',');
88
+ const allKeys = Array.from(columns.keys());
89
+ currentKeys = currentKeys.filter((k) => !allKeys.includes(k));
90
+ const enabled = Array.from(columns.keys()).filter((k) => { var _a; return (_a = columns.get(k)) === null || _a === void 0 ? void 0 : _a.Enabled; });
91
+ currentKeys.push(...enabled);
92
+ localStorage.setItem(props.LocalStorageKey, currentKeys.join(','));
93
+ }
94
+ function changeColumns(key) {
95
+ setColumns((d) => {
96
+ var _a, _b;
97
+ const u = _.cloneDeep(d);
98
+ const mapRef = u.get(key);
99
+ if (mapRef == null) {
100
+ console.error("Could not find reference for column " + key);
101
+ }
102
+ else
103
+ mapRef.Enabled = !((_b = (_a = u.get(key)) === null || _a === void 0 ? void 0 : _a.Enabled) !== null && _b !== void 0 ? _b : false);
104
+ return u;
105
+ });
106
+ }
107
+ function checkLocal(key) {
108
+ if (props.LocalStorageKey === undefined)
109
+ return false;
110
+ const keys = localStorage.getItem(props.LocalStorageKey);
111
+ if (keys === null)
112
+ return false;
113
+ const activeKeys = keys.split(',');
114
+ return activeKeys.includes(key !== null && key !== void 0 ? key : '');
115
+ }
116
+ /**
117
+ * * Determines if a column is enabled by default, required, or was saved in the users preferences
118
+ * * @param c Column to check
119
+ * * @param skipLocal If true, will return whether it is enabled as part of the default settings
120
+ * */
121
+ function isEnabled(c, skipLocal = false) {
122
+ var _a;
123
+ const isSort = props.SortKey === (c === null || c === void 0 ? void 0 : c.Key);
124
+ const isLocal = checkLocal(c === null || c === void 0 ? void 0 : c.Key) && !skipLocal;
125
+ return ((_a = c === null || c === void 0 ? void 0 : c.Default) !== null && _a !== void 0 ? _a : false) || isSort || isLocal;
126
+ }
127
+ return (React.createElement(React.Fragment, null,
128
+ 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
+ React.createElement(gpa_symbols_1.ReactIcons.Settings, null)), ReduceWidthCallback: handleReduceWidthCallback }), React.Children.map(props.children, (element) => {
130
+ var _a, _b;
131
+ if (!React.isValidElement(element))
132
+ return null;
133
+ if (element.type === ConfigurableColumn_1.default)
134
+ return ((_b = (_a = columns.get(element.props.Key)) === null || _a === void 0 ? void 0 : _a.Enabled) !== null && _b !== void 0 ? _b : false) ? element.props.children : null;
135
+ return element;
136
+ })),
137
+ React.createElement(react_interactive_1.ToolTip, { Show: hover, Position: 'bottom', Target: guid + '-tooltip', Zindex: 99999 },
138
+ React.createElement("p", null, "Change Columns")),
139
+ props.SettingsPortal === undefined ? (React.createElement(react_interactive_1.Modal, { Title: 'Table Columns', Show: showSettings, ShowX: true, ShowCancel: false, ZIndex: props.ModalZIndex, CallBack: (conf) => {
140
+ setShowSettings(false);
141
+ if (conf)
142
+ setColumns((d) => {
143
+ const u = _.cloneDeep(d);
144
+ Array.from(d.keys()).forEach((k) => {
145
+ var _a;
146
+ const ref = u.get(k);
147
+ if (ref != null)
148
+ ref.Enabled = (_a = isEnabled(u.get(k), true)) !== null && _a !== void 0 ? _a : true;
149
+ });
150
+ return u;
151
+ });
152
+ }, ConfirmText: 'Reset Defaults', ConfirmBtnClass: 'btn-warning float-left' },
153
+ React.createElement(ColumnSelection, { columns: Array.from(columns.values()), onChange: changeColumns, sortKey: props.SortKey, disableAdd: widthDisabledAdd }))) : showSettings ? (React.createElement(react_portal_1.Portal, { node: document === null || document === void 0 ? void 0 : document.getElementById(props.SettingsPortal) },
154
+ React.createElement("div", { className: "card" },
155
+ React.createElement("div", { className: "card-header" },
156
+ React.createElement("h4", { className: "modal-title" }, "Table Columns"),
157
+ React.createElement("button", { type: "button", className: "close", onClick: () => setShowSettings(false) }, "\u00D7")),
158
+ React.createElement("div", { className: "card-body", style: { maxHeight: 'calc(100% - 210px)', overflowY: 'auto' } },
159
+ React.createElement(ColumnSelection, { columns: Array.from(columns.values()), onChange: changeColumns, sortKey: props.SortKey, disableAdd: widthDisabledAdd })),
160
+ React.createElement("div", { className: "card-footer" },
161
+ React.createElement("button", { type: "button", className: 'btn btn-primary float-left', onClick: () => {
162
+ setShowSettings(false);
163
+ setColumns((d) => {
164
+ const u = _.cloneDeep(d);
165
+ Array.from(d.keys()).forEach((k) => {
166
+ var _a;
167
+ const ref = u.get(k);
168
+ if (ref != null)
169
+ ref.Enabled = (_a = isEnabled(u.get(k), true)) !== null && _a !== void 0 ? _a : true;
170
+ });
171
+ return u;
172
+ });
173
+ } }, "Reset Defaults"))))) : null));
174
+ }
175
+ function ColumnSelection(props) {
176
+ const [showAlert, setShowAlert] = React.useState(true);
177
+ return (React.createElement(React.Fragment, null,
178
+ React.createElement("div", { className: "row" },
179
+ 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
180
+ ? 'The Table is currently sorted by this column so it cannot be hidden.'
181
+ : undefined })) : null)),
182
+ 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
183
+ ? 'The Table is currently sorted by this column so it cannot be hidden.'
184
+ : undefined })) : null)),
185
+ 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
186
+ ? 'The Table is currently sorted by this column so it cannot be hidden.'
187
+ : undefined })) : null))),
188
+ props.disableAdd ? (React.createElement(react_interactive_1.Alert, { AlertColor: 'alert-primary', Style: { marginBottom: 0, marginTop: '0.5em' }, Show: showAlert, SetShow: setShowAlert }, "Additional columns disabled due to table size.")) : null));
189
+ }
@@ -0,0 +1,26 @@
1
+ import { Search } from '@gpa-gemstone/react-interactive';
2
+ /**
3
+ * Interface defining the properties expected by the BooleanFilter component.
4
+ */
5
+ interface IFilterProps<T> {
6
+ /**
7
+ * Function to set the filter based on Search.IFilter<T> array.
8
+ * @param evt - Event handler that updates the filter.
9
+ */
10
+ SetFilter: (evt: Search.IFilter<T>[]) => void;
11
+ /**
12
+ * Array of filters of type Search.IFilter<T>.
13
+ */
14
+ Filter: Search.IFilter<T>[];
15
+ /**
16
+ * Name of the field for filtering.
17
+ */
18
+ FieldName: string;
19
+ }
20
+ /**
21
+ * Component to handle boolean filtering based on provided filter props.
22
+ * @param {IFilterProps<T>} props - Props passed to the BooleanFilter component.
23
+ * @returns JSX element representing the BooleanFilter component.
24
+ */
25
+ export declare function BooleanFilter<T>(props: IFilterProps<T>): JSX.Element;
26
+ export {};
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BooleanFilter = BooleanFilter;
4
+ // ******************************************************************************************************
5
+ // BooleanFilter.tsx - Gbtc
6
+ //
7
+ // Copyright © 2022, Grid Protection Alliance. All Rights Reserved.
8
+ //
9
+ // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
10
+ // the NOTICE file distributed with this work for additional information regarding copyright ownership.
11
+ // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
12
+ // file except in compliance with the License. You may obtain a copy of the License at:
13
+ //
14
+ // http://opensource.org/licenses/MIT
15
+ //
16
+ // Unless agreed to in writing, the subject software distributed under the License is distributed on an
17
+ // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
18
+ // License for the specific language governing permissions and limitations.
19
+ //
20
+ // Code Modification History:
21
+ // ----------------------------------------------------------------------------------------------------
22
+ // 03/02/2022 - C. Lackner
23
+ // Generated original version of source code.
24
+ // ******************************************************************************************************
25
+ const React = require("react");
26
+ /**
27
+ * Component to handle boolean filtering based on provided filter props.
28
+ * @param {IFilterProps<T>} props - Props passed to the BooleanFilter component.
29
+ * @returns JSX element representing the BooleanFilter component.
30
+ */
31
+ function BooleanFilter(props) {
32
+ const [selected, setSelected] = React.useState(false);
33
+ const [notSelected, setNotSelected] = React.useState(false);
34
+ React.useEffect(() => {
35
+ if (props.Filter.length === 0) {
36
+ setSelected(true);
37
+ setNotSelected(true);
38
+ return;
39
+ }
40
+ setSelected(props.Filter[0].SearchText === '1');
41
+ setNotSelected(props.Filter[0].SearchText !== '1');
42
+ }, [props.Filter]);
43
+ React.useEffect(() => {
44
+ if (!selected && !notSelected) {
45
+ setSelected(true);
46
+ setNotSelected(true);
47
+ }
48
+ }, [selected, notSelected]);
49
+ React.useEffect(() => {
50
+ if (selected && !notSelected && (props.Filter.length === 0 || props.Filter[0].SearchText !== '1')) {
51
+ props.SetFilter([{ FieldName: props.FieldName, IsPivotColumn: false, SearchText: '1', Operator: '=', Type: 'boolean' }]);
52
+ }
53
+ if (!selected && notSelected && (props.Filter.length === 0 || props.Filter[0].SearchText !== '0')) {
54
+ props.SetFilter([{ FieldName: props.FieldName, IsPivotColumn: false, SearchText: '0', Operator: '=', Type: 'boolean' }]);
55
+ }
56
+ if (selected && notSelected && props.Filter.length > 0)
57
+ props.SetFilter([]);
58
+ }, [selected, notSelected]);
59
+ return React.createElement(React.Fragment, null,
60
+ React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); setSelected((s) => !s); } },
61
+ React.createElement("td", null,
62
+ React.createElement("input", { type: "checkbox", checked: selected, onChange: () => null })),
63
+ React.createElement("td", null, "Selected")),
64
+ React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); setNotSelected((v) => !v); } },
65
+ React.createElement("td", null,
66
+ React.createElement("input", { type: "checkbox", checked: notSelected, onChange: () => null })),
67
+ React.createElement("td", null, "Not Selected")));
68
+ }
@@ -0,0 +1,10 @@
1
+ import { Search } from '@gpa-gemstone/react-interactive';
2
+ interface IProps<T> {
3
+ SetFilter: (evt: Search.IFilter<T>[]) => void;
4
+ Filter: Search.IFilter<T>[];
5
+ FieldName: string;
6
+ }
7
+ export declare function DateFilter<T>(props: IProps<T>): JSX.Element;
8
+ export declare function TimeFilter<T>(props: IProps<T>): JSX.Element;
9
+ export declare function DateTimeFilter<T>(props: IProps<T>): JSX.Element;
10
+ export {};