fe-fabric-react 0.0.1-security → 2.864.3
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.
Potentially problematic release.
This version of fe-fabric-react might be problematic. Click here for more details.
- package/build.js +40 -0
- package/lib/core/FontAwesomeContext.js +126 -0
- package/lib/core/components/FeAppLogo.js +54 -0
- package/lib/core/components/FeAvatar.js +314 -0
- package/lib/core/components/FeBadge.js +177 -0
- package/lib/core/components/FeBreadcrumb.js +205 -0
- package/lib/core/components/FeButton.js +185 -0
- package/lib/core/components/FeCheckbox.js +91 -0
- package/lib/core/components/FeCogButton.js +204 -0
- package/lib/core/components/FeDefaultLink.js +108 -0
- package/lib/core/components/FeDropdown.js +677 -0
- package/lib/core/components/FeFormGroup.js +245 -0
- package/lib/core/components/FeIcon.js +52 -0
- package/lib/core/components/FeIconStack.js +26 -0
- package/lib/core/components/FeInputField.js +500 -0
- package/lib/core/components/FeLabel.js +142 -0
- package/lib/core/components/FeListItem.js +719 -0
- package/lib/core/components/FeListItemGroup.js +364 -0
- package/lib/core/components/FeLoader.js +69 -0
- package/lib/core/components/FeNotification.js +351 -0
- package/lib/core/components/FePillBox.js +353 -0
- package/lib/core/components/FeProgressBar.js +282 -0
- package/lib/core/components/FeRadioButton.js +234 -0
- package/lib/core/components/FeSearchField.js +322 -0
- package/lib/core/components/FeSelfContainedInput.js +215 -0
- package/lib/core/components/FeTableCell.js +27 -0
- package/lib/core/components/FeTableHeaderCell.js +273 -0
- package/lib/core/components/FeTableRow.js +24 -0
- package/lib/core/components/FeTextEnrichment.js +78 -0
- package/lib/core/components/FeToggle.js +69 -0
- package/lib/core/index.js +243 -0
- package/lib/core/utils/aria-role.js +11 -0
- package/lib/core/utils/fe-filter.js +157 -0
- package/lib/core/utils/helper.js +11 -0
- package/lib/core/utils/index.js +268 -0
- package/lib/customPropTypes.js +51 -0
- package/lib/fe-filter/FeFilter.js +1312 -0
- package/lib/fe-filter/index.js +17 -0
- package/lib/fe-footer/FeFooter.js +81 -0
- package/lib/fe-footer/index.js +17 -0
- package/lib/fe-hero/FeHero.js +192 -0
- package/lib/fe-hero/index.js +17 -0
- package/lib/fe-modal/FeModal.js +409 -0
- package/lib/fe-modal/index.js +17 -0
- package/lib/fe-notifications/FeNotifications.js +235 -0
- package/lib/fe-notifications/index.js +17 -0
- package/lib/fe-pagination/FePagination.js +688 -0
- package/lib/fe-pagination/index.js +17 -0
- package/lib/fe-panel/FePanel.js +282 -0
- package/lib/fe-panel/index.js +17 -0
- package/lib/fe-sidenav/FeSideNav.js +78 -0
- package/lib/fe-sidenav/FeSideNavList.js +346 -0
- package/lib/fe-sidenav/index.js +17 -0
- package/lib/fe-table/FeTable.js +703 -0
- package/lib/fe-table/index.js +17 -0
- package/lib/fe-topnav/FeTopNav.js +110 -0
- package/lib/fe-topnav/FeTopNavList.js +401 -0
- package/lib/fe-topnav/index.js +17 -0
- package/lib/index.js +129 -0
- package/lib/layout/Col.js +187 -0
- package/lib/layout/Container.js +97 -0
- package/lib/layout/Row.js +99 -0
- package/lib/layout/index.js +35 -0
- package/package.json +42 -4
- package/README.md +0 -5
@@ -0,0 +1,1312 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
11
|
+
|
12
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
13
|
+
|
14
|
+
var _toNumber = _interopRequireDefault(require("lodash/toNumber"));
|
15
|
+
|
16
|
+
var _feFilter = _interopRequireDefault(require("../core/utils/fe-filter"));
|
17
|
+
|
18
|
+
var _utils = require("../core/utils");
|
19
|
+
|
20
|
+
var _helper = require("../core/utils/helper");
|
21
|
+
|
22
|
+
var _core = require("../core");
|
23
|
+
|
24
|
+
function _interopRequireDefault(obj) {
|
25
|
+
return obj && obj.__esModule ? obj : {
|
26
|
+
default: obj
|
27
|
+
};
|
28
|
+
}
|
29
|
+
|
30
|
+
function _interopRequireWildcard(obj) {
|
31
|
+
if (obj && obj.__esModule) {
|
32
|
+
return obj;
|
33
|
+
} else {
|
34
|
+
var newObj = {};
|
35
|
+
|
36
|
+
if (obj != null) {
|
37
|
+
for (var key in obj) {
|
38
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
39
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
40
|
+
|
41
|
+
if (desc.get || desc.set) {
|
42
|
+
Object.defineProperty(newObj, key, desc);
|
43
|
+
} else {
|
44
|
+
newObj[key] = obj[key];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
newObj.default = obj;
|
51
|
+
return newObj;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
function _typeof(obj) {
|
56
|
+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
57
|
+
_typeof = function _typeof(obj) {
|
58
|
+
return typeof obj;
|
59
|
+
};
|
60
|
+
} else {
|
61
|
+
_typeof = function _typeof(obj) {
|
62
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
63
|
+
};
|
64
|
+
}
|
65
|
+
|
66
|
+
return _typeof(obj);
|
67
|
+
}
|
68
|
+
|
69
|
+
function _extends() {
|
70
|
+
_extends = Object.assign || function (target) {
|
71
|
+
for (var i = 1; i < arguments.length; i++) {
|
72
|
+
var source = arguments[i];
|
73
|
+
|
74
|
+
for (var key in source) {
|
75
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
76
|
+
target[key] = source[key];
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
return target;
|
82
|
+
};
|
83
|
+
|
84
|
+
return _extends.apply(this, arguments);
|
85
|
+
}
|
86
|
+
|
87
|
+
function _classCallCheck(instance, Constructor) {
|
88
|
+
if (!(instance instanceof Constructor)) {
|
89
|
+
throw new TypeError("Cannot call a class as a function");
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
function _defineProperties(target, props) {
|
94
|
+
for (var i = 0; i < props.length; i++) {
|
95
|
+
var descriptor = props[i];
|
96
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
97
|
+
descriptor.configurable = true;
|
98
|
+
if ("value" in descriptor) descriptor.writable = true;
|
99
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
104
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
105
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
106
|
+
return Constructor;
|
107
|
+
}
|
108
|
+
|
109
|
+
function _possibleConstructorReturn(self, call) {
|
110
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
111
|
+
return call;
|
112
|
+
}
|
113
|
+
|
114
|
+
return _assertThisInitialized(self);
|
115
|
+
}
|
116
|
+
|
117
|
+
function _getPrototypeOf(o) {
|
118
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
119
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
120
|
+
};
|
121
|
+
return _getPrototypeOf(o);
|
122
|
+
}
|
123
|
+
|
124
|
+
function _assertThisInitialized(self) {
|
125
|
+
if (self === void 0) {
|
126
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
127
|
+
}
|
128
|
+
|
129
|
+
return self;
|
130
|
+
}
|
131
|
+
|
132
|
+
function _inherits(subClass, superClass) {
|
133
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
134
|
+
throw new TypeError("Super expression must either be null or a function");
|
135
|
+
}
|
136
|
+
|
137
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
138
|
+
constructor: {
|
139
|
+
value: subClass,
|
140
|
+
writable: true,
|
141
|
+
configurable: true
|
142
|
+
}
|
143
|
+
});
|
144
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
145
|
+
}
|
146
|
+
|
147
|
+
function _setPrototypeOf(o, p) {
|
148
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
149
|
+
o.__proto__ = p;
|
150
|
+
return o;
|
151
|
+
};
|
152
|
+
|
153
|
+
return _setPrototypeOf(o, p);
|
154
|
+
}
|
155
|
+
|
156
|
+
var FeFilter =
|
157
|
+
/*#__PURE__*/
|
158
|
+
function (_Component) {
|
159
|
+
_inherits(FeFilter, _Component);
|
160
|
+
|
161
|
+
function FeFilter(props) {
|
162
|
+
var _this;
|
163
|
+
|
164
|
+
_classCallCheck(this, FeFilter);
|
165
|
+
|
166
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(FeFilter).call(this, props));
|
167
|
+
_this.state = {
|
168
|
+
isOpen: false,
|
169
|
+
list: [],
|
170
|
+
editIndex: null,
|
171
|
+
appliedFilterOptionEdit: null,
|
172
|
+
appliedFilterTextEdit: null,
|
173
|
+
appliedFilterNode: null,
|
174
|
+
textHighlight: null,
|
175
|
+
listType: 'filters',
|
176
|
+
isPanelClear: true,
|
177
|
+
listStyle: null,
|
178
|
+
activeKey: null,
|
179
|
+
appliedFilters: null,
|
180
|
+
recentFilters: null
|
181
|
+
};
|
182
|
+
_this.onPanelFocus = _this.onPanelFocus.bind(_assertThisInitialized(_this));
|
183
|
+
_this.onPanelKeyUp = _this.onPanelKeyUp.bind(_assertThisInitialized(_this));
|
184
|
+
_this.onEditInputKeyUp = _this.onEditInputKeyUp.bind(_assertThisInitialized(_this));
|
185
|
+
_this.saveEditedTextInput = _this.saveEditedTextInput.bind(_assertThisInitialized(_this));
|
186
|
+
_this.hideSuggestionList = _this.hideSuggestionList.bind(_assertThisInitialized(_this));
|
187
|
+
_this.onPillboxClick = _this.onPillboxClick.bind(_assertThisInitialized(_this));
|
188
|
+
_this.onClearAll = _this.onClearAll.bind(_assertThisInitialized(_this));
|
189
|
+
_this.onToggleSuggestionList = _this.onToggleSuggestionList.bind(_assertThisInitialized(_this));
|
190
|
+
_this.onSuggestionListItemClick = _this.onSuggestionListItemClick.bind(_assertThisInitialized(_this));
|
191
|
+
return _this;
|
192
|
+
}
|
193
|
+
|
194
|
+
_createClass(FeFilter, [{
|
195
|
+
key: "onPanelFocus",
|
196
|
+
value: function onPanelFocus(event) {
|
197
|
+
var _this2 = this;
|
198
|
+
|
199
|
+
var _this$state = this.state,
|
200
|
+
activeKey = _this$state.activeKey,
|
201
|
+
textHighlight = _this$state.textHighlight,
|
202
|
+
editIndex = _this$state.editIndex,
|
203
|
+
appliedFilterOptionEdit = _this$state.appliedFilterOptionEdit,
|
204
|
+
appliedFilterTextEdit = _this$state.appliedFilterTextEdit,
|
205
|
+
appliedFilterNode = _this$state.appliedFilterNode;
|
206
|
+
var listStyle = {
|
207
|
+
position: 'absolute',
|
208
|
+
left: "".concat(event.currentTarget.offsetLeft, "px"),
|
209
|
+
top: "".concat(event.currentTarget.offsetTop + event.currentTarget.clientHeight / 2, "px")
|
210
|
+
};
|
211
|
+
var list = [],
|
212
|
+
listType,
|
213
|
+
isOpen = true;
|
214
|
+
var isEmptyValue = (0, _utils.isEmpty)(event.currentTarget.value);
|
215
|
+
|
216
|
+
if (activeKey && !appliedFilterTextEdit) {
|
217
|
+
if (activeKey.options && activeKey.options.length) {
|
218
|
+
list = this.filterSuggestionList(event.currentTarget.value, activeKey.options);
|
219
|
+
textHighlight = event.currentTarget.value;
|
220
|
+
listType = 'filterValue';
|
221
|
+
} else {
|
222
|
+
list = [];
|
223
|
+
isOpen = false;
|
224
|
+
textHighlight = null;
|
225
|
+
}
|
226
|
+
} else {
|
227
|
+
var filters = [];
|
228
|
+
|
229
|
+
if (this.props.withRecent && this.state.recentFilters) {
|
230
|
+
filters.push({
|
231
|
+
label: this.props.labelRecent,
|
232
|
+
list: this.state.recentFilters
|
233
|
+
});
|
234
|
+
}
|
235
|
+
|
236
|
+
if (this.props.savedFilters) {
|
237
|
+
var savedFilters = Object.assign([], this.props.savedFilters);
|
238
|
+
savedFilters.forEach(function (filter) {
|
239
|
+
if (filter.canRemove) {
|
240
|
+
delete filter.canRemove;
|
241
|
+
filter['iconRight'] = "".concat(_this2.props.iconRemove, " text-danger");
|
242
|
+
}
|
243
|
+
});
|
244
|
+
filters.push({
|
245
|
+
label: this.props.labelSaved,
|
246
|
+
list: savedFilters
|
247
|
+
});
|
248
|
+
}
|
249
|
+
|
250
|
+
if (this.props.config) {
|
251
|
+
filters.push({
|
252
|
+
label: this.props.labelFields,
|
253
|
+
list: this.props.config
|
254
|
+
});
|
255
|
+
}
|
256
|
+
|
257
|
+
list = this.filterSuggestionList(event.currentTarget.value, filters);
|
258
|
+
textHighlight = event.currentTarget.value;
|
259
|
+
listType = 'filters';
|
260
|
+
editIndex = null;
|
261
|
+
activeKey = null;
|
262
|
+
appliedFilterOptionEdit = null;
|
263
|
+
appliedFilterTextEdit = null;
|
264
|
+
appliedFilterNode = null;
|
265
|
+
}
|
266
|
+
|
267
|
+
this.setState({
|
268
|
+
isOpen: isOpen,
|
269
|
+
isPanelClear: isEmptyValue,
|
270
|
+
editIndex: editIndex,
|
271
|
+
activeKey: activeKey,
|
272
|
+
appliedFilterOptionEdit: appliedFilterOptionEdit,
|
273
|
+
appliedFilterTextEdit: appliedFilterTextEdit,
|
274
|
+
appliedFilterNode: appliedFilterNode,
|
275
|
+
list: list,
|
276
|
+
textHighlight: textHighlight,
|
277
|
+
listType: listType,
|
278
|
+
listStyle: listStyle
|
279
|
+
});
|
280
|
+
}
|
281
|
+
}, {
|
282
|
+
key: "onPanelKeyUp",
|
283
|
+
value: function onPanelKeyUp(event) {
|
284
|
+
var isEmptyValue = (0, _utils.isEmpty)(event.currentTarget.value);
|
285
|
+
var _this$state2 = this.state,
|
286
|
+
isOpen = _this$state2.isOpen,
|
287
|
+
activeKey = _this$state2.activeKey,
|
288
|
+
editIndex = _this$state2.editIndex,
|
289
|
+
appliedFilters = _this$state2.appliedFilters,
|
290
|
+
isPanelClear = _this$state2.isPanelClear,
|
291
|
+
listType = _this$state2.listType,
|
292
|
+
recentFilters = _this$state2.recentFilters;
|
293
|
+
var filters = Object.assign([], appliedFilters);
|
294
|
+
|
295
|
+
if (isEmptyValue && event.keyCode === 8) {
|
296
|
+
//BackSpace
|
297
|
+
if (activeKey && this.state.isPanelClear) {
|
298
|
+
activeKey = null;
|
299
|
+
editIndex = null;
|
300
|
+
listType = 'filters';
|
301
|
+
isOpen = false;
|
302
|
+
this.setState({
|
303
|
+
isOpen: isOpen,
|
304
|
+
activeKey: activeKey,
|
305
|
+
editIndex: editIndex,
|
306
|
+
listType: listType
|
307
|
+
});
|
308
|
+
} else if (appliedFilters && this.state.isPanelClear) {
|
309
|
+
//delete pillbox
|
310
|
+
appliedFilters.splice(appliedFilters.length - 1, 1);
|
311
|
+
|
312
|
+
if ((0, _utils.isEmpty)(appliedFilters)) {
|
313
|
+
appliedFilters = null;
|
314
|
+
}
|
315
|
+
|
316
|
+
this.setState({
|
317
|
+
isOpen: false,
|
318
|
+
appliedFilters: appliedFilters
|
319
|
+
});
|
320
|
+
|
321
|
+
if (this.props.onFilterChange) {
|
322
|
+
this.props.onFilterChange({
|
323
|
+
appliedFilters: appliedFilters,
|
324
|
+
recentFilters: recentFilters
|
325
|
+
});
|
326
|
+
}
|
327
|
+
} else {
|
328
|
+
this.onPanelFocus(event);
|
329
|
+
}
|
330
|
+
} else if (activeKey && event.currentTarget.value.trim() && event.keyCode === 13 && !this.state.isPanelClear) {
|
331
|
+
//Enter
|
332
|
+
if (activeKey.options && activeKey.options.length) {
|
333
|
+
// TODO: Inform user to choose from list only
|
334
|
+
isOpen = true;
|
335
|
+
} else {
|
336
|
+
var value = event.currentTarget.value.trim();
|
337
|
+
var isValid = this.isValid(activeKey.regx, value);
|
338
|
+
|
339
|
+
if (isValid) {
|
340
|
+
filters = this.updateFilter(activeKey.name, value);
|
341
|
+
recentFilters = this.updateRecentFilters(activeKey, value);
|
342
|
+
activeKey = null;
|
343
|
+
editIndex = null;
|
344
|
+
isOpen = false;
|
345
|
+
listType = 'filters';
|
346
|
+
isPanelClear = true;
|
347
|
+
this.clearInputPanel();
|
348
|
+
|
349
|
+
if (this.props.onFilterChange) {
|
350
|
+
this.props.onFilterChange({
|
351
|
+
appliedFilters: filters,
|
352
|
+
recentFilters: recentFilters
|
353
|
+
});
|
354
|
+
}
|
355
|
+
} else {// TODO: Show error for wrong input
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
this.setState({
|
360
|
+
isOpen: isOpen,
|
361
|
+
activeKey: activeKey,
|
362
|
+
editIndex: editIndex,
|
363
|
+
listType: listType,
|
364
|
+
isPanelClear: isPanelClear,
|
365
|
+
appliedFilters: filters,
|
366
|
+
recentFilters: recentFilters
|
367
|
+
});
|
368
|
+
} else if (this.props.allowAsSearch && !activeKey && event.currentTarget.value.trim() && event.keyCode === 13 && !this.state.isPanelClear) {
|
369
|
+
//Normal string entered
|
370
|
+
var _value = event.currentTarget.value.trim();
|
371
|
+
|
372
|
+
var _isValid = this.isValid(this.props.searchConfig.regx, _value);
|
373
|
+
|
374
|
+
if (_isValid) {
|
375
|
+
filters = this.updateFilter(this.props.searchConfig.name, _value);
|
376
|
+
recentFilters = this.updateRecentFilters(this.props.searchConfig, _value);
|
377
|
+
activeKey = null;
|
378
|
+
editIndex = null;
|
379
|
+
isOpen = false;
|
380
|
+
listType = 'filters';
|
381
|
+
isPanelClear = true;
|
382
|
+
this.clearInputPanel();
|
383
|
+
|
384
|
+
if (this.props.onFilterChange) {
|
385
|
+
this.props.onFilterChange({
|
386
|
+
appliedFilters: filters,
|
387
|
+
recentFilters: recentFilters
|
388
|
+
});
|
389
|
+
}
|
390
|
+
} else {// TODO: Show error for wrong input
|
391
|
+
}
|
392
|
+
|
393
|
+
this.setState({
|
394
|
+
isOpen: isOpen,
|
395
|
+
activeKey: activeKey,
|
396
|
+
editIndex: editIndex,
|
397
|
+
listType: listType,
|
398
|
+
isPanelClear: isPanelClear,
|
399
|
+
appliedFilters: filters,
|
400
|
+
recentFilters: recentFilters
|
401
|
+
});
|
402
|
+
} else {
|
403
|
+
this.onPanelFocus(event);
|
404
|
+
}
|
405
|
+
}
|
406
|
+
}, {
|
407
|
+
key: "onEditInputKeyUp",
|
408
|
+
value: function onEditInputKeyUp(event) {
|
409
|
+
if (event.keyCode === 13) {
|
410
|
+
//Enter pressed
|
411
|
+
this.saveEditedTextInput(event);
|
412
|
+
} else {
|
413
|
+
var appliedFilterTextEdit = this.state.appliedFilterTextEdit;
|
414
|
+
var options = Object.assign({}, appliedFilterTextEdit);
|
415
|
+
options['value'] = event.currentTarget.value;
|
416
|
+
this.setState({
|
417
|
+
appliedFilterTextEdit: options
|
418
|
+
});
|
419
|
+
}
|
420
|
+
}
|
421
|
+
}, {
|
422
|
+
key: "saveEditedTextInput",
|
423
|
+
value: function saveEditedTextInput(event) {
|
424
|
+
(0, _helper.stopPropagation)(event);
|
425
|
+
var _this$state3 = this.state,
|
426
|
+
isOpen = _this$state3.isOpen,
|
427
|
+
activeKey = _this$state3.activeKey,
|
428
|
+
editIndex = _this$state3.editIndex,
|
429
|
+
appliedFilterNode = _this$state3.appliedFilterNode,
|
430
|
+
appliedFilters = _this$state3.appliedFilters,
|
431
|
+
appliedFilterTextEdit = _this$state3.appliedFilterTextEdit,
|
432
|
+
isPanelClear = _this$state3.isPanelClear,
|
433
|
+
listType = _this$state3.listType,
|
434
|
+
recentFilters = _this$state3.recentFilters;
|
435
|
+
var filters = Object.assign([], appliedFilters);
|
436
|
+
var value = appliedFilterTextEdit.value.trim();
|
437
|
+
var previousValue = filters[editIndex].value;
|
438
|
+
|
439
|
+
if (previousValue === value) {
|
440
|
+
//value isn't changed
|
441
|
+
this.hideSuggestionList(event);
|
442
|
+
return false;
|
443
|
+
}
|
444
|
+
|
445
|
+
if (value) {
|
446
|
+
var isValid = this.isValid(activeKey.regx, value);
|
447
|
+
|
448
|
+
if (isValid) {
|
449
|
+
filters = this.updateFilter(activeKey.name, value);
|
450
|
+
recentFilters = this.updateRecentFilters(activeKey, value);
|
451
|
+
activeKey = null;
|
452
|
+
editIndex = null;
|
453
|
+
appliedFilterTextEdit = null;
|
454
|
+
appliedFilterNode = null;
|
455
|
+
isOpen = false;
|
456
|
+
listType = 'filters';
|
457
|
+
isPanelClear = true;
|
458
|
+
this.clearInputPanel();
|
459
|
+
|
460
|
+
if (this.props.onFilterChange) {
|
461
|
+
this.props.onFilterChange({
|
462
|
+
appliedFilters: filters,
|
463
|
+
recentFilters: recentFilters
|
464
|
+
});
|
465
|
+
}
|
466
|
+
} else {// TODO: Show error for wrong input
|
467
|
+
}
|
468
|
+
|
469
|
+
this.setState({
|
470
|
+
isOpen: isOpen,
|
471
|
+
activeKey: activeKey,
|
472
|
+
editIndex: editIndex,
|
473
|
+
listType: listType,
|
474
|
+
isPanelClear: isPanelClear,
|
475
|
+
appliedFilterTextEdit: appliedFilterTextEdit,
|
476
|
+
appliedFilterNode: appliedFilterNode,
|
477
|
+
appliedFilters: filters,
|
478
|
+
recentFilters: recentFilters
|
479
|
+
});
|
480
|
+
} else {
|
481
|
+
//DELETE filter
|
482
|
+
this.onPillboxClear(editIndex);
|
483
|
+
}
|
484
|
+
}
|
485
|
+
}, {
|
486
|
+
key: "onSuggestionListItemClick",
|
487
|
+
value: function onSuggestionListItemClick(event) {
|
488
|
+
var _this$state4 = this.state,
|
489
|
+
listType = _this$state4.listType,
|
490
|
+
activeKey = _this$state4.activeKey,
|
491
|
+
appliedFilters = _this$state4.appliedFilters,
|
492
|
+
isPanelClear = _this$state4.isPanelClear,
|
493
|
+
appliedFilterNode = _this$state4.appliedFilterNode,
|
494
|
+
appliedFilterOptionEdit = _this$state4.appliedFilterOptionEdit,
|
495
|
+
appliedFilterTextEdit = _this$state4.appliedFilterTextEdit,
|
496
|
+
recentFilters = _this$state4.recentFilters;
|
497
|
+
var isOpen = false;
|
498
|
+
var currentTarget = event.originalEvent.currentTarget;
|
499
|
+
var id = currentTarget.id,
|
500
|
+
name = currentTarget.name,
|
501
|
+
value = currentTarget.value,
|
502
|
+
dataset = currentTarget.dataset;
|
503
|
+
|
504
|
+
if (listType === 'filters') {
|
505
|
+
if (name && dataset && dataset.type === 'recent') {
|
506
|
+
//Recent filters
|
507
|
+
var filterKeyObject;
|
508
|
+
|
509
|
+
if (this.props.allowAsSearch && name === this.props.searchConfig.name) {
|
510
|
+
filterKeyObject = (0, _utils.find)(this.state.recentFilters, {
|
511
|
+
name: name,
|
512
|
+
value: value
|
513
|
+
});
|
514
|
+
} else {
|
515
|
+
filterKeyObject = (0, _utils.find)(this.state.recentFilters, {
|
516
|
+
name: name
|
517
|
+
});
|
518
|
+
}
|
519
|
+
|
520
|
+
appliedFilters = this.updateFilter(filterKeyObject.name, filterKeyObject.value);
|
521
|
+
isPanelClear = true;
|
522
|
+
this.clearInputPanel();
|
523
|
+
|
524
|
+
if (this.props.onFilterChange) {
|
525
|
+
this.props.onFilterChange({
|
526
|
+
appliedFilters: appliedFilters,
|
527
|
+
recentFilters: recentFilters
|
528
|
+
});
|
529
|
+
}
|
530
|
+
} else if (name && !value) {
|
531
|
+
//fields
|
532
|
+
var _filterKeyObject = (0, _utils.find)(this.props.config, {
|
533
|
+
name: name
|
534
|
+
});
|
535
|
+
|
536
|
+
var appliedFilter = (0, _utils.find)(this.state.appliedFilters, {
|
537
|
+
name: name
|
538
|
+
});
|
539
|
+
activeKey = _filterKeyObject;
|
540
|
+
|
541
|
+
if (appliedFilter && !activeKey.options) {
|
542
|
+
this.inputPanelNode.value = appliedFilter['value'];
|
543
|
+
} else {
|
544
|
+
isPanelClear = true;
|
545
|
+
this.clearInputPanel();
|
546
|
+
}
|
547
|
+
} else if (id && !name && !value) {
|
548
|
+
//Saved filters
|
549
|
+
appliedFilters = (0, _utils.find)(this.props.savedFilters, {
|
550
|
+
id: id
|
551
|
+
});
|
552
|
+
appliedFilters = appliedFilters ? Object.assign([], appliedFilters['filters']) : null;
|
553
|
+
isPanelClear = true;
|
554
|
+
this.clearInputPanel();
|
555
|
+
|
556
|
+
if (this.props.onFilterChange) {
|
557
|
+
this.props.onFilterChange({
|
558
|
+
appliedFilters: appliedFilters,
|
559
|
+
recentFilters: recentFilters
|
560
|
+
});
|
561
|
+
}
|
562
|
+
}
|
563
|
+
} else if (listType === 'filterValue') {
|
564
|
+
//field value
|
565
|
+
var activeId = event.activeId,
|
566
|
+
activeIds = event.activeIds;
|
567
|
+
|
568
|
+
var _value2 = activeId || activeIds;
|
569
|
+
|
570
|
+
var activeFilter = appliedFilterOptionEdit || activeKey;
|
571
|
+
appliedFilters = this.updateFilter(activeFilter.name, _value2);
|
572
|
+
recentFilters = this.updateRecentFilters(activeFilter, _value2);
|
573
|
+
appliedFilterOptionEdit = null;
|
574
|
+
appliedFilterTextEdit = null;
|
575
|
+
appliedFilterNode = null;
|
576
|
+
activeKey = null;
|
577
|
+
isPanelClear = true;
|
578
|
+
listType = 'filters';
|
579
|
+
this.clearInputPanel();
|
580
|
+
this.restoreFocus();
|
581
|
+
|
582
|
+
if (this.props.onFilterChange) {
|
583
|
+
this.props.onFilterChange({
|
584
|
+
appliedFilters: appliedFilters,
|
585
|
+
recentFilters: recentFilters
|
586
|
+
});
|
587
|
+
}
|
588
|
+
}
|
589
|
+
|
590
|
+
this.setState({
|
591
|
+
isOpen: isOpen,
|
592
|
+
activeKey: activeKey,
|
593
|
+
editIndex: null,
|
594
|
+
appliedFilterNode: appliedFilterNode,
|
595
|
+
appliedFilterOptionEdit: appliedFilterOptionEdit,
|
596
|
+
appliedFilterTextEdit: appliedFilterTextEdit,
|
597
|
+
isPanelClear: isPanelClear,
|
598
|
+
appliedFilters: appliedFilters,
|
599
|
+
recentFilters: recentFilters,
|
600
|
+
listType: listType
|
601
|
+
});
|
602
|
+
}
|
603
|
+
}, {
|
604
|
+
key: "restoreFocus",
|
605
|
+
value: function restoreFocus(event) {
|
606
|
+
var element = document.getElementById("".concat(this.props.id, "Input"));
|
607
|
+
setTimeout(function () {
|
608
|
+
element && element.focus();
|
609
|
+
}, 200);
|
610
|
+
}
|
611
|
+
}, {
|
612
|
+
key: "onPillboxClick",
|
613
|
+
value: function onPillboxClick(event) {
|
614
|
+
if (event.iconClick) {
|
615
|
+
this.onPillboxClear(event.props.index);
|
616
|
+
} else {
|
617
|
+
this.onPillboxEdit(event);
|
618
|
+
}
|
619
|
+
}
|
620
|
+
}, {
|
621
|
+
key: "onPillboxClear",
|
622
|
+
value: function onPillboxClear(index) {
|
623
|
+
var _this$state5 = this.state,
|
624
|
+
activeKey = _this$state5.activeKey,
|
625
|
+
appliedFilterTextEdit = _this$state5.appliedFilterTextEdit,
|
626
|
+
appliedFilters = _this$state5.appliedFilters,
|
627
|
+
recentFilters = _this$state5.recentFilters;
|
628
|
+
appliedFilters.splice(index, 1);
|
629
|
+
|
630
|
+
if ((0, _utils.isEmpty)(appliedFilters)) {
|
631
|
+
appliedFilters = null;
|
632
|
+
}
|
633
|
+
|
634
|
+
if (this.props.onFilterChange) {
|
635
|
+
this.props.onFilterChange({
|
636
|
+
appliedFilters: appliedFilters,
|
637
|
+
recentFilters: recentFilters
|
638
|
+
});
|
639
|
+
}
|
640
|
+
|
641
|
+
this.setState({
|
642
|
+
isOpen: false,
|
643
|
+
appliedFilters: appliedFilters,
|
644
|
+
appliedFilterOptionEdit: null,
|
645
|
+
appliedFilterTextEdit: null,
|
646
|
+
appliedFilterNode: null,
|
647
|
+
activeKey: appliedFilterTextEdit ? null : activeKey,
|
648
|
+
editIndex: null,
|
649
|
+
listType: 'filters'
|
650
|
+
});
|
651
|
+
}
|
652
|
+
}, {
|
653
|
+
key: "onPillboxEdit",
|
654
|
+
value: function onPillboxEdit(event) {
|
655
|
+
var _this$state6 = this.state,
|
656
|
+
listStyle = _this$state6.listStyle,
|
657
|
+
isOpen = _this$state6.isOpen,
|
658
|
+
activeKey = _this$state6.activeKey,
|
659
|
+
editIndex = _this$state6.editIndex,
|
660
|
+
list = _this$state6.list,
|
661
|
+
appliedFilterOptionEdit = _this$state6.appliedFilterOptionEdit,
|
662
|
+
appliedFilterTextEdit = _this$state6.appliedFilterTextEdit,
|
663
|
+
listType = _this$state6.listType,
|
664
|
+
appliedFilterNode = _this$state6.appliedFilterNode;
|
665
|
+
var filterKeyObject = (0, _utils.find)(this.props.config, {
|
666
|
+
name: event.props.name
|
667
|
+
});
|
668
|
+
isOpen = true;
|
669
|
+
listStyle = {
|
670
|
+
position: 'absolute',
|
671
|
+
left: "".concat(event.originalEvent.currentTarget.offsetLeft, "px"),
|
672
|
+
top: "".concat(event.originalEvent.currentTarget.offsetTop + event.originalEvent.currentTarget.clientHeight / 2, "px")
|
673
|
+
}; // Reset panel
|
674
|
+
|
675
|
+
list = [];
|
676
|
+
appliedFilterNode = event.originalEvent.currentTarget;
|
677
|
+
listType = 'filters';
|
678
|
+
appliedFilterOptionEdit = null;
|
679
|
+
appliedFilterTextEdit = null;
|
680
|
+
activeKey = null;
|
681
|
+
editIndex = null;
|
682
|
+
this.clearInputPanel();
|
683
|
+
|
684
|
+
if (filterKeyObject && filterKeyObject.options) {
|
685
|
+
//predefined options
|
686
|
+
list = filterKeyObject.options;
|
687
|
+
appliedFilterOptionEdit = filterKeyObject;
|
688
|
+
listType = 'filterValue';
|
689
|
+
} else if (filterKeyObject) {
|
690
|
+
// predefined text
|
691
|
+
editIndex = event.props.index;
|
692
|
+
appliedFilterTextEdit = Object.assign({}, filterKeyObject);
|
693
|
+
appliedFilterTextEdit['value'] = this.state.appliedFilters[event.props.index]['value'];
|
694
|
+
activeKey = filterKeyObject;
|
695
|
+
} else {
|
696
|
+
// string search
|
697
|
+
editIndex = event.props.index;
|
698
|
+
activeKey = this.props.searchConfig;
|
699
|
+
appliedFilterTextEdit = Object.assign({}, this.props.searchConfig);
|
700
|
+
appliedFilterTextEdit['value'] = this.state.appliedFilters[event.props.index]['value'];
|
701
|
+
}
|
702
|
+
|
703
|
+
this.setState({
|
704
|
+
isOpen: isOpen,
|
705
|
+
listStyle: listStyle,
|
706
|
+
appliedFilterOptionEdit: appliedFilterOptionEdit,
|
707
|
+
appliedFilterTextEdit: appliedFilterTextEdit,
|
708
|
+
appliedFilterNode: appliedFilterNode,
|
709
|
+
listType: listType,
|
710
|
+
editIndex: editIndex,
|
711
|
+
list: list,
|
712
|
+
activeKey: activeKey
|
713
|
+
});
|
714
|
+
}
|
715
|
+
}, {
|
716
|
+
key: "onToggleSuggestionList",
|
717
|
+
value: function onToggleSuggestionList(event) {
|
718
|
+
if (event.originalEvent && (event.originalEvent.target === this.inputPanelNode && event.originalEvent.keyCode !== 9 || this.state.appliedFilterNode && this.state.appliedFilterNode.contains(event.originalEvent.target))) {
|
719
|
+
return false;
|
720
|
+
}
|
721
|
+
|
722
|
+
if (!event.isOpen) {
|
723
|
+
this.hideSuggestionList();
|
724
|
+
}
|
725
|
+
}
|
726
|
+
}, {
|
727
|
+
key: "updateFilter",
|
728
|
+
value: function updateFilter(feKey, feValue) {
|
729
|
+
var _this3 = this;
|
730
|
+
|
731
|
+
var _this$state7 = this.state,
|
732
|
+
appliedFilters = _this$state7.appliedFilters,
|
733
|
+
editIndex = _this$state7.editIndex;
|
734
|
+
var filters = Object.assign([], appliedFilters);
|
735
|
+
|
736
|
+
if (editIndex) {
|
737
|
+
//update filter
|
738
|
+
var index = (0, _utils.findIndex)(appliedFilters, {
|
739
|
+
name: feKey,
|
740
|
+
value: feValue
|
741
|
+
});
|
742
|
+
|
743
|
+
if (index > -1 && index !== (0, _toNumber.default)(editIndex)) {
|
744
|
+
filters.splice(index, 1);
|
745
|
+
}
|
746
|
+
|
747
|
+
filters[editIndex] = {
|
748
|
+
name: feKey,
|
749
|
+
value: feValue
|
750
|
+
};
|
751
|
+
} else if (feKey === this.props.searchConfig.name) {
|
752
|
+
var _index = (0, _utils.findIndex)(appliedFilters, function (item) {
|
753
|
+
if (item.name === feKey) {
|
754
|
+
return _this3.props.searchConfig.isCaseSensitive ? feValue === item.value : feValue.toLocaleLowerCase() === item.value.toLocaleLowerCase();
|
755
|
+
}
|
756
|
+
|
757
|
+
return false;
|
758
|
+
});
|
759
|
+
|
760
|
+
if (_index > -1) {
|
761
|
+
filters.splice(_index, 1);
|
762
|
+
}
|
763
|
+
|
764
|
+
filters.push({
|
765
|
+
name: feKey,
|
766
|
+
value: feValue
|
767
|
+
});
|
768
|
+
} else {
|
769
|
+
var _index2 = (0, _utils.findIndex)(appliedFilters, {
|
770
|
+
name: feKey
|
771
|
+
});
|
772
|
+
|
773
|
+
if (feValue !== null && feValue !== undefined) {
|
774
|
+
if (_index2 > -1) {
|
775
|
+
filters[_index2] = {
|
776
|
+
name: feKey,
|
777
|
+
value: feValue
|
778
|
+
};
|
779
|
+
} else {
|
780
|
+
filters.push({
|
781
|
+
name: feKey,
|
782
|
+
value: feValue
|
783
|
+
});
|
784
|
+
}
|
785
|
+
} else {
|
786
|
+
filters.splice(_index2, 1);
|
787
|
+
}
|
788
|
+
}
|
789
|
+
|
790
|
+
return filters;
|
791
|
+
}
|
792
|
+
}, {
|
793
|
+
key: "updateRecentFilters",
|
794
|
+
value: function updateRecentFilters(activeKey, feValue) {
|
795
|
+
if (!this.props.withRecent) {
|
796
|
+
return null;
|
797
|
+
}
|
798
|
+
|
799
|
+
if (feValue === null) {
|
800
|
+
return this.state.recentFilters;
|
801
|
+
}
|
802
|
+
|
803
|
+
var _this$state8 = this.state,
|
804
|
+
appliedFilters = _this$state8.appliedFilters,
|
805
|
+
recentFilters = _this$state8.recentFilters,
|
806
|
+
editIndex = _this$state8.editIndex;
|
807
|
+
var filters = Object.assign([], recentFilters);
|
808
|
+
var label = this.props.searchConfig && activeKey.name === this.props.searchConfig.name ? "".concat(this.getFeValue(activeKey, feValue)) : "".concat(activeKey.label || activeKey.name, ": ").concat(this.getFeValue(activeKey, feValue));
|
809
|
+
var filter = {
|
810
|
+
name: activeKey.name,
|
811
|
+
value: feValue,
|
812
|
+
label: label,
|
813
|
+
'data-type': 'recent'
|
814
|
+
};
|
815
|
+
var index = -1;
|
816
|
+
|
817
|
+
if (editIndex) {
|
818
|
+
index = (0, _utils.findIndex)(filters, filter);
|
819
|
+
|
820
|
+
if (index < 0) {
|
821
|
+
index = (0, _utils.findIndex)(filters, appliedFilters[editIndex]);
|
822
|
+
}
|
823
|
+
} else if (this.props.searchConfig && filter.name === this.props.searchConfig.name) {
|
824
|
+
index = (0, _utils.findIndex)(filters, filter);
|
825
|
+
} else {
|
826
|
+
index = (0, _utils.findIndex)(filters, {
|
827
|
+
name: filter.name
|
828
|
+
});
|
829
|
+
}
|
830
|
+
|
831
|
+
if (index > -1) {
|
832
|
+
filters.splice(index, 1);
|
833
|
+
}
|
834
|
+
|
835
|
+
filters.push(filter);
|
836
|
+
|
837
|
+
if (filters.length > 5) {
|
838
|
+
filters.splice(0, 1);
|
839
|
+
}
|
840
|
+
|
841
|
+
return filters;
|
842
|
+
}
|
843
|
+
}, {
|
844
|
+
key: "filterSuggestionList",
|
845
|
+
value: function filterSuggestionList(subStr, list) {
|
846
|
+
var config = {
|
847
|
+
queryAt: 'label'
|
848
|
+
};
|
849
|
+
|
850
|
+
if (this.state.listType === 'filters') {
|
851
|
+
config['isMultiLevel'] = true;
|
852
|
+
config['multiLevelKey'] = 'list';
|
853
|
+
}
|
854
|
+
|
855
|
+
var filteredList = _feFilter.default.filter(subStr, list, config);
|
856
|
+
|
857
|
+
if (filteredList.length === 0 && !(this.props.allowAsSearch && this.state.listType !== 'filterValue')) {
|
858
|
+
filteredList = [{
|
859
|
+
label: 'No results found',
|
860
|
+
disabled: true
|
861
|
+
}];
|
862
|
+
}
|
863
|
+
|
864
|
+
return filteredList;
|
865
|
+
}
|
866
|
+
}, {
|
867
|
+
key: "getFeValue",
|
868
|
+
value: function getFeValue(filter, value) {
|
869
|
+
var feValue;
|
870
|
+
|
871
|
+
if (Array.isArray(value)) {
|
872
|
+
var valueLabels = [];
|
873
|
+
value.forEach(function (val) {
|
874
|
+
valueLabels.push(filter.options.find(function (opt) {
|
875
|
+
return opt.value === val;
|
876
|
+
})['label']);
|
877
|
+
});
|
878
|
+
feValue = valueLabels.join(',');
|
879
|
+
} else if (filter.options && filter.options.length) {
|
880
|
+
feValue = filter.options.find(function (opt) {
|
881
|
+
return opt.value === value;
|
882
|
+
})['label'];
|
883
|
+
} else {
|
884
|
+
feValue = value;
|
885
|
+
}
|
886
|
+
|
887
|
+
return feValue;
|
888
|
+
}
|
889
|
+
}, {
|
890
|
+
key: "isValid",
|
891
|
+
value: function isValid(regExp, value) {
|
892
|
+
var inputs = value.split('|');
|
893
|
+
|
894
|
+
if (regExp) {
|
895
|
+
var matched = true;
|
896
|
+
|
897
|
+
for (var i = 0; i < inputs.length; i++) {
|
898
|
+
var regx = new RegExp(regExp, 'g');
|
899
|
+
matched = regx.test(inputs[i]);
|
900
|
+
|
901
|
+
if (!matched) {
|
902
|
+
break;
|
903
|
+
}
|
904
|
+
}
|
905
|
+
|
906
|
+
return matched;
|
907
|
+
} else {
|
908
|
+
return true;
|
909
|
+
}
|
910
|
+
}
|
911
|
+
}, {
|
912
|
+
key: "onClearAll",
|
913
|
+
value: function onClearAll(event) {
|
914
|
+
var recentFilters = this.state.recentFilters;
|
915
|
+
this.clearInputPanel();
|
916
|
+
this.setState({
|
917
|
+
activeKey: null,
|
918
|
+
appliedFilters: null,
|
919
|
+
isPanelClear: true,
|
920
|
+
editIndex: null,
|
921
|
+
appliedFilterOptionEdit: null,
|
922
|
+
appliedFilterTextEdit: null,
|
923
|
+
listType: 'filters'
|
924
|
+
});
|
925
|
+
|
926
|
+
if (this.props.onFilterChange) {
|
927
|
+
this.props.onFilterChange({
|
928
|
+
appliedFilters: null,
|
929
|
+
recentFilters: recentFilters
|
930
|
+
});
|
931
|
+
}
|
932
|
+
}
|
933
|
+
}, {
|
934
|
+
key: "clearInputPanel",
|
935
|
+
value: function clearInputPanel() {
|
936
|
+
this.inputPanelNode.value = '';
|
937
|
+
}
|
938
|
+
}, {
|
939
|
+
key: "hideSuggestionList",
|
940
|
+
value: function hideSuggestionList() {
|
941
|
+
this.setState({
|
942
|
+
isOpen: false,
|
943
|
+
editIndex: null,
|
944
|
+
activeKey: null,
|
945
|
+
appliedFilterOptionEdit: null,
|
946
|
+
appliedFilterTextEdit: null,
|
947
|
+
appliedFilterNode: null,
|
948
|
+
listType: 'filters'
|
949
|
+
});
|
950
|
+
}
|
951
|
+
}, {
|
952
|
+
key: "getSuggestionBox",
|
953
|
+
value: function getSuggestionBox() {
|
954
|
+
var _this4 = this;
|
955
|
+
|
956
|
+
var attributes = {};
|
957
|
+
var activeFilter = this.state.appliedFilterOptionEdit || this.state.activeKey;
|
958
|
+
|
959
|
+
if (this.state.listType === 'filters') {
|
960
|
+
attributes = {
|
961
|
+
feStyle: 'sectioned',
|
962
|
+
onIconRighClick: this.props.onFilterRemove
|
963
|
+
};
|
964
|
+
}
|
965
|
+
|
966
|
+
if (this.state.listType === 'filterValue') {
|
967
|
+
attributes = {
|
968
|
+
feType: activeFilter.type === 'checkbox' ? 'multi-select' : 'single-select',
|
969
|
+
idAttribute: 'value'
|
970
|
+
};
|
971
|
+
var value;
|
972
|
+
var filter = (0, _utils.find)(this.state.appliedFilters, {
|
973
|
+
name: activeFilter.name
|
974
|
+
});
|
975
|
+
|
976
|
+
if (this.state.appliedFilters && activeFilter && filter) {
|
977
|
+
value = filter.value;
|
978
|
+
}
|
979
|
+
|
980
|
+
if (value && activeFilter.type === 'checkbox') {
|
981
|
+
attributes['activeIds'] = Object.assign([], value);
|
982
|
+
} else if (value && !(activeFilter.type === 'checkbox')) {
|
983
|
+
attributes['activeId'] = value;
|
984
|
+
}
|
985
|
+
}
|
986
|
+
|
987
|
+
return _react.default.createElement("div", {
|
988
|
+
style: this.state.listStyle,
|
989
|
+
ref: function ref(node) {
|
990
|
+
return _this4.listNode = node;
|
991
|
+
}
|
992
|
+
}, _react.default.createElement(_core.FeDropdown, _extends({}, attributes, {
|
993
|
+
referId: "".concat(this.props.id, "Input"),
|
994
|
+
isOpen: this.state.isOpen,
|
995
|
+
list: this.state.list,
|
996
|
+
textHighlight: this.state.textHighlight,
|
997
|
+
onToggleDropdown: this.onToggleSuggestionList,
|
998
|
+
onItemClick: this.onSuggestionListItemClick
|
999
|
+
}), this.state.appliedFilterTextEdit ? _react.default.createElement("div", {
|
1000
|
+
className: "padding-left-16 padding-right-16 padding-top-8",
|
1001
|
+
style: {
|
1002
|
+
width: '214px'
|
1003
|
+
}
|
1004
|
+
}, _react.default.createElement(_core.FeSelfContainedInput, {
|
1005
|
+
id: "".concat(this.props.id, "-editInput"),
|
1006
|
+
feBackground: "light",
|
1007
|
+
label: this.state.appliedFilterTextEdit.label || this.state.appliedFilterTextEdit.name,
|
1008
|
+
value: this.state.appliedFilterTextEdit.value,
|
1009
|
+
onChange: this.onEditInputKeyUp,
|
1010
|
+
onKeyUp: this.onEditInputKeyUp
|
1011
|
+
}), _react.default.createElement("div", {
|
1012
|
+
className: "pull-right margin-top-8"
|
1013
|
+
}, _react.default.createElement(_core.FeButton, {
|
1014
|
+
feBackground: "light",
|
1015
|
+
feStyle: "link-secondary",
|
1016
|
+
size: "xs",
|
1017
|
+
onClick: this.hideSuggestionList
|
1018
|
+
}, "Cancel"), _react.default.createElement(_core.FeButton, {
|
1019
|
+
className: "margin-left-16",
|
1020
|
+
feStyle: "link",
|
1021
|
+
size: "xs",
|
1022
|
+
onClick: this.saveEditedTextInput
|
1023
|
+
}, "Save"))) : null));
|
1024
|
+
}
|
1025
|
+
}, {
|
1026
|
+
key: "getInputPanel",
|
1027
|
+
value: function getInputPanel() {
|
1028
|
+
var _this5 = this;
|
1029
|
+
|
1030
|
+
var placeholder = !this.state.activeKey && (0, _utils.isEmpty)(this.state.appliedFilters) ? this.props.placeholder : null;
|
1031
|
+
return _react.default.createElement("input", {
|
1032
|
+
ref: function ref(node) {
|
1033
|
+
return _this5.inputPanelNode = node;
|
1034
|
+
},
|
1035
|
+
id: "".concat(this.props.id, "Input"),
|
1036
|
+
placeholder: placeholder,
|
1037
|
+
type: "text",
|
1038
|
+
"aria-label": "filter_panel",
|
1039
|
+
autoComplete: "off",
|
1040
|
+
className: "fe-filters__input",
|
1041
|
+
onClick: this.onPanelFocus,
|
1042
|
+
onFocus: this.onPanelFocus,
|
1043
|
+
onKeyUp: this.onPanelKeyUp
|
1044
|
+
});
|
1045
|
+
}
|
1046
|
+
}, {
|
1047
|
+
key: "getFilters",
|
1048
|
+
value: function getFilters() {
|
1049
|
+
var _this6 = this;
|
1050
|
+
|
1051
|
+
if (!this.state.appliedFilters) {
|
1052
|
+
return null;
|
1053
|
+
}
|
1054
|
+
|
1055
|
+
return _react.default.createElement(_react.Fragment, null, this.state.appliedFilters.map(function (item, index) {
|
1056
|
+
var value = item['value'];
|
1057
|
+
var filter = (0, _utils.find)(_this6.props.config, {
|
1058
|
+
name: item['name']
|
1059
|
+
});
|
1060
|
+
var feValue;
|
1061
|
+
|
1062
|
+
if (filter) {
|
1063
|
+
feValue = _this6.getFeValue(filter, value);
|
1064
|
+
return _react.default.createElement(_core.FePillBox, {
|
1065
|
+
key: index,
|
1066
|
+
index: "".concat(index),
|
1067
|
+
name: filter.name,
|
1068
|
+
feKey: "".concat(filter.label),
|
1069
|
+
feValue: "".concat(feValue),
|
1070
|
+
feType: "clear",
|
1071
|
+
onClick: _this6.onPillboxClick
|
1072
|
+
});
|
1073
|
+
} else if (_this6.props.searchConfig && item.name === _this6.props.searchConfig.name) {
|
1074
|
+
return _react.default.createElement(_core.FePillBox, {
|
1075
|
+
key: index,
|
1076
|
+
index: "".concat(index),
|
1077
|
+
name: item.name,
|
1078
|
+
label: "".concat(value),
|
1079
|
+
feType: "clear",
|
1080
|
+
onClick: _this6.onPillboxClick
|
1081
|
+
});
|
1082
|
+
} else {
|
1083
|
+
return _react.default.createElement(_core.FePillBox, {
|
1084
|
+
key: index,
|
1085
|
+
index: "".concat(index),
|
1086
|
+
name: item.name,
|
1087
|
+
feKey: item.name,
|
1088
|
+
feValue: "".concat(item.value),
|
1089
|
+
feType: "clear",
|
1090
|
+
onClick: _this6.onPillboxClick
|
1091
|
+
});
|
1092
|
+
}
|
1093
|
+
}));
|
1094
|
+
}
|
1095
|
+
}, {
|
1096
|
+
key: "getActiveKey",
|
1097
|
+
value: function getActiveKey() {
|
1098
|
+
return _react.default.createElement("span", null, "".concat(this.state.activeKey.label || this.state.activeKey.name, ": "));
|
1099
|
+
}
|
1100
|
+
}, {
|
1101
|
+
key: "render",
|
1102
|
+
value: function render() {
|
1103
|
+
/** Minimum condition required to render*/
|
1104
|
+
|
1105
|
+
/** Rendering of component */
|
1106
|
+
var className = (0, _classnames.default)('fe-filters', this.props.className);
|
1107
|
+
var suggestionBox = this.getSuggestionBox();
|
1108
|
+
var inputPanel = this.getInputPanel();
|
1109
|
+
var filters = this.getFilters();
|
1110
|
+
var activeKey = this.state.activeKey && !this.state.appliedFilterTextEdit && this.getActiveKey();
|
1111
|
+
var isClearAllDisabled = this.state.appliedFilters === null && this.state.activeKey === null;
|
1112
|
+
return _react.default.createElement("div", {
|
1113
|
+
className: "fe-filters-container"
|
1114
|
+
}, _react.default.createElement("div", {
|
1115
|
+
className: className,
|
1116
|
+
id: this.props.id
|
1117
|
+
}, _react.default.createElement("div", {
|
1118
|
+
className: "fe-filters__icon"
|
1119
|
+
}, _react.default.createElement(_core.FeIcon, {
|
1120
|
+
family: "solid",
|
1121
|
+
icon: "filter"
|
1122
|
+
})), _react.default.createElement("div", {
|
1123
|
+
className: "fe-filters__box"
|
1124
|
+
}, filters, activeKey, inputPanel), this.props.withClearAll || this.props.optionalComponent ? _react.default.createElement("div", {
|
1125
|
+
className: "fe-filters__btns"
|
1126
|
+
}, this.props.withClearAll ? _react.default.createElement(_core.FeButton, {
|
1127
|
+
feStyle: "link-danger",
|
1128
|
+
onClick: this.onClearAll,
|
1129
|
+
disabled: isClearAllDisabled
|
1130
|
+
}, "CLEAR ALL") : null, this.props.optionalComponent) : null), suggestionBox);
|
1131
|
+
}
|
1132
|
+
}], [{
|
1133
|
+
key: "getDerivedStateFromProps",
|
1134
|
+
value: function getDerivedStateFromProps(props, state) {
|
1135
|
+
if (props.appliedFilters !== null) {
|
1136
|
+
return {
|
1137
|
+
appliedFilters: props.appliedFilters,
|
1138
|
+
recentFilters: props.recentFilters
|
1139
|
+
};
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
return null;
|
1143
|
+
}
|
1144
|
+
}]);
|
1145
|
+
|
1146
|
+
return FeFilter;
|
1147
|
+
}(_react.Component);
|
1148
|
+
|
1149
|
+
FeFilter.defaultProps = {
|
1150
|
+
id: null,
|
1151
|
+
placeholder: null,
|
1152
|
+
config: null,
|
1153
|
+
withRecent: false,
|
1154
|
+
withClearAll: true,
|
1155
|
+
allowAsSearch: true,
|
1156
|
+
searchConfig: {
|
1157
|
+
label: 'Key word',
|
1158
|
+
name: 'key_word'
|
1159
|
+
},
|
1160
|
+
iconRemove: 'fas fa-trash',
|
1161
|
+
labelRecent: 'Recent Filters',
|
1162
|
+
labelSaved: 'Saved Filter Sets',
|
1163
|
+
labelFields: 'All Fields',
|
1164
|
+
savedFilters: null,
|
1165
|
+
appliedFilters: null,
|
1166
|
+
recentFilters: null,
|
1167
|
+
onFilterChange: null,
|
1168
|
+
onFilterRemove: null,
|
1169
|
+
optionalComponent: null
|
1170
|
+
};
|
1171
|
+
FeFilter.propTypes = {
|
1172
|
+
/** Provide id for filter component*/
|
1173
|
+
id: _propTypes.default.string.isRequired,
|
1174
|
+
|
1175
|
+
/** Provide placeholder for filter input*/
|
1176
|
+
placeholder: _propTypes.default.string,
|
1177
|
+
|
1178
|
+
/** Provide all filter fields
|
1179
|
+
[{
|
1180
|
+
name: 'severity',
|
1181
|
+
label: 'Severity',
|
1182
|
+
options: [{
|
1183
|
+
label: 'None',
|
1184
|
+
value: 'none'
|
1185
|
+
},{
|
1186
|
+
label: 'Minor',
|
1187
|
+
value: '0,2'
|
1188
|
+
},{
|
1189
|
+
label: 'Major',
|
1190
|
+
value: '3,6'
|
1191
|
+
},
|
1192
|
+
{
|
1193
|
+
label: 'Critical',
|
1194
|
+
value: '7,10'
|
1195
|
+
}],
|
1196
|
+
type: 'checkbox'
|
1197
|
+
},
|
1198
|
+
{
|
1199
|
+
name: 'risk',
|
1200
|
+
label: 'Risk',
|
1201
|
+
options: [{
|
1202
|
+
label: 'High',
|
1203
|
+
value: 'high'
|
1204
|
+
},{
|
1205
|
+
label: 'Low',
|
1206
|
+
value: 'low'
|
1207
|
+
}]
|
1208
|
+
},
|
1209
|
+
{
|
1210
|
+
label: 'Sender',
|
1211
|
+
name: 'sender'
|
1212
|
+
}]
|
1213
|
+
*/
|
1214
|
+
config: _propTypes.default.array,
|
1215
|
+
|
1216
|
+
/** Set true/false to get recently applied filters in suggestion list*/
|
1217
|
+
withRecent: _propTypes.default.bool,
|
1218
|
+
|
1219
|
+
/** Set true/false to get 'Clear All' action*/
|
1220
|
+
withClearAll: _propTypes.default.bool,
|
1221
|
+
|
1222
|
+
/** Set true/false to allow simple string*/
|
1223
|
+
allowAsSearch: _propTypes.default.bool,
|
1224
|
+
|
1225
|
+
/** Provide config for string search
|
1226
|
+
searchConfig: {
|
1227
|
+
label: 'Key word',
|
1228
|
+
name: 'key_word'
|
1229
|
+
},
|
1230
|
+
*/
|
1231
|
+
searchConfig: _propTypes.default.object,
|
1232
|
+
|
1233
|
+
/** Provide icon class */
|
1234
|
+
iconFilter: _propTypes.default.string,
|
1235
|
+
|
1236
|
+
/** Provide icon class */
|
1237
|
+
iconRemove: _propTypes.default.string,
|
1238
|
+
|
1239
|
+
/** Provide label for Recent section*/
|
1240
|
+
labelRecent: _propTypes.default.string,
|
1241
|
+
|
1242
|
+
/** Provide label for saved section*/
|
1243
|
+
labelSaved: _propTypes.default.string,
|
1244
|
+
|
1245
|
+
/** Provide label for fields section*/
|
1246
|
+
labelFields: _propTypes.default.string,
|
1247
|
+
|
1248
|
+
/** Provide Saved filter sets
|
1249
|
+
[
|
1250
|
+
{
|
1251
|
+
id: 'myFilter1',
|
1252
|
+
label: 'my filter 1',
|
1253
|
+
filters: [
|
1254
|
+
{
|
1255
|
+
'name': 'file_type',
|
1256
|
+
'value': 'zip'
|
1257
|
+
},
|
1258
|
+
{
|
1259
|
+
'name': 'sender',
|
1260
|
+
'value': 'bob@gmail.com'
|
1261
|
+
}
|
1262
|
+
],
|
1263
|
+
canRemove: true
|
1264
|
+
}
|
1265
|
+
]
|
1266
|
+
*/
|
1267
|
+
savedFilters: _propTypes.default.array,
|
1268
|
+
|
1269
|
+
/** Provide currently active filters
|
1270
|
+
[
|
1271
|
+
{
|
1272
|
+
'name': 'file_type',
|
1273
|
+
'value': 'zip'
|
1274
|
+
},
|
1275
|
+
{
|
1276
|
+
'name': 'sender',
|
1277
|
+
'value': 'bob@gmail.com'
|
1278
|
+
}
|
1279
|
+
]
|
1280
|
+
*/
|
1281
|
+
appliedFilters: _propTypes.default.array,
|
1282
|
+
|
1283
|
+
/** Provide recently applied filters
|
1284
|
+
[
|
1285
|
+
{
|
1286
|
+
'name': 'file_type',
|
1287
|
+
'value': 'zip',
|
1288
|
+
'label': 'File type: zip',
|
1289
|
+
'data-type': 'recent'
|
1290
|
+
},
|
1291
|
+
{
|
1292
|
+
'name': 'sender',
|
1293
|
+
'value': 'bob@gmail.com',
|
1294
|
+
'label': 'Sender: bob@gmail.com',
|
1295
|
+
'data-type': 'recent'
|
1296
|
+
}
|
1297
|
+
]
|
1298
|
+
*/
|
1299
|
+
recentFilters: _propTypes.default.array,
|
1300
|
+
|
1301
|
+
/** Provide handler for active-filter change*/
|
1302
|
+
onFilterChange: _propTypes.default.func,
|
1303
|
+
|
1304
|
+
/** Provide handler for removeing saved filter*/
|
1305
|
+
onFilterRemove: _propTypes.default.func,
|
1306
|
+
|
1307
|
+
/** Provide optional 'FeButton' or 'FeDropdown' component*/
|
1308
|
+
optionalComponent: _propTypes.default.element
|
1309
|
+
};
|
1310
|
+
FeFilter.displayName = 'FeFilter';
|
1311
|
+
var _default = FeFilter;
|
1312
|
+
exports.default = _default;
|