@bento-core/facet-filter 1.0.1-icdc.1 → 1.0.1-icdc.10

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/README.md CHANGED
@@ -72,12 +72,17 @@ import FacetFilter from 'bento-core';
72
72
  ```
73
73
  import { InputTypes } from 'bento-core';
74
74
 
75
+ // fields for labelds and counts
76
+ const GROUP = 'group'; // access labels
77
+ const COUNT = 'subjects'; // access count value
78
+
75
79
  export const facetsConfig = [{
76
80
  section: CASES,
77
81
  label: 'Program',
78
82
  apiForFiltering: 'filterSubjectCountByProgram',
79
83
  datafield: 'programs',
80
- field: GROUP,
84
+ field: GROUP,
85
+ count: COUNT,
81
86
  type: InputTypes.CHECKBOX,
82
87
  sort_type: sortType.ALPHABET,
83
88
  show: true,
@@ -265,11 +270,29 @@ const CustomClearAllFiltersBtn = ({ onClearAllFilters, disable }) => {
265
270
  ```
266
271
  // response
267
272
  // filterCaseCountByProgram: [{group: "COP", subjects: 301}]
273
+
274
+ // facet = {
275
+ // section: CASES,
276
+ // label: 'Program',
277
+ // apiForFiltering: 'filterSubjectCountByProgram',
278
+ // datafield: 'programs',
279
+ // field: GROUP,
280
+ // count: COUNT,
281
+ // type: InputTypes.CHECKBOX,
282
+ // sort_type: sortType.ALPHABET,
283
+ // show: true,
284
+ // customCount = (text) => `(${text})`,
285
+ // }
286
+
287
+ const {
288
+ field = 'group',
289
+ count = 'subjects',
290
+ customCount = (text) => `(${text})`,
291
+ } = facet;
268
292
  const {
269
- name,
270
- customName,
271
- subjects,
272
- customSubjects,
293
+ isChecked = false,
294
+ index,
295
+ section,
273
296
  tooltip,
274
297
  } = checkboxItem;
275
298
 
@@ -17,7 +17,9 @@ const BentoFacetFilter = _ref => {
17
17
  let {
18
18
  sideBarSections,
19
19
  CustomFacetSection,
20
- CustomFacetView
20
+ CustomFacetView,
21
+ enableClearSection,
22
+ enableFacetCollapse
21
23
  } = _ref;
22
24
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, sideBarSections.map((section, index) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Divider, {
23
25
  variant: "middle",
@@ -27,7 +29,9 @@ const BentoFacetFilter = _ref => {
27
29
  CustomSection: CustomFacetSection
28
30
  }, section.items.map(facet => /*#__PURE__*/_react.default.createElement(_ReduxFacetView.default, {
29
31
  facet: facet,
30
- CustomView: CustomFacetView
32
+ CustomView: CustomFacetView,
33
+ enableClearSection: enableClearSection,
34
+ enableFacetCollapse: enableFacetCollapse
31
35
  }))))));
32
36
  };
33
37
  var _default = (0, _core.withStyles)(_FacetFilterStyle.default)(BentoFacetFilter);
@@ -20,6 +20,13 @@ var _default = () => ({
20
20
  position: 'initial'
21
21
  }
22
22
  },
23
+ subSectionSummaryTextWrapper: {
24
+ display: 'flex',
25
+ alignItems: 'center',
26
+ justifyContent: 'space-between',
27
+ width: '100%',
28
+ paddingRight: '15px'
29
+ },
23
30
  subSectionSummaryText: {
24
31
  marginLeft: '10px',
25
32
  lineHeight: 0,
@@ -34,21 +41,26 @@ var _default = () => ({
34
41
  marginBottom: '5px',
35
42
  borderTop: '1px solid #B1B1B1',
36
43
  textAlign: 'left',
37
- marginLeft: '-5px'
44
+ // marginLeft: '-5px',
45
+ display: 'flex',
46
+ alignItems: 'center',
47
+ justifyContent: 'space-around'
38
48
  },
39
49
  sortGroupIcon: {
40
50
  cursor: 'pointer',
41
51
  fontFamily: 'Nunito',
42
- fontSize: '10px',
43
- marginRight: '12px',
44
- marginLeft: '16px'
52
+ fontSize: '10px'
53
+ // marginRight: '12px',
54
+ // marginLeft: '16px',
45
55
  },
56
+
46
57
  sortGroupItem: {
47
58
  cursor: 'pointer',
48
59
  fontFamily: 'Nunito',
49
- fontSize: '10px',
50
- marginRight: '32px'
60
+ fontSize: '10px'
61
+ // marginRight: '32px',
51
62
  },
63
+
52
64
  NonSortGroup: {
53
65
  marginBottom: '5px',
54
66
  borderTop: '1px solid #B1B1B1',
@@ -63,11 +75,12 @@ var _default = () => ({
63
75
  sortGroupItemCounts: {
64
76
  cursor: 'pointer',
65
77
  fontFamily: 'Nunito',
66
- fontSize: '10px',
67
- float: 'right',
68
- marginRight: '10px',
69
- marginTop: '5px'
78
+ fontSize: '10px'
79
+ // float: 'right',
80
+ // marginRight: '10px',
81
+ // marginTop: '5px',
70
82
  },
83
+
71
84
  highlight: {
72
85
  color: '#b2c6d6'
73
86
  },
@@ -7,12 +7,15 @@ exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _core = require("@material-ui/core");
9
9
  var _clsx = _interopRequireDefault(require("clsx"));
10
+ var _Refresh = _interopRequireDefault(require("@material-ui/icons/Refresh"));
11
+ var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
10
12
  var _AccordionSummaryView = _interopRequireDefault(require("../summary/AccordionSummaryView"));
11
13
  var _Types = require("../inputs/Types");
12
14
  var _FacetStyle = _interopRequireDefault(require("./FacetStyle"));
13
15
  var _FilterItems = _interopRequireDefault(require("../inputs/FilterItems"));
14
16
  var _Sort = require("../../utils/Sort");
15
17
  var _clearIcon = _interopRequireDefault(require("./assets/clearIcon.svg"));
18
+ var _ActionTypes = require("../../store/actions/ActionTypes");
16
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
21
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -25,18 +28,50 @@ const FacetView = _ref => {
25
28
  let {
26
29
  classes,
27
30
  facet,
31
+ enableClearSection,
28
32
  onClearFacetSection,
29
33
  onClearSliderSection,
30
34
  CustomView,
31
35
  autoComplete,
32
- upload
36
+ upload,
37
+ filterState,
38
+ currentActionType = {},
39
+ enableFacetCollapse
33
40
  } = _ref;
34
41
  const [expand, setExpand] = (0, _react.useState)(false);
35
42
  const onExpandFacet = () => setExpand(!expand);
43
+ const {
44
+ datafield
45
+ } = facet;
46
+ /**
47
+ * Collapse expanded facet or facets
48
+ * 1. on clear facet section
49
+ * 2. on clear all
50
+ * 3. on uncheck facet from DQB
51
+ */
52
+ (0, _react.useEffect)(() => {
53
+ if (enableFacetCollapse) {
54
+ const actionType = currentActionType[datafield];
55
+ // collapse facet if uncheck from DQB
56
+ if (actionType && actionType === _ActionTypes.sideBarActionTypes.FACET_VALUE_CHANGED) {
57
+ const {
58
+ isFacetOrigin
59
+ } = currentActionType;
60
+ if (!isFacetOrigin) {
61
+ if (Object.keys(filterState[datafield] || {}).length === 0) {
62
+ setExpand(false);
63
+ }
64
+ }
65
+ }
66
+ if (actionType && actionType === _ActionTypes.sideBarActionTypes.CLEAR_FACET_SECTION || currentActionType === _ActionTypes.sideBarActionTypes.CLEAR_ALL_FILTERS) {
67
+ setExpand(false);
68
+ }
69
+ }
70
+ }, [filterState]);
36
71
 
37
72
  /**
38
- * expand section incase of active local search
39
- */
73
+ * expand section incase of active local search
74
+ */
40
75
  (0, _react.useEffect)(() => {
41
76
  if (autoComplete && autoComplete.length > 0 || upload && upload.length > 0) {
42
77
  setExpand(true);
@@ -48,10 +83,13 @@ const FacetView = _ref => {
48
83
  };
49
84
  const onClearSection = () => {
50
85
  setSortBy(null);
51
- if (facet.type === _Types.InputTypes.SLIDER) {
52
- onClearSliderSection(facet);
53
- } else {
54
- onClearFacetSection(facet);
86
+ const activeFilterItems = filterState[datafield];
87
+ if (activeFilterItems && Object.keys(activeFilterItems).length > 0) {
88
+ if (facet.type === _Types.InputTypes.SLIDER) {
89
+ onClearSliderSection(facet);
90
+ } else {
91
+ onClearFacetSection(facet);
92
+ }
55
93
  }
56
94
  };
57
95
  /**
@@ -75,14 +113,25 @@ const FacetView = _ref => {
75
113
  },
76
114
  id: facet.section
77
115
  }, CustomView ? /*#__PURE__*/_react.default.createElement(CustomView, {
116
+ clearFacetSectionValues: onClearSection,
117
+ hasSelections: selectedItems.length,
78
118
  facet: facet,
79
119
  facetClasses: isActiveFacet ? "activeFacet".concat(facet.section) : "inactiveFacet".concat(facet.section)
80
- }) : /*#__PURE__*/_react.default.createElement(_AccordionSummaryView.default, null, /*#__PURE__*/_react.default.createElement("div", {
120
+ }) : /*#__PURE__*/_react.default.createElement(_AccordionSummaryView.default, null, !enableClearSection ? /*#__PURE__*/_react.default.createElement("div", {
121
+ id: "filterGroup_ ".concat(facet.datafield, "\n ").concat(facet.label),
122
+ className: (0, _clsx.default)(classes.subSectionSummaryText, {
123
+ ["activeFacet".concat(facet.section)]: isActiveFacet
124
+ })
125
+ }, facet.label) : /*#__PURE__*/_react.default.createElement("div", {
126
+ className: classes.subSectionSummaryTextWrapper
127
+ }, /*#__PURE__*/_react.default.createElement("div", {
81
128
  id: "filterGroup_ ".concat(facet.datafield, "\n ").concat(facet.label),
82
129
  className: (0, _clsx.default)(classes.subSectionSummaryText, {
83
130
  ["activeFacet".concat(facet.section)]: isActiveFacet
84
131
  })
85
- }, facet.label)), (facet.type === _Types.InputTypes.SLIDER || facetValues.length === 0) && /*#__PURE__*/_react.default.createElement("div", {
132
+ }, facet.label), selectedItems.length ? /*#__PURE__*/_react.default.createElement(_IconButton.default, {
133
+ onClick: onClearSection
134
+ }, /*#__PURE__*/_react.default.createElement(_Refresh.default, null)) : null)), (facet.type === _Types.InputTypes.SLIDER || facetValues.length === 0) && /*#__PURE__*/_react.default.createElement("div", {
86
135
  className: classes.NonSortGroup
87
136
  }, /*#__PURE__*/_react.default.createElement("span", {
88
137
  className: classes.NonSortGroupItem
@@ -14,11 +14,13 @@ const mapStateToProps = state => {
14
14
  var _state$localFind, _state$localFind2;
15
15
  return {
16
16
  filterState: state.statusReducer.filterState,
17
+ currentActionType: state.statusReducer.currentActionType,
17
18
  autoComplete: (state === null || state === void 0 ? void 0 : (_state$localFind = state.localFind) === null || _state$localFind === void 0 ? void 0 : _state$localFind.autocomplete) || [],
18
19
  upload: (state === null || state === void 0 ? void 0 : (_state$localFind2 = state.localFind) === null || _state$localFind2 === void 0 ? void 0 : _state$localFind2.upload) || []
19
20
  };
20
21
  };
21
22
  const mapDispatchToProps = dispatch => ({
23
+ onToggle: facet => dispatch((0, _Actions.toggleCheckBox)(facet)),
22
24
  onClearFacetSection: facet => {
23
25
  dispatch((0, _Actions.clearFacetSection)(facet));
24
26
  },
@@ -10,6 +10,7 @@ var _core = require("@material-ui/core");
10
10
  var _clsx = _interopRequireDefault(require("clsx"));
11
11
  var _icons = require("@material-ui/icons");
12
12
  var _CheckboxStyle = _interopRequireDefault(require("./CheckboxStyle"));
13
+ var _ActionTypes = require("../../../store/actions/ActionTypes");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
  /* eslint-disable no-unused-vars */
15
16
  /* eslint-disable no-unused-vars */
@@ -46,7 +47,11 @@ const CheckBoxView = _ref => {
46
47
  const toggleCheckBoxItem = {
47
48
  name: name,
48
49
  datafield: datafield,
49
- isChecked: !isChecked
50
+ isChecked: !isChecked,
51
+ actionType: {
52
+ [datafield]: _ActionTypes.sideBarActionTypes.FACET_VALUE_CHANGED,
53
+ isFacetOrigin: true
54
+ }
50
55
  };
51
56
  onToggle(toggleCheckBoxItem);
52
57
  };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _core = require("@material-ui/core");
9
+ var _clsx = _interopRequireDefault(require("clsx"));
9
10
  var _SliderStyle = _interopRequireDefault(require("./SliderStyle"));
10
11
  var _Types = require("../Types");
11
12
  var _InputMinMaxView = _interopRequireDefault(require("./InputMinMaxView"));
@@ -63,9 +64,9 @@ const SliderView = _ref => {
63
64
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
64
65
  className: classes.sliderRoot
65
66
  }, /*#__PURE__*/_react.default.createElement("div", {
66
- className: classes.minMaxInputs
67
+ className: (0, _clsx.default)(classes.minMaxInputs, 'minMaxInputs')
67
68
  }, /*#__PURE__*/_react.default.createElement("div", {
68
- className: classes.minValue
69
+ className: (0, _clsx.default)(classes.minValue, 'min_input_box')
69
70
  }, /*#__PURE__*/_react.default.createElement(_core.Typography, {
70
71
  className: classes.minInputLabel
71
72
  }, "Min:"), /*#__PURE__*/_react.default.createElement(_InputMinMaxView.default, {
@@ -76,7 +77,7 @@ const SliderView = _ref => {
76
77
  type: _Types.silderTypes.INPUT_MIN,
77
78
  onInputChange: handleChangeCommittedSlider
78
79
  })), /*#__PURE__*/_react.default.createElement("div", {
79
- className: classes.maxValue
80
+ className: (0, _clsx.default)(classes.maxValue, 'max_input_box')
80
81
  }, /*#__PURE__*/_react.default.createElement(_core.Typography, {
81
82
  className: classes.maxInputLabel
82
83
  }, "Max:"), /*#__PURE__*/_react.default.createElement(_InputMinMaxView.default, {
@@ -87,7 +88,7 @@ const SliderView = _ref => {
87
88
  type: _Types.silderTypes.INPUT_MAX,
88
89
  onInputChange: handleChangeCommittedSlider
89
90
  }))), /*#__PURE__*/_react.default.createElement("div", {
90
- className: classes.slider
91
+ className: (0, _clsx.default)(classes.slider, 'slider')
91
92
  }, /*#__PURE__*/_react.default.createElement(_core.Slider, {
92
93
  disableSwap: true,
93
94
  getAriaValueText: valuetext,
@@ -11,6 +11,7 @@ var _AccordionSummaryStyle = _interopRequireDefault(require("./AccordionSummaryS
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  const Summary = (0, _core.withStyles)({
13
13
  root: {
14
+ width: '307px',
14
15
  marginBottom: -1,
15
16
  minHeight: 48,
16
17
  paddingLeft: 14,
package/dist/index.js CHANGED
@@ -81,6 +81,12 @@ Object.defineProperty(exports, "onToggleStateUpdate", {
81
81
  return _SideBarReducer.onToggleStateUpdate;
82
82
  }
83
83
  });
84
+ Object.defineProperty(exports, "sideBarActionTypes", {
85
+ enumerable: true,
86
+ get: function get() {
87
+ return _ActionTypes.sideBarActionTypes;
88
+ }
89
+ });
84
90
  Object.defineProperty(exports, "sideBarReducerGenerator", {
85
91
  enumerable: true,
86
92
  get: function get() {
@@ -129,6 +135,7 @@ var _filter = require("./utils/filter");
129
135
  var _Types = require("./components/inputs/Types");
130
136
  var _SideBarReducer = require("./store/reducers/SideBarReducer");
131
137
  var _Actions = require("./store/actions/Actions");
138
+ var _ActionTypes = require("./store/actions/ActionTypes");
132
139
  var _component = require("./generator/component");
133
140
  var _ReduxClearAllBtn = _interopRequireDefault(require("./components/reset/ReduxClearAllBtn"));
134
141
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -44,7 +44,10 @@ const onClearFacetSection = _ref2 => {
44
44
  if (updatedState[datafield]) {
45
45
  updatedState[datafield] = {};
46
46
  }
47
- return updatedState;
47
+ return {
48
+ updatedState,
49
+ datafield
50
+ };
48
51
  };
49
52
  exports.onClearFacetSection = onClearFacetSection;
50
53
  const onClearSliderSection = _ref3 => {
@@ -87,31 +90,47 @@ function sideBarReducerGenerator() {
87
90
  switch (type) {
88
91
  case _ActionTypes.sideBarActionTypes.FACET_VALUE_CHANGED:
89
92
  updateState = onToggleStateUpdate(_objectSpread(_objectSpread({}, state), payload));
93
+ const {
94
+ actionType = _ActionTypes.sideBarActionTypes.FACET_VALUE_CHANGED
95
+ } = payload;
90
96
  return _objectSpread(_objectSpread({}, state), {}, {
91
- filterState: _objectSpread({}, updateState)
97
+ filterState: _objectSpread({}, updateState),
98
+ currentActionType: actionType
92
99
  });
93
100
  case _ActionTypes.sideBarActionTypes.ON_TOGGLE_SLIDER:
94
101
  updateState = updateSiderValue(_objectSpread(_objectSpread({}, state), payload));
95
102
  return _objectSpread(_objectSpread({}, state), {}, {
96
- filterState: _objectSpread({}, updateState)
103
+ filterState: _objectSpread({}, updateState),
104
+ currentActionType: _ActionTypes.sideBarActionTypes.ON_TOGGLE_SLIDER
97
105
  });
98
106
  case _ActionTypes.sideBarActionTypes.CLEAR_ALL_FILTERS:
99
107
  return _objectSpread(_objectSpread({}, state), {}, {
100
- filterState: {}
108
+ filterState: {},
109
+ currentActionType: _ActionTypes.sideBarActionTypes.CLEAR_ALL_FILTERS
101
110
  });
102
111
  case _ActionTypes.sideBarActionTypes.CLEAR_FACET_SECTION:
103
- updateState = onClearFacetSection(_objectSpread(_objectSpread({}, payload), state));
112
+ const {
113
+ updatedState: updtState,
114
+ datafield
115
+ } = onClearFacetSection(_objectSpread(_objectSpread({}, payload), state));
116
+ updateState = updtState;
117
+ const currentActionType = {
118
+ [datafield]: _ActionTypes.sideBarActionTypes.CLEAR_FACET_SECTION
119
+ };
104
120
  return _objectSpread(_objectSpread({}, state), {}, {
105
- filterState: _objectSpread({}, updateState)
121
+ filterState: _objectSpread({}, updateState),
122
+ currentActionType
106
123
  });
107
124
  case _ActionTypes.sideBarActionTypes.CLEAR_SLIDER_SECTION:
108
125
  updateState = onClearSliderSection(_objectSpread(_objectSpread({}, payload), state));
109
126
  return _objectSpread(_objectSpread({}, state), {}, {
110
- filterState: _objectSpread({}, updateState)
127
+ filterState: _objectSpread({}, updateState),
128
+ currentActionType: _ActionTypes.sideBarActionTypes.CLEAR_SLIDER_SECTION
111
129
  });
112
130
  case _ActionTypes.sideBarActionTypes.CLEAR_AND_SELECT_FACET_VALUE:
113
131
  return {
114
- filterState: payload
132
+ filterState: payload,
133
+ currentActionType: _ActionTypes.sideBarActionTypes.CLEAR_AND_SELECT_FACET_VALUE
115
134
  };
116
135
  default:
117
136
  return state;
package/package.json CHANGED
@@ -1,17 +1,14 @@
1
1
  {
2
2
  "name": "@bento-core/facet-filter",
3
- "version": "1.0.1-icdc.1",
4
- "description": "### Bento core sidebar design:",
3
+ "version": "1.0.1-icdc.10",
4
+ "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "build": "npm run lint && cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
9
  "lint": "eslint src"
10
10
  },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/CBIIT/bento-frontend.git"
14
- },
11
+ "repository": "https://github.com/CBIIT/bento-frontend",
15
12
  "publishConfig": {
16
13
  "access": "public"
17
14
  },
@@ -27,9 +24,5 @@
27
24
  "react-redux": "^7.2.1"
28
25
  },
29
26
  "author": "CTOS Bento Team",
30
- "license": "ISC",
31
- "bugs": {
32
- "url": "https://github.com/CBIIT/bento-frontend/issues"
33
- },
34
- "homepage": "https://github.com/CBIIT/bento-frontend#readme"
27
+ "license": "ISC"
35
28
  }
@@ -1,10 +1,7 @@
1
1
  /* eslint-disable arrow-body-style */
2
2
  /* eslint-disable padded-blocks */
3
3
  import React from 'react';
4
- import {
5
- Divider,
6
- withStyles,
7
- } from '@material-ui/core';
4
+ import { Divider, withStyles } from '@material-ui/core';
8
5
  import styles from './FacetFilterStyle';
9
6
  import FacetSectionView from './components/section/FacetSectionView';
10
7
  import FacetView from './components/facet/ReduxFacetView';
@@ -13,30 +10,29 @@ const BentoFacetFilter = ({
13
10
  sideBarSections,
14
11
  CustomFacetSection,
15
12
  CustomFacetView,
13
+ enableClearSection,
14
+ enableFacetCollapse,
16
15
  }) => {
17
16
  return (
18
17
  <>
19
- {
20
- sideBarSections.map((section, index) => (
21
- <>
22
- <Divider
23
- variant="middle"
24
- className={`divider${index}`}
25
- />
26
- <FacetSectionView
27
- section={section}
28
- CustomSection={CustomFacetSection}
29
- >
30
- {section.items.map((facet) => (
31
- <FacetView
32
- facet={facet}
33
- CustomView={CustomFacetView}
34
- />
35
- ))}
36
- </FacetSectionView>
37
- </>
38
- ))
39
- }
18
+ {sideBarSections.map((section, index) => (
19
+ <>
20
+ <Divider variant="middle" className={`divider${index}`} />
21
+ <FacetSectionView
22
+ section={section}
23
+ CustomSection={CustomFacetSection}
24
+ >
25
+ {section.items.map((facet) => (
26
+ <FacetView
27
+ facet={facet}
28
+ CustomView={CustomFacetView}
29
+ enableClearSection={enableClearSection}
30
+ enableFacetCollapse={enableFacetCollapse}
31
+ />
32
+ ))}
33
+ </FacetSectionView>
34
+ </>
35
+ ))}
40
36
  </>
41
37
  );
42
38
  };
@@ -14,6 +14,13 @@ export default () => ({
14
14
  position: 'initial',
15
15
  },
16
16
  },
17
+ subSectionSummaryTextWrapper: {
18
+ display: 'flex',
19
+ alignItems: 'center',
20
+ justifyContent: 'space-between',
21
+ width: '100%',
22
+ paddingRight: '15px',
23
+ },
17
24
  subSectionSummaryText: {
18
25
  marginLeft: '10px',
19
26
  lineHeight: 0,
@@ -28,20 +35,23 @@ export default () => ({
28
35
  marginBottom: '5px',
29
36
  borderTop: '1px solid #B1B1B1',
30
37
  textAlign: 'left',
31
- marginLeft: '-5px',
38
+ // marginLeft: '-5px',
39
+ display: 'flex',
40
+ alignItems: 'center',
41
+ justifyContent: 'space-around',
32
42
  },
33
43
  sortGroupIcon: {
34
44
  cursor: 'pointer',
35
45
  fontFamily: 'Nunito',
36
46
  fontSize: '10px',
37
- marginRight: '12px',
38
- marginLeft: '16px',
47
+ // marginRight: '12px',
48
+ // marginLeft: '16px',
39
49
  },
40
50
  sortGroupItem: {
41
51
  cursor: 'pointer',
42
52
  fontFamily: 'Nunito',
43
53
  fontSize: '10px',
44
- marginRight: '32px',
54
+ // marginRight: '32px',
45
55
  },
46
56
  NonSortGroup: {
47
57
  marginBottom: '5px',
@@ -58,9 +68,9 @@ export default () => ({
58
68
  cursor: 'pointer',
59
69
  fontFamily: 'Nunito',
60
70
  fontSize: '10px',
61
- float: 'right',
62
- marginRight: '10px',
63
- marginTop: '5px',
71
+ // float: 'right',
72
+ // marginRight: '10px',
73
+ // marginTop: '5px',
64
74
  },
65
75
  highlight: {
66
76
  color: '#b2c6d6',
@@ -1,36 +1,68 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import {
3
- Accordion,
4
- List,
5
- withStyles,
6
- Icon,
3
+ Accordion, List, withStyles, Icon,
7
4
  } from '@material-ui/core';
8
5
  import clsx from 'clsx';
6
+ import RefreshIcon from '@material-ui/icons/Refresh';
7
+ import IconButton from '@material-ui/core/IconButton';
9
8
  import CustomAccordionSummary from '../summary/AccordionSummaryView';
10
9
  import { InputTypes } from '../inputs/Types';
11
10
  import styles from './FacetStyle';
12
11
  import FilterItems from '../inputs/FilterItems';
13
12
  import { sortType } from '../../utils/Sort';
14
13
  import clearIcon from './assets/clearIcon.svg';
14
+ import { sideBarActionTypes } from '../../store/actions/ActionTypes';
15
15
 
16
16
  const FacetView = ({
17
17
  classes,
18
18
  facet,
19
+ enableClearSection,
19
20
  onClearFacetSection,
20
21
  onClearSliderSection,
21
22
  CustomView,
22
23
  autoComplete,
23
24
  upload,
25
+ filterState,
26
+ currentActionType = {},
27
+ enableFacetCollapse,
24
28
  }) => {
25
29
  const [expand, setExpand] = useState(false);
26
30
  const onExpandFacet = () => setExpand(!expand);
27
31
 
32
+ const { datafield } = facet;
28
33
  /**
29
- * expand section incase of active local search
30
- */
34
+ * Collapse expanded facet or facets
35
+ * 1. on clear facet section
36
+ * 2. on clear all
37
+ * 3. on uncheck facet from DQB
38
+ */
39
+ useEffect(() => {
40
+ if (enableFacetCollapse) {
41
+ const actionType = currentActionType[datafield];
42
+ // collapse facet if uncheck from DQB
43
+ if (actionType && actionType === sideBarActionTypes.FACET_VALUE_CHANGED) {
44
+ const { isFacetOrigin } = currentActionType;
45
+ if (!isFacetOrigin) {
46
+ if (Object.keys(filterState[datafield] || {}).length === 0) {
47
+ setExpand(false);
48
+ }
49
+ }
50
+ }
51
+ if ((actionType && actionType === sideBarActionTypes.CLEAR_FACET_SECTION)
52
+ || currentActionType === sideBarActionTypes.CLEAR_ALL_FILTERS) {
53
+ setExpand(false);
54
+ }
55
+ }
56
+ }, [filterState]);
57
+
58
+ /**
59
+ * expand section incase of active local search
60
+ */
31
61
  useEffect(() => {
32
- if ((autoComplete && autoComplete.length > 0)
33
- || (upload && upload.length > 0)) {
62
+ if (
63
+ (autoComplete && autoComplete.length > 0)
64
+ || (upload && upload.length > 0)
65
+ ) {
34
66
  setExpand(true);
35
67
  }
36
68
  }, [autoComplete, upload]);
@@ -42,10 +74,13 @@ const FacetView = ({
42
74
 
43
75
  const onClearSection = () => {
44
76
  setSortBy(null);
45
- if (facet.type === InputTypes.SLIDER) {
46
- onClearSliderSection(facet);
47
- } else {
48
- onClearFacetSection(facet);
77
+ const activeFilterItems = filterState[datafield];
78
+ if (activeFilterItems && Object.keys(activeFilterItems).length > 0) {
79
+ if (facet.type === InputTypes.SLIDER) {
80
+ onClearSliderSection(facet);
81
+ } else {
82
+ onClearFacetSection(facet);
83
+ }
49
84
  }
50
85
  };
51
86
  /**
@@ -57,6 +92,7 @@ const FacetView = ({
57
92
  displayFacet.facetValues = selectedItems;
58
93
  const isActiveFacet = [...selectedItems].length > 0;
59
94
  const limitCheckBoxCount = facet?.showCheckboxCount || 5;
95
+
60
96
  return (
61
97
  <>
62
98
  <Accordion
@@ -68,119 +104,103 @@ const FacetView = ({
68
104
  }}
69
105
  id={facet.section}
70
106
  >
71
- { CustomView ? (
107
+ {CustomView ? (
72
108
  <CustomView
109
+ clearFacetSectionValues={onClearSection}
110
+ hasSelections={selectedItems.length}
73
111
  facet={facet}
74
112
  facetClasses={
75
- isActiveFacet ? `activeFacet${facet.section}`
76
- : `inactiveFacet${facet.section}`
113
+ isActiveFacet
114
+ ? `activeFacet${facet.section}`
115
+ : `inactiveFacet${facet.section}`
77
116
  }
78
117
  />
79
118
  ) : (
80
119
  <CustomAccordionSummary>
81
- <div
82
- id={
83
- `filterGroup_ ${facet.datafield}
84
- ${facet.label}`
85
- }
86
- className={clsx(classes.subSectionSummaryText, {
87
- [`activeFacet${facet.section}`]: isActiveFacet,
88
- })}
89
- >
90
- {facet.label}
91
- </div>
120
+ {!enableClearSection ? (
121
+ <div
122
+ id={`filterGroup_ ${facet.datafield}
123
+ ${facet.label}`}
124
+ className={clsx(classes.subSectionSummaryText, {
125
+ [`activeFacet${facet.section}`]: isActiveFacet,
126
+ })}
127
+ >
128
+ {facet.label}
129
+ </div>
130
+ ) : (
131
+ <div className={classes.subSectionSummaryTextWrapper}>
132
+ <div
133
+ id={`filterGroup_ ${facet.datafield}
134
+ ${facet.label}`}
135
+ className={clsx(classes.subSectionSummaryText, {
136
+ [`activeFacet${facet.section}`]: isActiveFacet,
137
+ })}
138
+ >
139
+ {facet.label}
140
+ </div>
141
+ {selectedItems.length ? (
142
+ <IconButton onClick={onClearSection}>
143
+ <RefreshIcon />
144
+ </IconButton>
145
+ ) : null}
146
+ </div>
147
+ )}
92
148
  </CustomAccordionSummary>
93
149
  )}
94
- {
95
- (facet.type === InputTypes.SLIDER || facetValues.length === 0)
96
- && (
150
+ {(facet.type === InputTypes.SLIDER || facetValues.length === 0) && (
97
151
  <div className={classes.NonSortGroup}>
98
- <span
99
- className={classes.NonSortGroupItem}
100
- >
152
+ <span className={classes.NonSortGroupItem}>
101
153
  No data for this field
102
154
  </span>
103
155
  </div>
104
- )
105
- }
106
- {
107
- (facet.type === InputTypes.SLIDER || facetValues.length > 0)
108
- && (
156
+ )}
157
+ {(facet.type === InputTypes.SLIDER || facetValues.length > 0) && (
109
158
  <div className={classes.sortGroup}>
110
159
  <span className={classes.sortGroupIcon}>
111
- <Icon
112
- style={{ fontSize: 10 }}
113
- onClick={onClearSection}
114
- >
115
- <img
116
- src={clearIcon}
117
- height={12}
118
- width={12}
119
- alt="clear-icon"
120
- />
160
+ <Icon style={{ fontSize: 10 }} onClick={onClearSection}>
161
+ <img src={clearIcon} height={12} width={12} alt="clear-icon" />
121
162
  </Icon>
122
163
  </span>
123
- { (facet.type === InputTypes.CHECKBOX && facetValues.length > 0)
124
- && (
125
- <>
126
- <span
127
- className={
128
- clsx(classes.sortGroupItem, {
129
- [classes.highlight]: sortBy === sortType.ALPHABET,
130
- })
131
- }
132
- onClick={() => {
133
- onSortFacet(sortType.ALPHABET);
134
- }}
135
- >
136
- Sort alphabetically
137
- </span>
138
- <span
139
- className={
140
- clsx(classes.sortGroupItemCounts, {
141
- [classes.highlight]: sortBy === sortType.NUMERIC,
142
- })
143
- }
144
- onClick={() => {
145
- onSortFacet(sortType.NUMERIC);
146
- }}
147
- >
148
- Sort by count
149
- </span>
150
- </>
151
- )}
164
+ {facet.type === InputTypes.CHECKBOX && facetValues.length > 0 && (
165
+ <>
166
+ <span
167
+ className={clsx(classes.sortGroupItem, {
168
+ [classes.highlight]: sortBy === sortType.ALPHABET,
169
+ })}
170
+ onClick={() => {
171
+ onSortFacet(sortType.ALPHABET);
172
+ }}
173
+ >
174
+ Sort alphabetically
175
+ </span>
176
+ <span
177
+ className={clsx(classes.sortGroupItemCounts, {
178
+ [classes.highlight]: sortBy === sortType.NUMERIC,
179
+ })}
180
+ onClick={() => {
181
+ onSortFacet(sortType.NUMERIC);
182
+ }}
183
+ >
184
+ Sort by count
185
+ </span>
186
+ </>
187
+ )}
152
188
  </div>
153
- )
154
- }
155
- {(expand)
156
- && (
157
- <FilterItems
158
- facet={facet}
159
- sortBy={sortBy}
160
- />
161
- )}
189
+ )}
190
+ {expand && <FilterItems facet={facet} sortBy={sortBy} />}
162
191
  </Accordion>
163
- {
164
- (!expand && type === InputTypes.CHECKBOX && selectedItems.length > 0) && (
165
- <>
166
- <List id="filter_Items">
167
- <FilterItems
168
- facet={displayFacet}
169
- />
170
- </List>
171
- </>
172
- )
173
- }
174
- {
175
- (!expand && selectedItems.length > limitCheckBoxCount) && (
176
- <div
177
- className={classes.showMore}
178
- onClick={onExpandFacet}
179
- >
180
- ...expand to see all selections
181
- </div>
182
- )
183
- }
192
+ {!expand && type === InputTypes.CHECKBOX && selectedItems.length > 0 && (
193
+ <>
194
+ <List id="filter_Items">
195
+ <FilterItems facet={displayFacet} />
196
+ </List>
197
+ </>
198
+ )}
199
+ {!expand && selectedItems.length > limitCheckBoxCount && (
200
+ <div className={classes.showMore} onClick={onExpandFacet}>
201
+ ...expand to see all selections
202
+ </div>
203
+ )}
184
204
  </>
185
205
  );
186
206
  };
@@ -1,19 +1,29 @@
1
1
  import React from 'react';
2
2
  import { connect } from 'react-redux';
3
- import { clearFacetSection, clearSliderSection } from '../../store/actions/Actions';
3
+ import {
4
+ clearFacetSection,
5
+ clearSliderSection,
6
+ toggleCheckBox,
7
+ } from '../../store/actions/Actions';
4
8
  import FacetView from './FacetView';
5
9
 
6
- const ReduxFacetView = ((props) => <FacetView {...props} />);
10
+ const ReduxFacetView = (props) => <FacetView {...props} />;
7
11
 
8
12
  const mapStateToProps = (state) => ({
9
13
  filterState: state.statusReducer.filterState,
14
+ currentActionType: state.statusReducer.currentActionType,
10
15
  autoComplete: state?.localFind?.autocomplete || [],
11
16
  upload: state?.localFind?.upload || [],
12
17
  });
13
18
 
14
19
  const mapDispatchToProps = (dispatch) => ({
15
- onClearFacetSection: (facet) => { dispatch(clearFacetSection(facet)); },
16
- onClearSliderSection: (facet) => { dispatch(clearSliderSection(facet)); },
20
+ onToggle: (facet) => dispatch(toggleCheckBox(facet)),
21
+ onClearFacetSection: (facet) => {
22
+ dispatch(clearFacetSection(facet));
23
+ },
24
+ onClearSliderSection: (facet) => {
25
+ dispatch(clearSliderSection(facet));
26
+ },
17
27
  });
18
28
 
19
29
  export default connect(mapStateToProps, mapDispatchToProps)(ReduxFacetView);
@@ -20,9 +20,11 @@ import {
20
20
  } from '@material-ui/core';
21
21
  import clsx from 'clsx';
22
22
  import {
23
- CheckBox as CheckBoxIcon, CheckBoxOutlineBlank as CheckBoxBlankIcon,
23
+ CheckBox as CheckBoxIcon,
24
+ CheckBoxOutlineBlank as CheckBoxBlankIcon,
24
25
  } from '@material-ui/icons';
25
26
  import styles from './CheckboxStyle';
27
+ import { sideBarActionTypes } from '../../../store/actions/ActionTypes';
26
28
 
27
29
  const CheckBoxView = ({
28
30
  classes,
@@ -31,12 +33,7 @@ const CheckBoxView = ({
31
33
  onToggle,
32
34
  facet,
33
35
  }) => {
34
- const {
35
- isChecked = false,
36
- index,
37
- section,
38
- tooltip,
39
- } = checkboxItem;
36
+ const { isChecked = false, index, section, tooltip } = checkboxItem;
40
37
  const {
41
38
  field = 'group',
42
39
  count = 'subjects',
@@ -53,6 +50,10 @@ const CheckBoxView = ({
53
50
  name: name,
54
51
  datafield: datafield,
55
52
  isChecked: !isChecked,
53
+ actionType: {
54
+ [datafield]: sideBarActionTypes.FACET_VALUE_CHANGED,
55
+ isFacetOrigin: true,
56
+ },
56
57
  };
57
58
  onToggle(toggleCheckBoxItem);
58
59
  };
@@ -65,9 +66,7 @@ const CheckBoxView = ({
65
66
  [`${checkedSection}NameChecked`]: isChecked,
66
67
  })}
67
68
  >
68
- <Typography className={classes.checkboxName}>
69
- {name}
70
- </Typography>
69
+ <Typography className={classes.checkboxName}>{name}</Typography>
71
70
  </Box>
72
71
  );
73
72
 
@@ -79,7 +78,9 @@ const CheckBoxView = ({
79
78
  alignItems="flex-start"
80
79
  onClick={handleToggle}
81
80
  classes={{ gutters: classes.listItemGutters }}
82
- className={clsx({ [`${checkedSection}Checked${indexType}`]: isChecked })}
81
+ className={clsx({
82
+ [`${checkedSection}Checked${indexType}`]: isChecked,
83
+ })}
83
84
  >
84
85
  <Checkbox
85
86
  id={`checkbox_${facet.label}_${name}`}
@@ -91,23 +92,21 @@ const CheckBoxView = ({
91
92
  }
92
93
  onClick={handleToggle}
93
94
  checked={isChecked}
94
- checkedIcon={(
95
+ checkedIcon={
95
96
  <CheckBoxIcon
96
97
  style={{
97
98
  fontSize: 18,
98
99
  }}
99
100
  className={`${checkedSection}CheckedIcon`}
100
101
  />
101
- )}
102
+ }
102
103
  disableRipple
103
104
  color="secondary"
104
105
  classes={{ root: classes.checkboxRoot }}
105
106
  />
106
- { tooltip ? (
107
+ {tooltip ? (
107
108
  <Tooltip id={datafield} title={tooltip}>
108
- <div className={datafield}>
109
- {name}
110
- </div>
109
+ <div className={datafield}>{name}</div>
111
110
  </Tooltip>
112
111
  ) : (
113
112
  <LabelComponent />
@@ -3,7 +3,7 @@ import { connect } from 'react-redux';
3
3
  import { toggleCheckBox } from '../../../store/actions/Actions';
4
4
  import CheckboxView from './CheckboxView';
5
5
 
6
- const ReduxCheckbox = ((props) => <CheckboxView {...props} />);
6
+ const ReduxCheckbox = (props) => <CheckboxView {...props} />;
7
7
 
8
8
  const mapStateToProps = (state) => ({
9
9
  filterState: state.statusReducer.filterState,
@@ -4,6 +4,7 @@
4
4
  /* eslint-disable object-curly-newline */
5
5
  import React, { useEffect, useState } from 'react';
6
6
  import { withStyles, Slider, Typography, Box } from '@material-ui/core';
7
+ import clsx from 'clsx';
7
8
  import styles from './SliderStyle';
8
9
  import { silderTypes } from '../Types';
9
10
  import InputMinMaxView from './InputMinMaxView';
@@ -53,8 +54,8 @@ const SliderView = ({
53
54
  return (
54
55
  <>
55
56
  <div className={classes.sliderRoot}>
56
- <div className={classes.minMaxInputs}>
57
- <div className={classes.minValue}>
57
+ <div className={clsx(classes.minMaxInputs, 'minMaxInputs')}>
58
+ <div className={clsx(classes.minValue, 'min_input_box')}>
58
59
  <Typography className={classes.minInputLabel}>
59
60
  Min:
60
61
  </Typography>
@@ -67,7 +68,7 @@ const SliderView = ({
67
68
  onInputChange={handleChangeCommittedSlider}
68
69
  />
69
70
  </div>
70
- <div className={classes.maxValue}>
71
+ <div className={clsx(classes.maxValue, 'max_input_box')}>
71
72
  <Typography className={classes.maxInputLabel}>
72
73
  Max:
73
74
  </Typography>
@@ -81,7 +82,7 @@ const SliderView = ({
81
82
  />
82
83
  </div>
83
84
  </div>
84
- <div className={classes.slider}>
85
+ <div className={clsx(classes.slider, 'slider')}>
85
86
  {/* Change to red if invalid range */}
86
87
  <Slider
87
88
  disableSwap
@@ -1,15 +1,11 @@
1
1
  import React from 'react';
2
- import {
3
- AccordionSummary,
4
- withStyles,
5
- } from '@material-ui/core';
6
- import {
7
- ExpandMore as ExpandMoreIcon,
8
- } from '@material-ui/icons';
2
+ import { AccordionSummary, withStyles } from '@material-ui/core';
3
+ import { ExpandMore as ExpandMoreIcon } from '@material-ui/icons';
9
4
  import style from './AccordionSummaryStyle';
10
5
 
11
6
  const Summary = withStyles({
12
7
  root: {
8
+ width: '307px',
13
9
  marginBottom: -1,
14
10
  minHeight: 48,
15
11
  paddingLeft: 14,
@@ -27,10 +23,7 @@ const Summary = withStyles({
27
23
  expanded: {},
28
24
  })(AccordionSummary);
29
25
 
30
- const CustomAccordionSummary = ({
31
- children,
32
- classes,
33
- }) => (
26
+ const CustomAccordionSummary = ({ children, classes }) => (
34
27
  <Summary
35
28
  expandIcon={(
36
29
  <ExpandMoreIcon
package/src/index.js CHANGED
@@ -23,6 +23,9 @@ export {
23
23
  clearSliderSection,
24
24
  clearAllAndSelectFacet,
25
25
  } from './store/actions/Actions';
26
+ export {
27
+ sideBarActionTypes,
28
+ } from './store/actions/ActionTypes';
26
29
  export {
27
30
  generateFacetSectionView,
28
31
  } from './generator/component';
@@ -30,7 +30,7 @@ export const onClearFacetSection = ({
30
30
  if (updatedState[datafield]) {
31
31
  updatedState[datafield] = {};
32
32
  }
33
- return updatedState;
33
+ return { updatedState, datafield };
34
34
  };
35
35
 
36
36
  export const onClearSliderSection = ({
@@ -64,36 +64,48 @@ export function sideBarReducerGenerator() {
64
64
  switch (type) {
65
65
  case sideBarActionTypes.FACET_VALUE_CHANGED:
66
66
  updateState = onToggleStateUpdate({ ...state, ...payload });
67
+ const { actionType = sideBarActionTypes.FACET_VALUE_CHANGED } = payload;
67
68
  return {
68
69
  ...state,
69
70
  filterState: { ...updateState },
71
+ currentActionType: actionType,
70
72
  };
71
73
  case sideBarActionTypes.ON_TOGGLE_SLIDER:
72
74
  updateState = updateSiderValue({ ...state, ...payload });
73
75
  return {
74
76
  ...state,
75
77
  filterState: { ...updateState },
78
+ currentActionType: sideBarActionTypes.ON_TOGGLE_SLIDER,
76
79
  };
77
80
  case sideBarActionTypes.CLEAR_ALL_FILTERS:
78
81
  return {
79
82
  ...state,
80
83
  filterState: {},
84
+ currentActionType: sideBarActionTypes.CLEAR_ALL_FILTERS,
81
85
  };
82
86
  case sideBarActionTypes.CLEAR_FACET_SECTION:
83
- updateState = onClearFacetSection({ ...payload, ...state });
87
+ const {
88
+ updatedState: updtState,
89
+ datafield,
90
+ } = onClearFacetSection({ ...payload, ...state });
91
+ updateState = updtState;
92
+ const currentActionType = { [datafield]: sideBarActionTypes.CLEAR_FACET_SECTION };
84
93
  return {
85
94
  ...state,
86
95
  filterState: { ...updateState },
96
+ currentActionType,
87
97
  };
88
98
  case sideBarActionTypes.CLEAR_SLIDER_SECTION:
89
99
  updateState = onClearSliderSection({ ...payload, ...state });
90
100
  return {
91
101
  ...state,
92
102
  filterState: { ...updateState },
103
+ currentActionType: sideBarActionTypes.CLEAR_SLIDER_SECTION,
93
104
  };
94
105
  case sideBarActionTypes.CLEAR_AND_SELECT_FACET_VALUE:
95
106
  return {
96
107
  filterState: payload,
108
+ currentActionType: sideBarActionTypes.CLEAR_AND_SELECT_FACET_VALUE,
97
109
  };
98
110
  default:
99
111
  return state;