@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.
- package/lib/ConfigurableTable/ConfigurableColumn.d.ts +11 -0
- package/lib/{SearchableTable.js → ConfigurableTable/ConfigurableColumn.js} +7 -16
- package/lib/ConfigurableTable/ConfigurableTable.d.ts +25 -0
- package/lib/ConfigurableTable/ConfigurableTable.js +189 -0
- package/lib/Filters/BooleanFilter.d.ts +26 -0
- package/lib/Filters/BooleanFilter.js +68 -0
- package/lib/Filters/DateTimeFilters.d.ts +10 -0
- package/lib/Filters/DateTimeFilters.js +321 -0
- package/lib/Filters/EnumFilter.d.ts +37 -0
- package/lib/Filters/EnumFilter.js +89 -0
- package/lib/Filters/NumberFilter.d.ts +19 -0
- package/lib/Filters/NumberFilter.js +160 -0
- package/lib/Filters/TextFilter.d.ts +14 -0
- package/lib/Filters/TextFilter.js +78 -0
- package/lib/Table/Column.d.ts +19 -0
- package/lib/Table/Column.js +73 -0
- package/lib/Table/FilterableColumn.d.ts +20 -0
- package/lib/Table/FilterableColumn.js +74 -0
- package/lib/Table/Table.d.ts +3 -0
- package/lib/Table/Table.js +498 -0
- package/lib/{AdjustableTable/Table.d.ts → Table/Types.d.ts} +72 -4
- package/lib/{DynamicTable.js → Table/Types.js} +3 -23
- package/lib/index.d.ts +7 -14
- package/lib/index.js +13 -19
- package/package.json +8 -4
- package/lib/AdjustableTable/AdjustableColumn.d.ts +0 -18
- package/lib/AdjustableTable/AdjustableColumn.js +0 -187
- package/lib/AdjustableTable/Column.d.ts +0 -59
- package/lib/AdjustableTable/Column.js +0 -98
- package/lib/AdjustableTable/Table.js +0 -488
- package/lib/DynamicTable.d.ts +0 -37
- package/lib/SearchableTable.d.ts +0 -15
- package/lib/SelectTable.d.ts +0 -19
- package/lib/SelectTable.js +0 -102
- package/lib/Table.d.ts +0 -99
- package/lib/Table.js +0 -94
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// DateTimeFilters.tsx - Gbtc
|
|
4
|
+
//
|
|
5
|
+
// Copyright © 2022, 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
|
+
// 03/02/2022 - C Lackner
|
|
21
|
+
// Generated original version of source code.
|
|
22
|
+
// ******************************************************************************************************
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.DateFilter = DateFilter;
|
|
25
|
+
exports.TimeFilter = TimeFilter;
|
|
26
|
+
exports.DateTimeFilter = DateTimeFilter;
|
|
27
|
+
const React = require("react");
|
|
28
|
+
const react_forms_1 = require("@gpa-gemstone/react-forms");
|
|
29
|
+
// Defines time and date formats
|
|
30
|
+
const momentDateFormat = "MM/DD/YYYY";
|
|
31
|
+
const momentTimeFormat = "HH:mm:ss.SSS"; // Also is the gemstone format
|
|
32
|
+
// Filter for date only
|
|
33
|
+
function DateFilter(props) {
|
|
34
|
+
const [date, setDate] = React.useState('');
|
|
35
|
+
const [secondDate, setSecondDate] = React.useState('');
|
|
36
|
+
const [operator, setOperator] = React.useState('after');
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (props.Filter.length === 0) {
|
|
39
|
+
setDate('');
|
|
40
|
+
setSecondDate('');
|
|
41
|
+
}
|
|
42
|
+
if (props.Filter.length > 1) {
|
|
43
|
+
const f1 = props.Filter.find(f => f.Operator === '>' || f.Operator === '>=');
|
|
44
|
+
if (f1 == null)
|
|
45
|
+
setDate('');
|
|
46
|
+
else
|
|
47
|
+
setDate(f1.SearchText);
|
|
48
|
+
const f2 = props.Filter.find(f => f.Operator === '<' || f.Operator === '<=');
|
|
49
|
+
if (f2 == null)
|
|
50
|
+
setSecondDate('');
|
|
51
|
+
else
|
|
52
|
+
setSecondDate(f2.SearchText);
|
|
53
|
+
if (f1 !== null && f2 !== null)
|
|
54
|
+
setOperator('between');
|
|
55
|
+
else if (f1 == null)
|
|
56
|
+
setOperator('before');
|
|
57
|
+
else
|
|
58
|
+
setOperator('after');
|
|
59
|
+
}
|
|
60
|
+
if (props.Filter.length === 1) {
|
|
61
|
+
setSecondDate('');
|
|
62
|
+
if (props.Filter[0].Operator === '>' || props.Filter[0].Operator === '>=')
|
|
63
|
+
setOperator('after');
|
|
64
|
+
else
|
|
65
|
+
setOperator('before');
|
|
66
|
+
setDate(props.Filter[0].SearchText);
|
|
67
|
+
}
|
|
68
|
+
}, [props.Filter]);
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
let handle = null;
|
|
71
|
+
if (date === '' && secondDate === '' && props.Filter.length !== 0)
|
|
72
|
+
handle = setTimeout(() => props.SetFilter([]), 500);
|
|
73
|
+
if (date === '' && secondDate === '')
|
|
74
|
+
return () => { if (handle !== null)
|
|
75
|
+
clearTimeout(handle); };
|
|
76
|
+
if (operator === 'between')
|
|
77
|
+
handle = setTimeout(() => props.SetFilter([
|
|
78
|
+
{
|
|
79
|
+
FieldName: props.FieldName,
|
|
80
|
+
IsPivotColumn: false,
|
|
81
|
+
Operator: '>=',
|
|
82
|
+
Type: 'datetime',
|
|
83
|
+
SearchText: date
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
FieldName: props.FieldName,
|
|
87
|
+
IsPivotColumn: false,
|
|
88
|
+
Operator: '<=',
|
|
89
|
+
Type: 'datetime',
|
|
90
|
+
SearchText: secondDate
|
|
91
|
+
}
|
|
92
|
+
]), 500);
|
|
93
|
+
else
|
|
94
|
+
handle = setTimeout(() => props.SetFilter([{
|
|
95
|
+
FieldName: props.FieldName,
|
|
96
|
+
IsPivotColumn: false,
|
|
97
|
+
Operator: (operator === 'after' ? '>' : '<'),
|
|
98
|
+
Type: 'datetime',
|
|
99
|
+
SearchText: date
|
|
100
|
+
}]), 500);
|
|
101
|
+
return () => { if (handle !== null)
|
|
102
|
+
clearTimeout(handle); };
|
|
103
|
+
}, [operator, date, secondDate]);
|
|
104
|
+
return React.createElement(React.Fragment, null,
|
|
105
|
+
React.createElement("tr", null,
|
|
106
|
+
React.createElement("td", null,
|
|
107
|
+
React.createElement("select", { className: 'form-control', value: operator, onChange: (evt) => {
|
|
108
|
+
const value = evt.target.value;
|
|
109
|
+
setOperator(value);
|
|
110
|
+
} },
|
|
111
|
+
React.createElement("option", { value: 'before' }, "Before"),
|
|
112
|
+
React.createElement("option", { value: 'after' }, "After"),
|
|
113
|
+
React.createElement("option", { value: 'between' }, "Between")))),
|
|
114
|
+
React.createElement("tr", null,
|
|
115
|
+
React.createElement("td", null,
|
|
116
|
+
React.createElement("input", { type: 'date', className: 'form-control', value: date, onChange: (evt) => {
|
|
117
|
+
const value = evt.target.value;
|
|
118
|
+
setDate(value);
|
|
119
|
+
} }))),
|
|
120
|
+
operator === 'between' ? React.createElement(React.Fragment, null,
|
|
121
|
+
React.createElement("tr", null,
|
|
122
|
+
React.createElement("td", null, "and")),
|
|
123
|
+
React.createElement("tr", null,
|
|
124
|
+
React.createElement("td", null,
|
|
125
|
+
React.createElement("input", { type: 'date', className: 'form-control', value: secondDate, onChange: (evt) => {
|
|
126
|
+
const value = evt.target.value;
|
|
127
|
+
setSecondDate(value);
|
|
128
|
+
} })))) : null);
|
|
129
|
+
}
|
|
130
|
+
// Time filter only
|
|
131
|
+
function TimeFilter(props) {
|
|
132
|
+
const [time, setTime] = React.useState('');
|
|
133
|
+
const [secondTime, setSecondTime] = React.useState('');
|
|
134
|
+
const [operator, setOperator] = React.useState('after');
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
if (props.Filter.length === 0) {
|
|
137
|
+
setTime('');
|
|
138
|
+
setSecondTime('');
|
|
139
|
+
}
|
|
140
|
+
if (props.Filter.length > 1) {
|
|
141
|
+
const f1 = props.Filter.find(f => f.Operator === '>' || f.Operator === '>=');
|
|
142
|
+
if (f1 == null)
|
|
143
|
+
setTime('');
|
|
144
|
+
else
|
|
145
|
+
setTime(f1.SearchText);
|
|
146
|
+
const f2 = props.Filter.find(f => f.Operator === '<' || f.Operator === '<=');
|
|
147
|
+
if (f2 == null)
|
|
148
|
+
setSecondTime('');
|
|
149
|
+
else
|
|
150
|
+
setSecondTime(f2.SearchText);
|
|
151
|
+
if (f1 !== null && f2 !== null)
|
|
152
|
+
setOperator('between');
|
|
153
|
+
else if (f1 == null)
|
|
154
|
+
setOperator('before');
|
|
155
|
+
else
|
|
156
|
+
setOperator('after');
|
|
157
|
+
}
|
|
158
|
+
if (props.Filter.length === 1) {
|
|
159
|
+
setSecondTime('');
|
|
160
|
+
if (props.Filter[0].Operator === '>' || props.Filter[0].Operator === '>=')
|
|
161
|
+
setOperator('after');
|
|
162
|
+
else
|
|
163
|
+
setOperator('before');
|
|
164
|
+
setTime(props.Filter[0].SearchText);
|
|
165
|
+
}
|
|
166
|
+
}, [props.Filter]);
|
|
167
|
+
React.useEffect(() => {
|
|
168
|
+
let handle = null;
|
|
169
|
+
if (time === '' && secondTime === '' && props.Filter.length !== 0)
|
|
170
|
+
handle = setTimeout(() => props.SetFilter([]), 500);
|
|
171
|
+
if (time === '' && secondTime === '')
|
|
172
|
+
return () => { if (handle !== null)
|
|
173
|
+
clearTimeout(handle); };
|
|
174
|
+
if (operator === 'between')
|
|
175
|
+
handle = setTimeout(() => props.SetFilter([
|
|
176
|
+
{
|
|
177
|
+
FieldName: props.FieldName,
|
|
178
|
+
IsPivotColumn: false,
|
|
179
|
+
Operator: '>=',
|
|
180
|
+
Type: 'datetime',
|
|
181
|
+
SearchText: time
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
FieldName: props.FieldName,
|
|
185
|
+
IsPivotColumn: false,
|
|
186
|
+
Operator: '<=',
|
|
187
|
+
Type: 'datetime',
|
|
188
|
+
SearchText: secondTime
|
|
189
|
+
}
|
|
190
|
+
]), 500);
|
|
191
|
+
else
|
|
192
|
+
handle = setTimeout(() => props.SetFilter([{
|
|
193
|
+
FieldName: props.FieldName,
|
|
194
|
+
IsPivotColumn: false,
|
|
195
|
+
Operator: (operator === 'after' ? '>' : '<'),
|
|
196
|
+
Type: 'datetime',
|
|
197
|
+
SearchText: time
|
|
198
|
+
}]), 500);
|
|
199
|
+
return () => { if (handle !== null)
|
|
200
|
+
clearTimeout(handle); };
|
|
201
|
+
}, [operator, time, secondTime]);
|
|
202
|
+
return React.createElement(React.Fragment, null,
|
|
203
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
204
|
+
React.createElement("td", null,
|
|
205
|
+
React.createElement("select", { className: 'form-control', value: operator, onChange: (evt) => {
|
|
206
|
+
const value = evt.target.value;
|
|
207
|
+
setOperator(value);
|
|
208
|
+
} },
|
|
209
|
+
React.createElement("option", { value: 'before' }, "Before"),
|
|
210
|
+
React.createElement("option", { value: 'after' }, "After"),
|
|
211
|
+
React.createElement("option", { value: 'between' }, "Between")))),
|
|
212
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
213
|
+
React.createElement("td", null,
|
|
214
|
+
React.createElement("input", { type: 'time', className: 'form-control', value: time, onChange: (evt) => {
|
|
215
|
+
const value = evt.target.value;
|
|
216
|
+
setTime(value);
|
|
217
|
+
} }))),
|
|
218
|
+
operator === 'between' ? React.createElement(React.Fragment, null,
|
|
219
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
220
|
+
React.createElement("td", null, "and")),
|
|
221
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
222
|
+
React.createElement("td", null,
|
|
223
|
+
React.createElement("input", { type: 'time', className: 'form-control', value: secondTime, onChange: (evt) => {
|
|
224
|
+
const value = evt.target.value;
|
|
225
|
+
setSecondTime(value);
|
|
226
|
+
} })))) : null);
|
|
227
|
+
}
|
|
228
|
+
// DateTime combination filter
|
|
229
|
+
function DateTimeFilter(props) {
|
|
230
|
+
const [dateTime, setDateTime] = React.useState('');
|
|
231
|
+
const [secondDateTime, setSecondDateTime] = React.useState('');
|
|
232
|
+
const val = React.useMemo(() => ({ Value: dateTime }), [dateTime]);
|
|
233
|
+
const val2 = React.useMemo(() => ({ Value: secondDateTime }), [secondDateTime]);
|
|
234
|
+
const [operator, setOperator] = React.useState('after');
|
|
235
|
+
React.useEffect(() => {
|
|
236
|
+
if (props.Filter.length === 0) {
|
|
237
|
+
setDateTime('');
|
|
238
|
+
setSecondDateTime('');
|
|
239
|
+
}
|
|
240
|
+
if (props.Filter.length > 1) {
|
|
241
|
+
const f1 = props.Filter.find(f => f.Operator === '>' || f.Operator === '>=');
|
|
242
|
+
if (f1 == null)
|
|
243
|
+
setDateTime('');
|
|
244
|
+
else
|
|
245
|
+
setDateTime(f1.SearchText);
|
|
246
|
+
const f2 = props.Filter.find(f => f.Operator === '<' || f.Operator === '<=');
|
|
247
|
+
if (f2 == null)
|
|
248
|
+
setSecondDateTime('');
|
|
249
|
+
else
|
|
250
|
+
setSecondDateTime(f2.SearchText);
|
|
251
|
+
if (f1 !== null && f2 !== null)
|
|
252
|
+
setOperator('between');
|
|
253
|
+
else if (f1 == null)
|
|
254
|
+
setOperator('before');
|
|
255
|
+
else
|
|
256
|
+
setOperator('after');
|
|
257
|
+
}
|
|
258
|
+
if (props.Filter.length === 1) {
|
|
259
|
+
setSecondDateTime('');
|
|
260
|
+
if (props.Filter[0].Operator === '>' || props.Filter[0].Operator === '>=')
|
|
261
|
+
setOperator('after');
|
|
262
|
+
else
|
|
263
|
+
setOperator('before');
|
|
264
|
+
setDateTime(props.Filter[0].SearchText);
|
|
265
|
+
}
|
|
266
|
+
}, [props.Filter]);
|
|
267
|
+
React.useEffect(() => {
|
|
268
|
+
let handle = null;
|
|
269
|
+
if (dateTime === '' && secondDateTime === '' && props.Filter.length !== 0)
|
|
270
|
+
handle = setTimeout(() => props.SetFilter([]), 500);
|
|
271
|
+
if (dateTime === '' && secondDateTime === '')
|
|
272
|
+
return () => { if (handle !== null)
|
|
273
|
+
clearTimeout(handle); };
|
|
274
|
+
if (operator === 'between')
|
|
275
|
+
handle = setTimeout(() => props.SetFilter([
|
|
276
|
+
{
|
|
277
|
+
FieldName: props.FieldName,
|
|
278
|
+
IsPivotColumn: false,
|
|
279
|
+
Operator: '>=',
|
|
280
|
+
Type: 'datetime',
|
|
281
|
+
SearchText: dateTime
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
FieldName: props.FieldName,
|
|
285
|
+
IsPivotColumn: false,
|
|
286
|
+
Operator: '<=',
|
|
287
|
+
Type: 'datetime',
|
|
288
|
+
SearchText: secondDateTime
|
|
289
|
+
}
|
|
290
|
+
]), 500);
|
|
291
|
+
else
|
|
292
|
+
handle = setTimeout(() => props.SetFilter([{
|
|
293
|
+
FieldName: props.FieldName,
|
|
294
|
+
IsPivotColumn: false,
|
|
295
|
+
Operator: (operator === 'after' ? '>' : '<'),
|
|
296
|
+
Type: 'datetime',
|
|
297
|
+
SearchText: dateTime
|
|
298
|
+
}]), 500);
|
|
299
|
+
return () => { if (handle !== null)
|
|
300
|
+
clearTimeout(handle); };
|
|
301
|
+
}, [operator, dateTime, secondDateTime]);
|
|
302
|
+
return React.createElement(React.Fragment, null,
|
|
303
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
304
|
+
React.createElement("td", null,
|
|
305
|
+
React.createElement("select", { className: 'form-control', value: operator, onChange: (evt) => {
|
|
306
|
+
const value = evt.target.value;
|
|
307
|
+
setOperator(value);
|
|
308
|
+
} },
|
|
309
|
+
React.createElement("option", { value: 'before' }, "Before"),
|
|
310
|
+
React.createElement("option", { value: 'after' }, "After"),
|
|
311
|
+
React.createElement("option", { value: 'between' }, "Between")))),
|
|
312
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
313
|
+
React.createElement("td", null,
|
|
314
|
+
React.createElement(react_forms_1.DatePicker, { Record: val, Field: "Value", Setter: (r) => setDateTime(r.Value), Label: '', Type: 'datetime-local', Valid: () => true, Format: momentDateFormat + ' ' + momentTimeFormat }))),
|
|
315
|
+
operator === 'between' ? React.createElement(React.Fragment, null,
|
|
316
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
317
|
+
React.createElement("td", null, "and")),
|
|
318
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
319
|
+
React.createElement("td", null,
|
|
320
|
+
React.createElement(react_forms_1.DatePicker, { Record: val2, Field: "Value", Setter: (r) => setSecondDateTime(r.Value), Label: '', Type: 'datetime-local', Valid: () => true, Format: momentDateFormat + ' ' + momentTimeFormat })))) : null);
|
|
321
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Search } from '@gpa-gemstone/react-interactive';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an option with a value and label.
|
|
4
|
+
*/
|
|
5
|
+
interface IOptions {
|
|
6
|
+
Value: string | number;
|
|
7
|
+
Label: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents the properties expected by the EnumFilter component.
|
|
11
|
+
*/
|
|
12
|
+
interface IProps<T> {
|
|
13
|
+
/**
|
|
14
|
+
* Function to set the filter based on Search.IFilter<T> array.
|
|
15
|
+
* @param evt - Event handler that updates the filter.
|
|
16
|
+
*/
|
|
17
|
+
SetFilter: (evt: Search.IFilter<T>[]) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Array of filters of type Search.IFilter<T>.
|
|
20
|
+
*/
|
|
21
|
+
Filter: Search.IFilter<T>[];
|
|
22
|
+
/**
|
|
23
|
+
* Name of filtering field.
|
|
24
|
+
*/
|
|
25
|
+
FieldName: string;
|
|
26
|
+
/**
|
|
27
|
+
* The array of IOptions[] for filtering.
|
|
28
|
+
*/
|
|
29
|
+
Options: IOptions[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Component to handle enum filtering based on provided filter props.
|
|
33
|
+
* @param {IProps<T>} props - Props passed to EnumFilter.
|
|
34
|
+
* @returns JSX element representing EnumFilter component.
|
|
35
|
+
*/
|
|
36
|
+
export declare function EnumFilter<T>(props: IProps<T>): JSX.Element;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnumFilter = EnumFilter;
|
|
4
|
+
// ******************************************************************************************************
|
|
5
|
+
// EnumFilter.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 enum filtering based on provided filter props.
|
|
28
|
+
* @param {IProps<T>} props - Props passed to EnumFilter.
|
|
29
|
+
* @returns JSX element representing EnumFilter component.
|
|
30
|
+
*/
|
|
31
|
+
function EnumFilter(props) {
|
|
32
|
+
// State for options with selection.
|
|
33
|
+
const [options, setOptions] = React.useState([]);
|
|
34
|
+
// Update options based on props.Options changes.
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
if (props.Options.length !== options.length)
|
|
37
|
+
setOptions(props.Options.map(item => (Object.assign(Object.assign({}, item), { Selected: true }))));
|
|
38
|
+
else if (props.Options.some((o, i) => o.Label !== options[i].Label || o.Value !== options[i].Value))
|
|
39
|
+
setOptions(props.Options.map(item => (Object.assign(Object.assign({}, item), { Selected: true }))));
|
|
40
|
+
}, [props.Options]);
|
|
41
|
+
// Updates filter based on selected option changes.
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (props.Filter.length !== 0 && (options.filter((x) => x.Selected).length === options.length)) {
|
|
44
|
+
props.SetFilter([]);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (options.some(item => !item.Selected))
|
|
48
|
+
props.SetFilter([{
|
|
49
|
+
FieldName: props.FieldName,
|
|
50
|
+
IsPivotColumn: false,
|
|
51
|
+
Operator: 'IN',
|
|
52
|
+
Type: 'enum',
|
|
53
|
+
SearchText: `(${options.filter(o => o.Selected).map(x => x.Value).join(',')})`
|
|
54
|
+
}]);
|
|
55
|
+
}, [options]);
|
|
56
|
+
// Updates options based on filter changes.
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
if (props.Filter.length === 0)
|
|
59
|
+
setOptions((opt) => opt.map(item => (Object.assign(Object.assign({}, item), { Selected: true }))));
|
|
60
|
+
else {
|
|
61
|
+
let list = props.Filter[0].SearchText.replace('(', '').replace(')', '').split(',');
|
|
62
|
+
list = list.filter(x => x !== "");
|
|
63
|
+
const hasChanged = options.some(item => {
|
|
64
|
+
const i = list.findIndex(l => l === item.Value);
|
|
65
|
+
if (i < 0 && item.Selected)
|
|
66
|
+
return true;
|
|
67
|
+
if (i >= 0 && !item.Selected)
|
|
68
|
+
return true;
|
|
69
|
+
return false;
|
|
70
|
+
});
|
|
71
|
+
if (hasChanged)
|
|
72
|
+
setOptions((opt) => opt.map((item) => (Object.assign(Object.assign({}, item), { Selected: list.findIndex(l => l == item.Value) >= 0 }))));
|
|
73
|
+
}
|
|
74
|
+
}, [props.Filter]);
|
|
75
|
+
// Renders option checkboxes.
|
|
76
|
+
return React.createElement(React.Fragment, null,
|
|
77
|
+
React.createElement("tr", { onClick: (evt) => {
|
|
78
|
+
evt.preventDefault();
|
|
79
|
+
const isChecked = options.filter((x) => x.Selected).length === options.length;
|
|
80
|
+
setOptions((old) => old.map((o) => (Object.assign(Object.assign({}, o), { Selected: !isChecked }))));
|
|
81
|
+
} },
|
|
82
|
+
React.createElement("td", null,
|
|
83
|
+
React.createElement("input", { type: "checkbox", checked: options.filter((x) => x.Selected).length === options.length, onChange: () => null })),
|
|
84
|
+
React.createElement("td", null, "All")),
|
|
85
|
+
options.map((f, i) => (React.createElement("tr", { key: i, onClick: () => { setOptions((old) => old.map((o) => (Object.assign(Object.assign({}, o), { Selected: (o.Value === f.Value ? !o.Selected : o.Selected) })))); } },
|
|
86
|
+
React.createElement("td", null,
|
|
87
|
+
React.createElement("input", { type: "checkbox", checked: f.Selected, onChange: () => null })),
|
|
88
|
+
React.createElement("td", null, f.Label)))));
|
|
89
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
Unit?: IUnit[];
|
|
7
|
+
}
|
|
8
|
+
export interface IUnit {
|
|
9
|
+
label: string;
|
|
10
|
+
GetValue: (value: number) => number;
|
|
11
|
+
GetFilter: (filter: number) => number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param props
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare function NumberFilter<T>(props: IProps<T>): JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberFilter = NumberFilter;
|
|
4
|
+
// ******************************************************************************************************
|
|
5
|
+
// NumberFilter.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
|
+
*
|
|
28
|
+
* @param props
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
function NumberFilter(props) {
|
|
32
|
+
var _a, _b, _c, _d, _e;
|
|
33
|
+
const [value, setValue] = React.useState('');
|
|
34
|
+
const [secondValue, setSecondValue] = React.useState('');
|
|
35
|
+
const [operator, setOperator] = React.useState('less than');
|
|
36
|
+
const [unitIndex, setUnitIndex] = React.useState(0);
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (props.Filter.length === 0) {
|
|
39
|
+
setValue('');
|
|
40
|
+
setSecondValue('');
|
|
41
|
+
}
|
|
42
|
+
if (props.Filter.length > 1) {
|
|
43
|
+
const f1 = props.Filter.find(f => f.Operator === '>' || f.Operator === '>=');
|
|
44
|
+
if (f1 == null)
|
|
45
|
+
setValue('');
|
|
46
|
+
else
|
|
47
|
+
setValue(f1.SearchText);
|
|
48
|
+
const f2 = props.Filter.find(f => f.Operator === '<' || f.Operator === '<=');
|
|
49
|
+
if (f2 == null)
|
|
50
|
+
setSecondValue('');
|
|
51
|
+
else
|
|
52
|
+
setSecondValue(f2.SearchText);
|
|
53
|
+
}
|
|
54
|
+
if (props.Filter.length === 1) {
|
|
55
|
+
setSecondValue('');
|
|
56
|
+
if (props.Filter[0].Operator === '>' || props.Filter[0].Operator === '>=')
|
|
57
|
+
setOperator('greater than');
|
|
58
|
+
else if (props.Filter[0].Operator === '=')
|
|
59
|
+
setOperator('equal to');
|
|
60
|
+
else
|
|
61
|
+
setOperator('less than');
|
|
62
|
+
setValue(props.Filter[0].SearchText);
|
|
63
|
+
}
|
|
64
|
+
}, [props.Filter]);
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
let handle = null;
|
|
67
|
+
if (value === '' && secondValue === '' && props.Filter.length !== 0)
|
|
68
|
+
handle = setTimeout(() => props.SetFilter([]), 500);
|
|
69
|
+
if (value === '' && secondValue === '')
|
|
70
|
+
return () => { if (handle !== null)
|
|
71
|
+
clearTimeout(handle); };
|
|
72
|
+
if (operator === 'between')
|
|
73
|
+
handle = setTimeout(() => props.SetFilter([
|
|
74
|
+
{
|
|
75
|
+
FieldName: props.FieldName,
|
|
76
|
+
IsPivotColumn: false,
|
|
77
|
+
Operator: '>=',
|
|
78
|
+
Type: 'number',
|
|
79
|
+
SearchText: value
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
FieldName: props.FieldName,
|
|
83
|
+
IsPivotColumn: false,
|
|
84
|
+
Operator: '<=',
|
|
85
|
+
Type: 'number',
|
|
86
|
+
SearchText: secondValue
|
|
87
|
+
}
|
|
88
|
+
]), 500);
|
|
89
|
+
else
|
|
90
|
+
handle = setTimeout(() => props.SetFilter([{
|
|
91
|
+
FieldName: props.FieldName,
|
|
92
|
+
IsPivotColumn: false,
|
|
93
|
+
Operator: transformSymbol(operator),
|
|
94
|
+
Type: 'number',
|
|
95
|
+
SearchText: value
|
|
96
|
+
}]), 500);
|
|
97
|
+
return () => { if (handle !== null)
|
|
98
|
+
clearTimeout(handle); };
|
|
99
|
+
}, [operator, value, secondValue]);
|
|
100
|
+
function transformSymbol(s) {
|
|
101
|
+
if (s === 'less than')
|
|
102
|
+
return '<';
|
|
103
|
+
if (s === 'greater than')
|
|
104
|
+
return '>';
|
|
105
|
+
return '=';
|
|
106
|
+
}
|
|
107
|
+
const hasUnit = props.Unit !== undefined && unitIndex >= 0 && unitIndex < props.Unit.length;
|
|
108
|
+
return React.createElement(React.Fragment, null,
|
|
109
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
110
|
+
React.createElement("td", null,
|
|
111
|
+
React.createElement("select", { className: 'form-control', value: operator, onChange: (evt) => {
|
|
112
|
+
const v = evt.target.value;
|
|
113
|
+
setOperator(v);
|
|
114
|
+
} },
|
|
115
|
+
React.createElement("option", { value: 'less than' },
|
|
116
|
+
"Less than (",
|
|
117
|
+
'<',
|
|
118
|
+
")"),
|
|
119
|
+
React.createElement("option", { value: 'equal to' }, "Equal to (=)"),
|
|
120
|
+
React.createElement("option", { value: 'greater than' },
|
|
121
|
+
"Greater than (",
|
|
122
|
+
'>',
|
|
123
|
+
")"),
|
|
124
|
+
React.createElement("option", { value: 'between' }, "In range")))),
|
|
125
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
126
|
+
React.createElement("td", null,
|
|
127
|
+
React.createElement("input", { type: 'number', className: 'form-control', value: props.Unit !== undefined && hasUnit ? (_a = props.Unit[unitIndex].GetValue(parseFloat(value)).toString()) !== null && _a !== void 0 ? _a : '' : value, onChange: (evt) => {
|
|
128
|
+
let v = evt.target.value;
|
|
129
|
+
if (props.Unit !== undefined && unitIndex >= 0 && unitIndex < props.Unit.length) {
|
|
130
|
+
v = props.Unit[unitIndex].GetFilter(parseFloat(v)).toString();
|
|
131
|
+
}
|
|
132
|
+
setValue(v);
|
|
133
|
+
} })),
|
|
134
|
+
props.Unit !== undefined ?
|
|
135
|
+
React.createElement("td", null,
|
|
136
|
+
React.createElement("select", { className: 'form-control', value: (_c = (_b = props.Unit[unitIndex]) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : '', onChange: (evt) => {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
const v = evt.target.value;
|
|
139
|
+
setUnitIndex((_b = (_a = props.Unit) === null || _a === void 0 ? void 0 : _a.findIndex(u => u.label === v)) !== null && _b !== void 0 ? _b : -1);
|
|
140
|
+
} }, props.Unit.map((u) => React.createElement("option", { value: u.label, key: u.label }, u.label)))) : null),
|
|
141
|
+
operator === 'between' ? React.createElement(React.Fragment, null,
|
|
142
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
143
|
+
React.createElement("td", null, "and")),
|
|
144
|
+
React.createElement("tr", { onClick: (evt) => { evt.preventDefault(); } },
|
|
145
|
+
React.createElement("td", null,
|
|
146
|
+
React.createElement("input", { type: 'number', className: 'form-control', value: props.Unit !== undefined && hasUnit ? props.Unit[unitIndex].GetValue(parseFloat(secondValue)).toString() : secondValue, onChange: (evt) => {
|
|
147
|
+
let v = evt.target.value;
|
|
148
|
+
if (props.Unit !== undefined && unitIndex >= 0 && unitIndex < props.Unit.length) {
|
|
149
|
+
v = props.Unit[unitIndex].GetFilter(parseFloat(v)).toString();
|
|
150
|
+
}
|
|
151
|
+
setSecondValue(v);
|
|
152
|
+
} }))),
|
|
153
|
+
props.Unit !== undefined ?
|
|
154
|
+
React.createElement("td", null,
|
|
155
|
+
React.createElement("select", { className: 'form-control', value: (_e = (_d = props.Unit[unitIndex]) === null || _d === void 0 ? void 0 : _d.label) !== null && _e !== void 0 ? _e : '', onChange: (evt) => {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
const v = evt.target.value;
|
|
158
|
+
setUnitIndex((_b = (_a = props.Unit) === null || _a === void 0 ? void 0 : _a.findIndex(u => u.label === v)) !== null && _b !== void 0 ? _b : -1);
|
|
159
|
+
} }, props.Unit.map((u) => React.createElement("option", { value: u.label, key: u.label }, u.label)))) : null) : null);
|
|
160
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
ApproxMatches?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Component for rendering a text input filter.
|
|
10
|
+
* @param props - Props for configuring and managing the text filter.
|
|
11
|
+
* @returns JSX for rendering a text input filter with wildcard options.
|
|
12
|
+
*/
|
|
13
|
+
export declare function TextFilter<T>(props: IProps<T>): JSX.Element;
|
|
14
|
+
export {};
|