@teselagen/ui 0.3.5 → 0.3.7
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/index.umd.js +165 -133
- package/package.json +3 -3
- package/src/DataTable/FilterAndSortMenu.js +68 -56
- package/src/DataTable/index.js +143 -142
- package/src/DataTable/utils/queryParams.js +1 -1
|
@@ -21,9 +21,35 @@ import "@teselagen/react-table/react-table.css";
|
|
|
21
21
|
import "./style.css";
|
|
22
22
|
import "../toastr";
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const filterTypesDictionary = {
|
|
25
|
+
none: "",
|
|
26
|
+
startsWith: "text",
|
|
27
|
+
endsWith: "text",
|
|
28
|
+
contains: "text",
|
|
29
|
+
notContains: "text",
|
|
30
|
+
isExactly: "text",
|
|
31
|
+
isEmpty: "text",
|
|
32
|
+
notEmpty: "text",
|
|
33
|
+
inList: "list",
|
|
34
|
+
notInList: "list",
|
|
35
|
+
true: "boolean",
|
|
36
|
+
false: "boolean",
|
|
37
|
+
dateIs: "date",
|
|
38
|
+
notBetween: "dateRange",
|
|
39
|
+
isBetween: "dateRange",
|
|
40
|
+
isBefore: "date",
|
|
41
|
+
isAfter: "date",
|
|
42
|
+
greaterThan: "number",
|
|
43
|
+
lessThan: "number",
|
|
44
|
+
inRange: "numberRange",
|
|
45
|
+
outsideRange: "numberRange",
|
|
46
|
+
equalTo: "number",
|
|
47
|
+
regex: "text"
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const isInvalidFilterValue = (value) => {
|
|
25
51
|
if (Array.isArray(value) && value.length) {
|
|
26
|
-
return value.some(item => isInvalidFilterValue(item));
|
|
52
|
+
return value.some((item) => isInvalidFilterValue(item));
|
|
27
53
|
}
|
|
28
54
|
return value === "" || value === undefined || value.length === 0;
|
|
29
55
|
};
|
|
@@ -38,10 +64,27 @@ export default class FilterAndSortMenu extends React.Component {
|
|
|
38
64
|
...this.props.currentFilter
|
|
39
65
|
};
|
|
40
66
|
}
|
|
41
|
-
handleFilterChange = selectedFilter => {
|
|
67
|
+
handleFilterChange = (selectedFilter) => {
|
|
68
|
+
const { filterValue } = this.state;
|
|
69
|
+
if (
|
|
70
|
+
filterValue &&
|
|
71
|
+
!Array.isArray(filterValue) &&
|
|
72
|
+
filterTypesDictionary[selectedFilter] === "list"
|
|
73
|
+
) {
|
|
74
|
+
this.setState({
|
|
75
|
+
filterValue: filterValue?.split(" ") || []
|
|
76
|
+
});
|
|
77
|
+
} else if (
|
|
78
|
+
filterTypesDictionary[selectedFilter] === "text" &&
|
|
79
|
+
Array.isArray(filterValue)
|
|
80
|
+
) {
|
|
81
|
+
this.setState({
|
|
82
|
+
filterValue: filterValue.join(" ")
|
|
83
|
+
});
|
|
84
|
+
}
|
|
42
85
|
this.setState({ selectedFilter: camelCase(selectedFilter) });
|
|
43
86
|
};
|
|
44
|
-
handleFilterValueChange = filterValue => {
|
|
87
|
+
handleFilterValueChange = (filterValue) => {
|
|
45
88
|
this.setState({ filterValue });
|
|
46
89
|
};
|
|
47
90
|
handleFilterSubmit = () => {
|
|
@@ -65,7 +108,7 @@ export default class FilterAndSortMenu extends React.Component {
|
|
|
65
108
|
if (dataType === "number") {
|
|
66
109
|
filterValToUse =
|
|
67
110
|
filterValue &&
|
|
68
|
-
filterValue.map(val => parseFloat(val.replaceAll(",", "")));
|
|
111
|
+
filterValue.map((val) => parseFloat(val.replaceAll(",", "")));
|
|
69
112
|
}
|
|
70
113
|
}
|
|
71
114
|
|
|
@@ -91,36 +134,9 @@ export default class FilterAndSortMenu extends React.Component {
|
|
|
91
134
|
render() {
|
|
92
135
|
const { selectedFilter, filterValue } = this.state;
|
|
93
136
|
const { dataType, currentFilter, removeSingleFilter } = this.props;
|
|
94
|
-
const {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
handleFilterSubmit
|
|
98
|
-
} = this;
|
|
99
|
-
const filterTypesDictionary = {
|
|
100
|
-
none: "",
|
|
101
|
-
startsWith: "text",
|
|
102
|
-
endsWith: "text",
|
|
103
|
-
contains: "text",
|
|
104
|
-
notContains: "text",
|
|
105
|
-
isExactly: "text",
|
|
106
|
-
isEmpty: "text",
|
|
107
|
-
notEmpty: "text",
|
|
108
|
-
inList: "list",
|
|
109
|
-
notInList: "list",
|
|
110
|
-
true: "boolean",
|
|
111
|
-
false: "boolean",
|
|
112
|
-
dateIs: "date",
|
|
113
|
-
notBetween: "dateRange",
|
|
114
|
-
isBetween: "dateRange",
|
|
115
|
-
isBefore: "date",
|
|
116
|
-
isAfter: "date",
|
|
117
|
-
greaterThan: "number",
|
|
118
|
-
lessThan: "number",
|
|
119
|
-
inRange: "numberRange",
|
|
120
|
-
outsideRange: "numberRange",
|
|
121
|
-
equalTo: "number",
|
|
122
|
-
regex: "text"
|
|
123
|
-
};
|
|
137
|
+
const { handleFilterChange, handleFilterValueChange, handleFilterSubmit } =
|
|
138
|
+
this;
|
|
139
|
+
|
|
124
140
|
const filterMenuItems = getFilterMenuItems(dataType);
|
|
125
141
|
const ccSelectedFilter = camelCase(selectedFilter);
|
|
126
142
|
const requiresValue = ccSelectedFilter && ccSelectedFilter !== "none";
|
|
@@ -130,13 +146,13 @@ export default class FilterAndSortMenu extends React.Component {
|
|
|
130
146
|
<div className="custom-menu-item">
|
|
131
147
|
<div className={classNames(Classes.SELECT, Classes.FILL)}>
|
|
132
148
|
<select
|
|
133
|
-
onChange={function(e) {
|
|
149
|
+
onChange={function (e) {
|
|
134
150
|
const ccSelectedFilter = camelCase(e.target.value);
|
|
135
151
|
handleFilterChange(ccSelectedFilter);
|
|
136
152
|
}}
|
|
137
153
|
value={ccSelectedFilter}
|
|
138
154
|
>
|
|
139
|
-
{filterMenuItems.map(function(menuItem, index) {
|
|
155
|
+
{filterMenuItems.map(function (menuItem, index) {
|
|
140
156
|
return (
|
|
141
157
|
<option key={index} value={camelCase(menuItem)}>
|
|
142
158
|
{menuItem}
|
|
@@ -176,12 +192,8 @@ export default class FilterAndSortMenu extends React.Component {
|
|
|
176
192
|
}
|
|
177
193
|
|
|
178
194
|
const dateMinMaxHelpers = {
|
|
179
|
-
minDate: dayjs()
|
|
180
|
-
|
|
181
|
-
.toDate(),
|
|
182
|
-
maxDate: dayjs()
|
|
183
|
-
.add(25, "years")
|
|
184
|
-
.toDate()
|
|
195
|
+
minDate: dayjs().subtract(25, "years").toDate(),
|
|
196
|
+
maxDate: dayjs().add(25, "years").toDate()
|
|
185
197
|
};
|
|
186
198
|
const renderCreateNewOption = (query, active, handleClick) => (
|
|
187
199
|
<MenuItem
|
|
@@ -213,7 +225,7 @@ class FilterInput extends React.Component {
|
|
|
213
225
|
<div className="custom-menu-item">
|
|
214
226
|
<InputGroup
|
|
215
227
|
placeholder="Value"
|
|
216
|
-
onChange={function(e) {
|
|
228
|
+
onChange={function (e) {
|
|
217
229
|
handleFilterValueChange(e.target.value);
|
|
218
230
|
}}
|
|
219
231
|
autoFocus
|
|
@@ -232,15 +244,15 @@ class FilterInput extends React.Component {
|
|
|
232
244
|
noResults={null}
|
|
233
245
|
multi={true}
|
|
234
246
|
creatable={true}
|
|
235
|
-
value={(filterValue || []).map(val => ({
|
|
247
|
+
value={(filterValue || []).map((val) => ({
|
|
236
248
|
label: val,
|
|
237
249
|
value: val
|
|
238
250
|
}))}
|
|
239
|
-
onChange={selectedOptions => {
|
|
240
|
-
selectedOptions.some(opt => opt.value === "")
|
|
251
|
+
onChange={(selectedOptions) => {
|
|
252
|
+
selectedOptions.some((opt) => opt.value === "")
|
|
241
253
|
? handleFilterSubmit()
|
|
242
254
|
: handleFilterValueChange(
|
|
243
|
-
selectedOptions.map(opt => opt.value)
|
|
255
|
+
selectedOptions.map((opt) => opt.value)
|
|
244
256
|
);
|
|
245
257
|
}}
|
|
246
258
|
options={[]}
|
|
@@ -253,7 +265,7 @@ class FilterInput extends React.Component {
|
|
|
253
265
|
<div className="custom-menu-item">
|
|
254
266
|
<NumericInput
|
|
255
267
|
placeholder="Value"
|
|
256
|
-
onValueChange={function(numVal) {
|
|
268
|
+
onValueChange={function (numVal) {
|
|
257
269
|
handleFilterValueChange(isNaN(numVal) ? 0 : numVal);
|
|
258
270
|
}}
|
|
259
271
|
autoFocus
|
|
@@ -268,7 +280,7 @@ class FilterInput extends React.Component {
|
|
|
268
280
|
<div className="custom-menu-item">
|
|
269
281
|
<NumericInput
|
|
270
282
|
placeholder="Low"
|
|
271
|
-
onValueChange={function(numVal) {
|
|
283
|
+
onValueChange={function (numVal) {
|
|
272
284
|
handleFilterValueChange([
|
|
273
285
|
isNaN(numVal) ? 0 : numVal,
|
|
274
286
|
filterValue[1]
|
|
@@ -279,7 +291,7 @@ class FilterInput extends React.Component {
|
|
|
279
291
|
/>
|
|
280
292
|
<NumericInput
|
|
281
293
|
placeholder="High"
|
|
282
|
-
onValueChange={function(numVal) {
|
|
294
|
+
onValueChange={function (numVal) {
|
|
283
295
|
handleFilterValueChange([
|
|
284
296
|
filterValue[0],
|
|
285
297
|
isNaN(numVal) ? 0 : numVal
|
|
@@ -298,7 +310,7 @@ class FilterInput extends React.Component {
|
|
|
298
310
|
value={filterValue ? dayjs(filterValue).toDate() : undefined}
|
|
299
311
|
{...getDayjsFormatter("L")}
|
|
300
312
|
{...dateMinMaxHelpers}
|
|
301
|
-
onChange={selectedDates => {
|
|
313
|
+
onChange={(selectedDates) => {
|
|
302
314
|
handleFilterValueChange(selectedDates);
|
|
303
315
|
}}
|
|
304
316
|
/>
|
|
@@ -312,7 +324,7 @@ class FilterInput extends React.Component {
|
|
|
312
324
|
filterValueToUse = filterValue;
|
|
313
325
|
} else {
|
|
314
326
|
filterValueToUse =
|
|
315
|
-
filterValue && filterValue.split && filterValue.split("
|
|
327
|
+
filterValue && filterValue.split && filterValue.split(";");
|
|
316
328
|
}
|
|
317
329
|
inputGroup = (
|
|
318
330
|
<div className="custom-menu-item">
|
|
@@ -329,13 +341,13 @@ class FilterInput extends React.Component {
|
|
|
329
341
|
captureDismiss: true
|
|
330
342
|
}}
|
|
331
343
|
{...{
|
|
332
|
-
formatDate: date =>
|
|
344
|
+
formatDate: (date) =>
|
|
333
345
|
date == null ? "" : date.toLocaleDateString(),
|
|
334
|
-
parseDate: str => new Date(Date.parse(str)),
|
|
346
|
+
parseDate: (str) => new Date(Date.parse(str)),
|
|
335
347
|
placeholder: "JS Date"
|
|
336
348
|
}}
|
|
337
349
|
{...dateMinMaxHelpers}
|
|
338
|
-
onChange={selectedDates => {
|
|
350
|
+
onChange={(selectedDates) => {
|
|
339
351
|
if (selectedDates[0] && selectedDates[1]) {
|
|
340
352
|
handleFilterValueChange(selectedDates);
|
|
341
353
|
}
|