@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.
- package/lib/AdjustableTable/Column.d.ts +6 -45
- package/lib/AdjustableTable/Column.js +32 -53
- package/lib/AdjustableTable/Table.d.ts +2 -116
- package/lib/AdjustableTable/Table.js +329 -347
- package/lib/AdjustableTable/Types.d.ts +148 -0
- package/lib/AdjustableTable/Types.js +24 -0
- package/lib/ConfigurableTable/ConfigurableColumn.d.ts +11 -0
- package/lib/ConfigurableTable/ConfigurableColumn.js +31 -0
- package/lib/ConfigurableTable/ConfigurableTable.d.ts +25 -0
- package/lib/ConfigurableTable/ConfigurableTable.js +189 -0
- package/lib/FilterableTable/BooleanFilter.d.ts +26 -0
- package/lib/FilterableTable/BooleanFilter.js +68 -0
- package/lib/FilterableTable/DateTimeFilters.d.ts +10 -0
- package/lib/FilterableTable/DateTimeFilters.js +321 -0
- package/lib/FilterableTable/EnumFilter.d.ts +37 -0
- package/lib/FilterableTable/EnumFilter.js +89 -0
- package/lib/FilterableTable/FilterableColumn.d.ts +20 -0
- package/lib/FilterableTable/FilterableColumn.js +34 -0
- package/lib/FilterableTable/FilterableTable.d.ts +12 -0
- package/lib/FilterableTable/FilterableTable.js +95 -0
- package/lib/FilterableTable/NumberFilter.d.ts +19 -0
- package/lib/FilterableTable/NumberFilter.js +160 -0
- package/lib/FilterableTable/TextFilter.d.ts +14 -0
- package/lib/FilterableTable/TextFilter.js +78 -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/Table/Types.d.ts +185 -0
- package/lib/Table/Types.js +24 -0
- package/lib/index.d.ts +7 -14
- package/lib/index.js +13 -19
- package/package.json +56 -52
- package/lib/AdjustableTable/AdjustableColumn.d.ts +0 -18
- package/lib/AdjustableTable/AdjustableColumn.js +0 -187
|
@@ -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,20 @@
|
|
|
1
|
+
import * as ReactTableProps from '../Table/Types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Search } from '@gpa-gemstone/react-interactive';
|
|
4
|
+
import { IUnit } from './NumberFilter';
|
|
5
|
+
interface IOptions {
|
|
6
|
+
Value: string | number;
|
|
7
|
+
Label: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const IsFilterableColumnProps: (props: any) => boolean;
|
|
10
|
+
interface IFilterableCollumn<T> extends ReactTableProps.IColumn<T> {
|
|
11
|
+
Type?: Search.FieldType;
|
|
12
|
+
Enum?: IOptions[];
|
|
13
|
+
ExpandedLabel?: string;
|
|
14
|
+
Unit?: IUnit[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Wrapper to make any column configurable
|
|
18
|
+
*/
|
|
19
|
+
export default function FilterableColumn<T>(props: React.PropsWithChildren<IFilterableCollumn<T>>): JSX.Element;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// FilterableColumn.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
|
+
// 12/05/2024 - G. Santos
|
|
21
|
+
// Generated original version of source code.
|
|
22
|
+
// ******************************************************************************************************
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.IsFilterableColumnProps = void 0;
|
|
25
|
+
exports.default = FilterableColumn;
|
|
26
|
+
const React = require("react");
|
|
27
|
+
const IsFilterableColumnProps = (props) => ((props === null || props === void 0 ? void 0 : props['Key']) != null);
|
|
28
|
+
exports.IsFilterableColumnProps = IsFilterableColumnProps;
|
|
29
|
+
/**
|
|
30
|
+
* Wrapper to make any column configurable
|
|
31
|
+
*/
|
|
32
|
+
function FilterableColumn(props) {
|
|
33
|
+
return React.createElement(React.Fragment, null, props.children);
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as ReactTableProps from '../Table/Types';
|
|
3
|
+
import { Search } from '@gpa-gemstone/react-interactive';
|
|
4
|
+
interface IProps<T> extends ReactTableProps.ITable<T> {
|
|
5
|
+
SetFilter: (filters: Search.IFilter<T>[]) => void;
|
|
6
|
+
DefaultFilter?: Search.IFilter<T>[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Table with Filters in the column headers
|
|
10
|
+
*/
|
|
11
|
+
export default function FilterableTable<T>(props: React.PropsWithChildren<IProps<T>>): JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// FilterableTable.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.default = FilterableTable;
|
|
25
|
+
const React = require("react");
|
|
26
|
+
const Table_1 = require("../Table/Table");
|
|
27
|
+
const Column_1 = require("../Table/Column");
|
|
28
|
+
const gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
|
29
|
+
const BooleanFilter_1 = require("./BooleanFilter");
|
|
30
|
+
const TextFilter_1 = require("./TextFilter");
|
|
31
|
+
const EnumFilter_1 = require("./EnumFilter");
|
|
32
|
+
const NumberFilter_1 = require("./NumberFilter");
|
|
33
|
+
const DateTimeFilters_1 = require("./DateTimeFilters");
|
|
34
|
+
const helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
35
|
+
const FilterableColumn_1 = require("./FilterableColumn");
|
|
36
|
+
// ToDo: This whole structure is kinda gross, this should live in react-table so we don't have to map FilterableColumn -> Column -> HeaderWrapper
|
|
37
|
+
/**
|
|
38
|
+
* Table with Filters in the column headers
|
|
39
|
+
*/
|
|
40
|
+
function FilterableTable(props) {
|
|
41
|
+
const [filters, setFilters] = React.useState((props.DefaultFilter === undefined ? [] : props.DefaultFilter));
|
|
42
|
+
const [guid] = React.useState((0, helper_functions_1.CreateGuid)());
|
|
43
|
+
function updateFilters(flts, fld) {
|
|
44
|
+
setFilters((fls) => {
|
|
45
|
+
const otherFilters = fls.filter(item => item.FieldName !== fld);
|
|
46
|
+
return otherFilters.concat(flts);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
React.useEffect(() => { props.SetFilter(filters); }, [filters]);
|
|
50
|
+
return (React.createElement(Table_1.Table, Object.assign({}, props), React.Children.map(props.children, (element) => {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f;
|
|
52
|
+
if (!React.isValidElement(element))
|
|
53
|
+
return null;
|
|
54
|
+
if (!(0, FilterableColumn_1.IsFilterableColumnProps)(element.props))
|
|
55
|
+
return null;
|
|
56
|
+
return (React.createElement(Column_1.Column, Object.assign({}, element.props),
|
|
57
|
+
React.createElement(Header, { Label: (_a = element.props) === null || _a === void 0 ? void 0 : _a.children, Filter: filters.filter(f => { var _a, _b; return f.FieldName === ((_b = (_a = element.props) === null || _a === void 0 ? void 0 : _a.Field) === null || _b === void 0 ? void 0 : _b.toString()); }), SetFilter: (f) => { var _a; return updateFilters(f, (_a = element.props) === null || _a === void 0 ? void 0 : _a.Field); }, Field: (_b = element.props) === null || _b === void 0 ? void 0 : _b.Field, Type: (_c = element.props) === null || _c === void 0 ? void 0 : _c.Type, Options: (_d = element.props) === null || _d === void 0 ? void 0 : _d.Enum, ExpandedLabel: (_e = element.props) === null || _e === void 0 ? void 0 : _e.ExpandedLabel, Guid: guid, Unit: (_f = element.props) === null || _f === void 0 ? void 0 : _f.Unit })));
|
|
58
|
+
})));
|
|
59
|
+
}
|
|
60
|
+
// Table column header details
|
|
61
|
+
function Header(props) {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
63
|
+
const [show, setShow] = React.useState(false);
|
|
64
|
+
return React.createElement(React.Fragment, null,
|
|
65
|
+
React.createElement("div", { onMouseEnter: () => setShow(true), onMouseLeave: () => setShow(false) },
|
|
66
|
+
React.createElement("div", { style: { marginRight: 25 } }, props.Label),
|
|
67
|
+
props.Type !== undefined ? React.createElement(React.Fragment, null,
|
|
68
|
+
React.createElement("div", { style: { width: 25, position: 'absolute', right: 12, top: 12 } }, props.Filter.length > 0 ? React.createElement(gpa_symbols_1.ReactIcons.Filter, null) : null),
|
|
69
|
+
React.createElement("div", { style: {
|
|
70
|
+
maxHeight: window.innerHeight * 0.50,
|
|
71
|
+
overflowY: 'auto',
|
|
72
|
+
padding: '10 5',
|
|
73
|
+
display: show ? 'block' : 'none',
|
|
74
|
+
position: 'absolute',
|
|
75
|
+
backgroundColor: '#fff',
|
|
76
|
+
boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
|
|
77
|
+
zIndex: 401,
|
|
78
|
+
minWidth: 'calc(100% - 50px)',
|
|
79
|
+
marginLeft: -25
|
|
80
|
+
}, "data-tableid": props.Guid, onClick: (evt) => { evt.preventDefault(); evt.stopPropagation(); } },
|
|
81
|
+
React.createElement("table", { style: { margin: 0 } },
|
|
82
|
+
React.createElement("tbody", null,
|
|
83
|
+
((props.ExpandedLabel !== null) && (props.ExpandedLabel !== "") && (props.ExpandedLabel !== undefined)) ?
|
|
84
|
+
React.createElement("tr", null,
|
|
85
|
+
React.createElement("th", { colSpan: props.Type === 'boolean' ? 2 : 1 },
|
|
86
|
+
React.createElement("label", null, props.ExpandedLabel)))
|
|
87
|
+
: null,
|
|
88
|
+
props.Type === 'boolean' ? React.createElement(BooleanFilter_1.BooleanFilter, { SetFilter: props.SetFilter, Filter: props.Filter, FieldName: (_b = (_a = props.Field) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '' }) : null,
|
|
89
|
+
props.Type === 'string' ? React.createElement(TextFilter_1.TextFilter, { SetFilter: props.SetFilter, Filter: props.Filter, FieldName: (_d = (_c = props.Field) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : '' }) : null,
|
|
90
|
+
props.Type === 'enum' && props.Options !== undefined ? React.createElement(EnumFilter_1.EnumFilter, { FieldName: (_f = (_e = props.Field) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '', Filter: props.Filter, SetFilter: props.SetFilter, Options: props.Options }) : null,
|
|
91
|
+
props.Type === 'date' ? React.createElement(DateTimeFilters_1.DateFilter, { FieldName: (_h = (_g = props.Field) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _h !== void 0 ? _h : '', Filter: props.Filter, SetFilter: props.SetFilter }) : null,
|
|
92
|
+
props.Type === 'time' ? React.createElement(DateTimeFilters_1.TimeFilter, { FieldName: (_k = (_j = props.Field) === null || _j === void 0 ? void 0 : _j.toString()) !== null && _k !== void 0 ? _k : '', Filter: props.Filter, SetFilter: props.SetFilter }) : null,
|
|
93
|
+
props.Type === 'number' ? React.createElement(NumberFilter_1.NumberFilter, { FieldName: (_m = (_l = props.Field) === null || _l === void 0 ? void 0 : _l.toString()) !== null && _m !== void 0 ? _m : '', Filter: props.Filter, SetFilter: props.SetFilter, Unit: props.Unit }) : null,
|
|
94
|
+
props.Type === 'datetime' ? React.createElement(DateTimeFilters_1.DateTimeFilter, { FieldName: (_p = (_o = props.Field) === null || _o === void 0 ? void 0 : _o.toString()) !== null && _p !== void 0 ? _p : '', Filter: props.Filter, SetFilter: props.SetFilter }) : null)))) : null));
|
|
95
|
+
}
|
|
@@ -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 {};
|