@bento-core/facet-filter 1.0.1-ins.1 → 1.0.1-ins.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.
@@ -12,13 +12,13 @@ var _FacetFilterView = _interopRequireDefault(require("./FacetFilterView"));
12
12
  const _excluded = ["section"];
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
15
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
16
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
17
15
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
17
  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
18
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
21
19
  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); }
20
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
21
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
22
22
  const FacetFilterController = props => {
23
23
  /**
24
24
  * update checkbox state
@@ -26,28 +26,28 @@ const FacetFilterController = props => {
26
26
  * 2. subject state
27
27
  */
28
28
  const {
29
- filterState,
29
+ activeFilters,
30
30
  data,
31
31
  facetsConfig,
32
- facetSectionConfig,
33
- tooltipText = {}
32
+ facetSectionConfig
34
33
  } = props;
34
+ const filterState = {};
35
+ // console.log(activeFilters);
36
+ for (const [key, value] of Object.entries(activeFilters)) {
37
+ if (key !== 'program_names') {
38
+ filterState[key] = value;
39
+ }
40
+ }
35
41
  const updateFacetState = filterSections => {
36
42
  const updateSections = [...filterSections];
37
43
  if (!_lodash.default.isEmpty(filterState)) {
38
44
  for (const [key, value] of Object.entries(filterState)) {
39
45
  updateSections.forEach(sideBar => {
40
46
  if (sideBar.type === _Types.InputTypes.CHECKBOX && sideBar.datafield === key) {
41
- const {
42
- facetValues = []
43
- } = sideBar;
44
- const updateFacetVals = facetValues.map(item => {
45
- const facetVal = item[sideBar.field];
46
- return _objectSpread(_objectSpread({}, item), {}, {
47
- isChecked: value[facetVal] ? value[facetVal] : false
48
- });
47
+ sideBar.facetValues.forEach(item => {
48
+ // item.isChecked = value[item.name] ? value[item.name] : false;
49
+ item.isChecked = value.indexOf(item.name) > -1;
49
50
  });
50
- sideBar.facetValues = updateFacetVals;
51
51
  }
52
52
  if (sideBar.type === _Types.InputTypes.SLIDER && sideBar.datafield === key) {
53
53
  sideBar.facetValues = value;
@@ -57,13 +57,9 @@ const FacetFilterController = props => {
57
57
  } else {
58
58
  updateSections.forEach(sideBar => {
59
59
  if (sideBar.type === _Types.InputTypes.CHECKBOX) {
60
- const {
61
- facetValues = []
62
- } = sideBar;
63
- const updateFacetVals = facetValues.map(item => _objectSpread(_objectSpread({}, item), {}, {
64
- isChecked: false
65
- }));
66
- sideBar.facetValues = updateFacetVals;
60
+ sideBar.facetValues.forEach(item => {
61
+ item.isChecked = false;
62
+ });
67
63
  }
68
64
  /**
69
65
  * set default value for slider - on clear all filter
@@ -108,7 +104,6 @@ const FacetFilterController = props => {
108
104
  * Construct filter object
109
105
  * 1. add facet values to facets
110
106
  * 2. add 'name' key to each facet value
111
- * 3. add '
112
107
  */
113
108
  const addFacetValues = facets => {
114
109
  const updateFacets = [];
@@ -118,13 +113,38 @@ const FacetFilterController = props => {
118
113
  facetValues: []
119
114
  });
120
115
  const {
116
+ field,
121
117
  ApiLowerBoundName,
122
118
  ApiUpperBoundName,
123
119
  apiForFiltering
124
120
  } = updateFacet;
125
121
  if (data[apiForFiltering]) {
126
122
  if (Array.isArray(data[apiForFiltering])) {
127
- updateFacet.facetValues = data[apiForFiltering];
123
+ const validValues = [];
124
+ const updateField = data[apiForFiltering].map(item => {
125
+ const addField = _objectSpread({}, item);
126
+ addField.name = item[field];
127
+ validValues.push(addField.name);
128
+ return addField;
129
+ });
130
+ /**
131
+ * Check if there are orphen filter values and add them to the facet values
132
+ */
133
+ if (filterState !== undefined) {
134
+ const facetFilter = filterState[facet.datafield];
135
+ if (facetFilter) {
136
+ facetFilter.forEach(item => {
137
+ if (validValues.indexOf(item) === -1) {
138
+ const tmp = {};
139
+ tmp.group = item;
140
+ tmp.name = item;
141
+ tmp.subjects = 0;
142
+ updateField.push(tmp);
143
+ }
144
+ });
145
+ }
146
+ }
147
+ updateFacet.facetValues = updateField;
128
148
  }
129
149
  /**
130
150
  * add object to facet values
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/facet-filter",
3
- "version": "1.0.1-ins.1",
3
+ "version": "1.0.1-ins.3",
4
4
  "description": "### Bento core sidebar design:",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -21,28 +21,30 @@ const FacetFilterController = (props) => {
21
21
  * 2. subject state
22
22
  */
23
23
  const {
24
- filterState,
24
+ activeFilters,
25
25
  data,
26
26
  facetsConfig,
27
27
  facetSectionConfig,
28
- tooltipText = {},
29
28
  } = props;
30
29
 
30
+ const filterState = {};
31
+ // console.log(activeFilters);
32
+ for (const [key, value] of Object.entries(activeFilters)) {
33
+ if (key !== 'program_names') {
34
+ filterState[key] = value;
35
+ }
36
+ }
37
+
31
38
  const updateFacetState = (filterSections) => {
32
39
  const updateSections = [...filterSections];
33
40
  if (!_.isEmpty(filterState)) {
34
41
  for (const [key, value] of Object.entries(filterState)) {
35
42
  updateSections.forEach((sideBar) => {
36
43
  if (sideBar.type === InputTypes.CHECKBOX && sideBar.datafield === key) {
37
- const { facetValues = [] } = sideBar;
38
- const updateFacetVals = facetValues.map((item) => {
39
- const facetVal = item[sideBar.field];
40
- return {
41
- ...item,
42
- isChecked: value[facetVal] ? value[facetVal] : false,
43
- };
44
+ sideBar.facetValues.forEach((item) => {
45
+ // item.isChecked = value[item.name] ? value[item.name] : false;
46
+ item.isChecked = value.indexOf(item.name) > -1;
44
47
  });
45
- sideBar.facetValues = updateFacetVals;
46
48
  }
47
49
  if (sideBar.type === InputTypes.SLIDER && sideBar.datafield === key) {
48
50
  sideBar.facetValues = value;
@@ -52,12 +54,9 @@ const FacetFilterController = (props) => {
52
54
  } else {
53
55
  updateSections.forEach((sideBar) => {
54
56
  if (sideBar.type === InputTypes.CHECKBOX) {
55
- const { facetValues = [] } = sideBar;
56
- const updateFacetVals = facetValues.map((item) => ({
57
- ...item,
58
- isChecked: false,
59
- }));
60
- sideBar.facetValues = updateFacetVals;
57
+ sideBar.facetValues.forEach((item) => {
58
+ item.isChecked = false;
59
+ });
61
60
  }
62
61
  /**
63
62
  * set default value for slider - on clear all filter
@@ -93,7 +92,6 @@ const FacetFilterController = (props) => {
93
92
  * Construct filter object
94
93
  * 1. add facet values to facets
95
94
  * 2. add 'name' key to each facet value
96
- * 3. add '
97
95
  */
98
96
  const addFacetValues = (facets) => {
99
97
  const updateFacets = [];
@@ -101,13 +99,38 @@ const FacetFilterController = (props) => {
101
99
  facets.forEach((facet) => {
102
100
  const updateFacet = { ...facet, facetValues: [] };
103
101
  const {
102
+ field,
104
103
  ApiLowerBoundName,
105
104
  ApiUpperBoundName,
106
105
  apiForFiltering,
107
106
  } = updateFacet;
108
107
  if (data[apiForFiltering]) {
109
108
  if (Array.isArray(data[apiForFiltering])) {
110
- updateFacet.facetValues = data[apiForFiltering];
109
+ const validValues = [];
110
+ const updateField = data[apiForFiltering].map((item) => {
111
+ const addField = { ...item };
112
+ addField.name = item[field];
113
+ validValues.push(addField.name);
114
+ return addField;
115
+ });
116
+ /**
117
+ * Check if there are orphen filter values and add them to the facet values
118
+ */
119
+ if (filterState !== undefined) {
120
+ const facetFilter = filterState[facet.datafield];
121
+ if (facetFilter) {
122
+ facetFilter.forEach((item) => {
123
+ if (validValues.indexOf(item) === -1) {
124
+ const tmp = {};
125
+ tmp.group = item;
126
+ tmp.name = item;
127
+ tmp.subjects = 0;
128
+ updateField.push(tmp);
129
+ }
130
+ });
131
+ }
132
+ }
133
+ updateFacet.facetValues = updateField;
111
134
  }
112
135
  /**
113
136
  * add object to facet values