Skip to content

Commit 828327a

Browse files
author
Sergei Aksiutin
committed
[NEP-12629] Fix filters default value.
1 parent df27902 commit 828327a

File tree

7 files changed

+94
-49
lines changed

7 files changed

+94
-49
lines changed

dist/react-filterbar.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18224,7 +18224,8 @@ var FilterGroup = /*#__PURE__*/function (_React$Component) {
1822418224
style: {
1822518225
marginTop: 'auto',
1822618226
marginBottom: 'auto',
18227-
padding: '10px'
18227+
padding: '10px',
18228+
minWidth: '150px'
1822818229
},
1822918230
key: Math.random()
1823018231
}, /*#__PURE__*/React.createElement(_FilterInput.FilterInput, {
@@ -19385,10 +19386,10 @@ var RelativeDateInput = /*#__PURE__*/function (_React$Component) {
1938519386
var newValue = {
1938619387
value: selectedOption.val()
1938719388
};
19388-
this.state = {
19389+
this.setState({
1938919390
value: newValue
19390-
};
19391-
this.updateFilter(this.state.value);
19391+
});
19392+
this.updateFilter(newValue);
1939219393
}
1939319394
}, {
1939419395
key: "onDatePickerChange",
@@ -19455,6 +19456,7 @@ var RelativeDateInput = /*#__PURE__*/function (_React$Component) {
1945519456
this.setState({
1945619457
value: newValue
1945719458
});
19459+
this.updateFilter(this.state.value);
1945819460
}
1945919461
}, {
1946019462
key: "onBlur",
@@ -22077,6 +22079,12 @@ var _SearchClient = require("../clients/SearchClient");
2207722079

2207822080
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2207922081

22082+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
22083+
22084+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
22085+
22086+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22087+
2208022088
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
2208122089

2208222090
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -22105,7 +22113,7 @@ var FilterBarStore = /*#__PURE__*/function () {
2210522113
this.exportResultsUrl = configuration.exportResultsUrl;
2210622114
this.exportPageLimit = configuration.exportPageLimit;
2210722115
this.exportPageLimitExceededMessage = configuration.exportPageLimitExceededMessage;
22108-
this.filters = configuration.filters;
22116+
this.filters = configuration.filters || {};
2210922117
this.activeFilters = configuration.activeFilters || [];
2211022118
this.quickFilters = configuration.quickFilters || {};
2211122119

@@ -22480,13 +22488,13 @@ var FilterBarStore = /*#__PURE__*/function () {
2248022488
}, {
2248122489
key: "addGroupFilter",
2248222490
value: function addGroupFilter(filterUid, groupKey, value) {
22483-
var filter = this.filters[filterUid];
22491+
var filterTemplate = this.filters[filterUid];
22492+
22493+
var filter = _objectSpread({}, filterTemplate);
22494+
2248422495
filter.filterUid = filterUid;
2248522496
filter.uid = filterUid;
22486-
22487-
if (value) {
22488-
filter.value = value;
22489-
}
22497+
filter.value = value;
2249022498

2249122499
if (groupKey == undefined) {
2249222500
this.activeFilters.push([filter]);

dist/react-filterbar.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/react-components-structure.md

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
React Components Structure
2-
--------------------------
1+
### React Components Structure
32

43
FilterBar
54
-> FilterList
@@ -8,22 +7,52 @@ FilterBar
87
-> ClearFiltersButton
98
-> SaveFiltersButton
109
-> SavedSearchesList
11-
-> ConfigurationButton *
12-
-> ExportResultsButton *
10+
-> ConfigurationButton
11+
-> ExportResultsButton
1312
-> BatchActionsList
1413
-> FilterDisplay
1514
-> FilterGroup
16-
-> FilterItem
17-
-> FilterButton
18-
-> FilterButton
15+
-> FilterInput
16+
-> FilterButton ("ADD" button)
17+
-> FilterListOption
18+
-> FilterButton ("ADD FILTER" or "OR" button)
19+
-> FilterListOption
1920

2021

21-
{} - available filters
22-
[] - default filters
23-
[
24-
[filter1] -> when adding new add new filter1
22+
23+
### Filters Structure
24+
Class _FilterBarStore_ has the following varables:
25+
```(javascript)
26+
activeFilters = [] // as array of active groups with filters
27+
filters = {} // as initial hash with available filters
28+
```
29+
30+
#### Examples:
31+
##### Case 1
32+
Filter1
33+
34+
```(javascript)
35+
activeFilters = [
36+
[Filter1]
37+
]
38+
39+
```
40+
##### Case 2
41+
Filter1 and Filter2
42+
43+
```(javascript)
44+
activeFilters = [
45+
[Filter1, Filter2]
2546
]
2647
27-
[
28-
[filter1, filter2] -> when adding "ADD" button and add new filter2
48+
```
49+
##### Case 3
50+
(Filter1 and Filter 2) or Filter2
51+
52+
```(javascript)
53+
activeFilters = [
54+
[Filter1, Filter2],
55+
[Filter3]
2956
]
57+
58+
```

example/public/js/react-filterbar.js

Lines changed: 19 additions & 11 deletions
Large diffs are not rendered by default.

src/components/FilterBar/FilterDisplay/FilterGroup.react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class FilterGroup extends React.Component {
3939
filters.push(
4040
(
4141
<div
42-
style={ { marginTop: 'auto', marginBottom: 'auto', padding: '10px'} }
42+
style={ { marginTop: 'auto', marginBottom: 'auto', padding: '10px', minWidth: '150px'} }
4343
key={ Math.random() }
4444
>
4545
<FilterInput

src/components/FilterBar/FilterDisplay/Inputs/RelativeDateInput.react.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export class RelativeDateInput extends React.Component {
2020
}
2121

2222
onRelativeChange(event) {
23-
var selectedOption = $(event.target.childNodes[event.target.selectedIndex]);
24-
var newValue = { value: selectedOption.val() };
25-
this.state = { value: newValue }
26-
this.updateFilter(this.state.value);
23+
var selectedOption = $(event.target.childNodes[event.target.selectedIndex])
24+
var newValue = { value: selectedOption.val() }
25+
this.setState({ value: newValue })
26+
this.updateFilter(newValue)
2727
}
2828

2929
onDatePickerChange(event) {
@@ -80,6 +80,7 @@ export class RelativeDateInput extends React.Component {
8080
var newValue = this.state.value
8181
newValue[input] = event.target.value
8282
this.setState({ value: newValue })
83+
this.updateFilter(this.state.value)
8384
}
8485

8586
onBlur() {

src/stores/FilterBarStore.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class FilterBarStore {
1616
this.exportResultsUrl = configuration.exportResultsUrl;
1717
this.exportPageLimit = configuration.exportPageLimit;
1818
this.exportPageLimitExceededMessage = configuration.exportPageLimitExceededMessage;
19-
this.filters = configuration.filters;
19+
this.filters = configuration.filters || {};
2020
this.activeFilters = configuration.activeFilters || [];
2121
this.quickFilters = configuration.quickFilters || {};
2222

@@ -212,13 +212,12 @@ export class FilterBarStore {
212212
}
213213

214214
addGroupFilter(filterUid, groupKey, value) {
215-
const filter = this.filters[filterUid];
215+
const filterTemplate = this.filters[filterUid];
216+
const filter = { ...filterTemplate };
217+
216218
filter.filterUid = filterUid;
217219
filter.uid = filterUid;
218-
219-
if (value) {
220-
filter.value = value
221-
}
220+
filter.value = value;
222221

223222
if (groupKey == undefined) {
224223
this.activeFilters.push([filter])

0 commit comments

Comments
 (0)