@bento-core/facet-filter 1.0.1-ccdihub.28 → 1.0.1-ccdihub.29

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.
@@ -19,6 +19,25 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
19
19
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
20
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
21
21
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
22
+ const searchItems = (items, searchText) => {
23
+ let matchedItems = [];
24
+ const keyList = searchText.toUpperCase().split(',').filter(item => item.trim() !== '');
25
+ if (keyList.length === 0) {
26
+ matchedItems = items;
27
+ } else {
28
+ for (let i = 0; i < items.length; i += 1) {
29
+ const item = items[i];
30
+ for (let j = 0; j < keyList.length; j += 1) {
31
+ const key = keyList[j].trim();
32
+ if (key === '' || item.name.toUpperCase().includes(key)) {
33
+ matchedItems.push(item);
34
+ break;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ return matchedItems;
40
+ };
22
41
  const ModalFilterItems = _ref => {
23
42
  let {
24
43
  facet,
@@ -33,7 +52,7 @@ const ModalFilterItems = _ref => {
33
52
  datafield,
34
53
  section
35
54
  } = facet;
36
- const initialItemSize = 27;
55
+ const initialItemSize = 40;
37
56
  const [total, setTotal] = (0, _react.useState)(0);
38
57
  const [displayCount, setDisplayCount] = (0, _react.useState)(initialItemSize);
39
58
  const contentRef = (0, _react.useRef)(null);
@@ -60,7 +79,7 @@ const ModalFilterItems = _ref => {
60
79
  }));
61
80
  }
62
81
  }
63
- const uncheckedItems = sortFilters.filter(item => !item.isChecked).filter(item => item.name.toLowerCase().includes(searchText.toLowerCase())).slice(0, displayCount).map((item, index) => /*#__PURE__*/_react.default.createElement(_ReduxModalCheckbox.default, {
82
+ const uncheckedItems = searchItems(sortFilters.filter(item => !item.isChecked), searchText).slice(0, displayCount).map((item, index) => /*#__PURE__*/_react.default.createElement(_ReduxModalCheckbox.default, {
64
83
  checkboxItem: _objectSpread(_objectSpread({}, item), {}, {
65
84
  index,
66
85
  section
@@ -88,7 +107,7 @@ const ModalFilterItems = _ref => {
88
107
  sortFilters = (0, _Sort.sortBySection)(_objectSpread(_objectSpread({}, facet), {}, {
89
108
  sortBy
90
109
  }));
91
- const newUncheckedFullList = sortFilters.filter(item => !item.isChecked).filter(item => item.name.toLowerCase().includes(searchText.toLowerCase()));
110
+ const newUncheckedFullList = searchItems(sortFilters.filter(item => !item.isChecked), searchText);
92
111
  setDisplayCount(initialItemSize);
93
112
  setTotal(newUncheckedFullList.length);
94
113
  }, [searchText, sortBy]);
@@ -18,6 +18,25 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
18
18
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
19
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
20
20
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
+ const searchItems = (items, searchText) => {
22
+ let matchedItems = [];
23
+ const keyList = searchText.toUpperCase().split(',').filter(item => item.trim() !== '');
24
+ if (keyList.length === 0) {
25
+ matchedItems = items;
26
+ } else {
27
+ for (let i = 0; i < items.length; i += 1) {
28
+ const item = items[i];
29
+ for (let j = 0; j < keyList.length; j += 1) {
30
+ const key = keyList[j].trim();
31
+ if (key === '' || item.name.toUpperCase().includes(key)) {
32
+ matchedItems.push(item);
33
+ break;
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return matchedItems;
39
+ };
21
40
  const SearchFilterItems = _ref => {
22
41
  let {
23
42
  facet,
@@ -30,7 +49,7 @@ const SearchFilterItems = _ref => {
30
49
  datafield,
31
50
  section
32
51
  } = facet;
33
- const initialItemSize = 15;
52
+ const initialItemSize = 20;
34
53
  const [total, setTotal] = (0, _react.useState)(0);
35
54
  const [displayCount, setDisplayCount] = (0, _react.useState)(initialItemSize);
36
55
  const [open, setOpen] = (0, _react.useState)(false);
@@ -47,7 +66,7 @@ const SearchFilterItems = _ref => {
47
66
  facet: facet,
48
67
  queryParams: queryParams
49
68
  }));
50
- const uncheckedItems = sortFilters.filter(item => !item.isChecked).filter(item => item.name.toLowerCase().includes(searchText.toLowerCase())).slice(0, displayCount).map((item, index) => /*#__PURE__*/_react.default.createElement(_ReduxSearchCheckbox.default, {
69
+ const uncheckedItems = searchItems(sortFilters.filter(item => !item.isChecked), searchText).slice(0, displayCount).map((item, index) => /*#__PURE__*/_react.default.createElement(_ReduxSearchCheckbox.default, {
51
70
  checkboxItem: _objectSpread(_objectSpread({}, item), {}, {
52
71
  index,
53
72
  section
@@ -58,7 +77,7 @@ const SearchFilterItems = _ref => {
58
77
  }));
59
78
  (0, _react.useEffect)(() => {
60
79
  scrollableRef.current.scrollTo(0, 0);
61
- const newUncheckedFullList = sortFilters.filter(item => !item.isChecked).filter(item => item.name.toLowerCase().includes(searchText.toLowerCase()));
80
+ const newUncheckedFullList = searchItems(sortFilters.filter(item => !item.isChecked), searchText);
62
81
  setDisplayCount(initialItemSize);
63
82
  setTotal(newUncheckedFullList.length);
64
83
  }, [searchText]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/facet-filter",
3
- "version": "1.0.1-ccdihub.28",
3
+ "version": "1.0.1-ccdihub.29",
4
4
  "description": "### Bento core sidebar design:",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -11,6 +11,26 @@ import { sortBySection, sortType } from '../../utils/Sort';
11
11
  import styles from './ModalFilterStyle';
12
12
  import clearIcon from '../facet/assets/clearIcon.svg';
13
13
 
14
+ const searchItems = (items, searchText) => {
15
+ let matchedItems = [];
16
+ const keyList = searchText.toUpperCase().split(',').filter((item) => item.trim() !== '');
17
+ if (keyList.length === 0) {
18
+ matchedItems = items;
19
+ } else {
20
+ for (let i = 0; i < items.length; i += 1) {
21
+ const item = items[i];
22
+ for (let j = 0; j < keyList.length; j += 1) {
23
+ const key = keyList[j].trim();
24
+ if (key === '' || item.name.toUpperCase().includes(key)) {
25
+ matchedItems.push(item);
26
+ break;
27
+ }
28
+ }
29
+ }
30
+ }
31
+ return matchedItems;
32
+ };
33
+
14
34
  const ModalFilterItems = ({
15
35
  facet,
16
36
  searchText,
@@ -23,7 +43,7 @@ const ModalFilterItems = ({
23
43
  const {
24
44
  datafield, section,
25
45
  } = facet;
26
- const initialItemSize = 27;
46
+ const initialItemSize = 40;
27
47
  const [total, setTotal] = useState(0);
28
48
  const [displayCount, setDisplayCount] = useState(initialItemSize);
29
49
  const contentRef = useRef(null);
@@ -46,8 +66,8 @@ const ModalFilterItems = ({
46
66
  }
47
67
  }
48
68
 
49
- const uncheckedItems = sortFilters.filter((item) => !item.isChecked)
50
- .filter((item) => item.name.toLowerCase().includes(searchText.toLowerCase()))
69
+ const uncheckedItems = searchItems(sortFilters.filter((item) => !item.isChecked),
70
+ searchText)
51
71
  .slice(0, displayCount).map((item, index) => (<ReduxModalCheckbox
52
72
  checkboxItem={{ ...item, index, section }}
53
73
  datafield={datafield}
@@ -71,8 +91,8 @@ const ModalFilterItems = ({
71
91
  useEffect(() => {
72
92
  scrollableRef.current.scrollTo(0, 0);
73
93
  sortFilters = sortBySection({ ...facet, sortBy });
74
- const newUncheckedFullList = sortFilters.filter((item) => !item.isChecked)
75
- .filter((item) => item.name.toLowerCase().includes(searchText.toLowerCase()));
94
+ const newUncheckedFullList = searchItems(sortFilters.filter((item) => !item.isChecked),
95
+ searchText);
76
96
  setDisplayCount(initialItemSize);
77
97
  setTotal(newUncheckedFullList.length);
78
98
  }, [searchText, sortBy]);
@@ -10,6 +10,26 @@ import { sortBySection } from '../../utils/Sort';
10
10
  import styles from './FilterItemStyle';
11
11
  import ReduxFacetModal from '../facet/ReduxFacetModal';
12
12
 
13
+ const searchItems = (items, searchText) => {
14
+ let matchedItems = [];
15
+ const keyList = searchText.toUpperCase().split(',').filter((item) => item.trim() !== '');
16
+ if (keyList.length === 0) {
17
+ matchedItems = items;
18
+ } else {
19
+ for (let i = 0; i < items.length; i += 1) {
20
+ const item = items[i];
21
+ for (let j = 0; j < keyList.length; j += 1) {
22
+ const key = keyList[j].trim();
23
+ if (key === '' || item.name.toUpperCase().includes(key)) {
24
+ matchedItems.push(item);
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ }
30
+ return matchedItems;
31
+ };
32
+
13
33
  const SearchFilterItems = ({
14
34
  facet,
15
35
  queryParams,
@@ -20,7 +40,7 @@ const SearchFilterItems = ({
20
40
  const {
21
41
  datafield, section,
22
42
  } = facet;
23
- const initialItemSize = 15;
43
+ const initialItemSize = 20;
24
44
  const [total, setTotal] = useState(0);
25
45
  const [displayCount, setDisplayCount] = useState(initialItemSize);
26
46
  const [open, setOpen] = useState(false);
@@ -35,8 +55,8 @@ const SearchFilterItems = ({
35
55
  queryParams={queryParams}
36
56
  />));
37
57
 
38
- const uncheckedItems = sortFilters.filter((item) => !item.isChecked)
39
- .filter((item) => item.name.toLowerCase().includes(searchText.toLowerCase()))
58
+ const uncheckedItems = searchItems(sortFilters.filter((item) => !item.isChecked),
59
+ searchText)
40
60
  .slice(0, displayCount).map((item, index) => (<ReduxSearchCheckbox
41
61
  checkboxItem={{ ...item, index, section }}
42
62
  datafield={datafield}
@@ -46,8 +66,8 @@ const SearchFilterItems = ({
46
66
 
47
67
  useEffect(() => {
48
68
  scrollableRef.current.scrollTo(0, 0);
49
- const newUncheckedFullList = sortFilters.filter((item) => !item.isChecked)
50
- .filter((item) => item.name.toLowerCase().includes(searchText.toLowerCase()));
69
+ const newUncheckedFullList = searchItems(sortFilters.filter((item) => !item.isChecked),
70
+ searchText);
51
71
  setDisplayCount(initialItemSize);
52
72
  setTotal(newUncheckedFullList.length);
53
73
  }, [searchText]);