@gpa-gemstone/react-table 1.2.56 → 1.2.58

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 (47) hide show
  1. package/lib/AdjustableTable/Column.d.ts +6 -45
  2. package/lib/AdjustableTable/Column.js +32 -53
  3. package/lib/AdjustableTable/Table.d.ts +2 -116
  4. package/lib/AdjustableTable/Table.js +329 -347
  5. package/lib/AdjustableTable/Types.d.ts +148 -0
  6. package/lib/AdjustableTable/Types.js +24 -0
  7. package/lib/ConfigurableTable/ConfigurableColumn.d.ts +11 -0
  8. package/lib/ConfigurableTable/ConfigurableColumn.js +31 -0
  9. package/lib/ConfigurableTable/ConfigurableTable.d.ts +25 -0
  10. package/lib/ConfigurableTable/ConfigurableTable.js +189 -0
  11. package/lib/FilterableTable/BooleanFilter.d.ts +26 -0
  12. package/lib/FilterableTable/BooleanFilter.js +68 -0
  13. package/lib/FilterableTable/DateTimeFilters.d.ts +10 -0
  14. package/lib/FilterableTable/DateTimeFilters.js +321 -0
  15. package/lib/FilterableTable/EnumFilter.d.ts +37 -0
  16. package/lib/FilterableTable/EnumFilter.js +89 -0
  17. package/lib/FilterableTable/FilterableColumn.d.ts +20 -0
  18. package/lib/FilterableTable/FilterableColumn.js +34 -0
  19. package/lib/FilterableTable/FilterableTable.d.ts +12 -0
  20. package/lib/FilterableTable/FilterableTable.js +95 -0
  21. package/lib/FilterableTable/NumberFilter.d.ts +19 -0
  22. package/lib/FilterableTable/NumberFilter.js +160 -0
  23. package/lib/FilterableTable/TextFilter.d.ts +14 -0
  24. package/lib/FilterableTable/TextFilter.js +78 -0
  25. package/lib/Filters/BooleanFilter.d.ts +26 -0
  26. package/lib/Filters/BooleanFilter.js +68 -0
  27. package/lib/Filters/DateTimeFilters.d.ts +10 -0
  28. package/lib/Filters/DateTimeFilters.js +321 -0
  29. package/lib/Filters/EnumFilter.d.ts +37 -0
  30. package/lib/Filters/EnumFilter.js +89 -0
  31. package/lib/Filters/NumberFilter.d.ts +19 -0
  32. package/lib/Filters/NumberFilter.js +160 -0
  33. package/lib/Filters/TextFilter.d.ts +14 -0
  34. package/lib/Filters/TextFilter.js +78 -0
  35. package/lib/Table/Column.d.ts +19 -0
  36. package/lib/Table/Column.js +73 -0
  37. package/lib/Table/FilterableColumn.d.ts +20 -0
  38. package/lib/Table/FilterableColumn.js +74 -0
  39. package/lib/Table/Table.d.ts +3 -0
  40. package/lib/Table/Table.js +498 -0
  41. package/lib/Table/Types.d.ts +185 -0
  42. package/lib/Table/Types.js +24 -0
  43. package/lib/index.d.ts +7 -14
  44. package/lib/index.js +13 -19
  45. package/package.json +56 -52
  46. package/lib/AdjustableTable/AdjustableColumn.d.ts +0 -18
  47. package/lib/AdjustableTable/AdjustableColumn.js +0 -187
@@ -0,0 +1,148 @@
1
+ export interface ITable<T> {
2
+ /**
3
+ * List of T objects used to generate rows
4
+ */
5
+ Data: T[];
6
+ /**
7
+ * Callback when the user clicks on a data entry
8
+ * @param data contains the data including the columnKey
9
+ * @param event the onClick Event to allow propagation as needed
10
+ * @returns
11
+ */
12
+ OnClick?: (data: {
13
+ colKey?: string;
14
+ colField?: keyof T;
15
+ row: T;
16
+ data: T[keyof T] | null;
17
+ index: number;
18
+ }, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
19
+ /**
20
+ * Key of the collumn to sort by
21
+ */
22
+ SortKey: string;
23
+ /**
24
+ * Boolen to indicate whether the sort is ascending or descending
25
+ */
26
+ Ascending: boolean;
27
+ /**
28
+ * Callback when the data should be sorted
29
+ * @param data the information of the collumn including the Key of the collumn
30
+ * @param event The onCLick event to allow Propagation as needed
31
+ */
32
+ OnSort(data: {
33
+ colKey: string;
34
+ colField?: keyof T;
35
+ ascending: boolean;
36
+ }, event: React.MouseEvent<HTMLElement, MouseEvent>): void;
37
+ /**
38
+ * Class of the table component
39
+ */
40
+ TableClass?: string;
41
+ /**
42
+ * style of the table component
43
+ */
44
+ TableStyle?: React.CSSProperties;
45
+ /**
46
+ * style of the thead component
47
+ */
48
+ TheadStyle?: React.CSSProperties;
49
+ /**
50
+ * Class of the thead component
51
+ */
52
+ TheadClass?: string;
53
+ /**
54
+ * style of the tbody component
55
+ * Note: Display style overwritten to "block"
56
+ */
57
+ TbodyStyle?: React.CSSProperties;
58
+ /**
59
+ * Class of the tbody component
60
+ */
61
+ TbodyClass?: string;
62
+ /**
63
+ * style of the tfoot component
64
+ */
65
+ TfootStyle?: React.CSSProperties;
66
+ /**
67
+ * Class of the tfoot component
68
+ */
69
+ TfootClass?: string;
70
+ /**
71
+ * determines if a row should be styled as selected
72
+ * @param data the item to be checked
73
+ * @returns true if the row should be styled as selected
74
+ */
75
+ Selected?: (data: T, index: number) => boolean;
76
+ /**
77
+ *
78
+ * @param data the information of the row including the item of the row
79
+ * @param e the event triggering this
80
+ * @returns
81
+ */
82
+ OnDragStart?: (data: {
83
+ colKey?: string;
84
+ colField?: keyof T;
85
+ row: T;
86
+ data: T[keyof T] | null;
87
+ index: number;
88
+ }, e: React.DragEvent<Element>) => void;
89
+ /**
90
+ * The default style for the tr element
91
+ */
92
+ RowStyle?: React.CSSProperties;
93
+ /**
94
+ * a Function that retrieves a unique key used for React key properties
95
+ * @param data the item to be turned into a key
96
+ * @returns a unique Key
97
+ */
98
+ KeySelector: (data: T, index?: number) => string | number;
99
+ /**
100
+ * Optional Element to display in the last row of the Table
101
+ * use this for displaying warnings when the Table content gets cut off.
102
+ * Data appears in the tfoot element
103
+ */
104
+ LastRow?: string | React.ReactNode;
105
+ /**
106
+ * Optional Element to display on upper Right corner
107
+ */
108
+ LastColumn?: string | React.ReactNode;
109
+ /**
110
+ * Optional Callback that gets called when there is not enough space to display columns
111
+ * @param disabled takes in string of disabled keys
112
+ */
113
+ ReduceWidthCallback?: (disabled: string[]) => void;
114
+ }
115
+ export interface IColumn<T> {
116
+ /**
117
+ * a unique Key for this Collumn
118
+ */
119
+ Key: string;
120
+ /**
121
+ * Flag indicating whether sorting by this Collumn is allowed
122
+ */
123
+ AllowSort?: boolean;
124
+ /**
125
+ * Optional - the Field to be used
126
+ */
127
+ Field?: keyof T;
128
+ /**
129
+ * The Default style for the th element
130
+ */
131
+ HeaderStyle?: React.CSSProperties;
132
+ /**
133
+ * The Default style for the td element
134
+ */
135
+ RowStyle?: React.CSSProperties;
136
+ /**
137
+ * Determines the Content to be displayed
138
+ * @param d the data to be turned into content
139
+ * @returns the content displayed
140
+ */
141
+ Content?: (d: {
142
+ item: T;
143
+ key: string;
144
+ field: keyof T | undefined;
145
+ index: number;
146
+ style?: React.CSSProperties;
147
+ }) => React.ReactNode;
148
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // Types.ts - 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
+ // 12/06/2024 - G. Santos
21
+ // Migrated props to namespace.
22
+ //
23
+ // ******************************************************************************************************
24
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // ConfigurableColumn.tsx - Gbtc
4
+ //
5
+ // Copyright © 2023, 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
+ // 11/18/2023 - Christoph Lackner
21
+ // Generated original version of source code.
22
+ // ******************************************************************************************************
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.default = ConfigurableColumn;
25
+ const React = require("react");
26
+ /**
27
+ * Wrapper to make any column configurable
28
+ */
29
+ function ConfigurableColumn(props) {
30
+ return React.createElement(React.Fragment, null, props.children);
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 {};