@bento-core/facet-filter 1.0.1-ins.3 → 1.0.1-popsci.0

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
@@ -244,66 +244,12 @@ className={clsx(classes.sectionSummaryText, classes[facetClasses])}
244
244
  ## 10 CLearAllFilterButton Component
245
245
  Bento Core provides 1. function to clear all active filters, 2. disable flag (true incase of no active filters). Client is responsible for defining view (custom html).
246
246
  ```
247
- import { ClearAllFiltersBtn, FacetFilter } from '@bento-core/facet-filter';
248
- import { getFilters } from '@bento-core/facet-filter';
247
+ import { generateClearAllFilterBtn } from 'bento-core';
249
248
 
250
249
  const CustomClearAllFiltersBtn = ({ onClearAllFilters, disable }) => {
251
250
  //...custom component 1. bind onClearFilters fn
252
251
  // 2. disable flag to disable button
253
- }
254
- // get filter data
255
- // filterState: state.statusReducer.filterState, (from reducer)
256
- // const activeFilters = getFilters(filterState) // formating
257
-
258
- <ClearAllFiltersBtn
259
- Component={CustomClearAllFiltersBtn}
260
- activeFilters={activeFilters}
261
- />
262
- ```
263
-
264
- ## 11 Facet Value Component
265
- ```
266
- // response
267
- // filterCaseCountByProgram: [{group: "COP", subjects: 301}]
268
- const {
269
- name,
270
- customName,
271
- subjects,
272
- customSubjects,
273
- tooltip,
274
- } = checkboxItem;
275
-
276
- // 1. by default facet value component display group ("COP")
277
- // 2. set customName to display customize value
278
- // 3. by default facet value component display subjects (301)
279
- // 4. set customSubjects to display customize value or adjust correct field for subject count
280
- // 5. tooltip - provide text value to tooltip text
281
-
282
- /**
283
- * Add Bento frontend filter count/subjects
284
- * Add tootip text
285
- */
286
- const filterData = facetsConfig.reduce((acc, item) => {
287
- const facetValues = searchData[item.apiPath];
288
- if (!facetValues) {
289
- return acc;
290
- }
291
- const subjectCounts = [...facetValues].map((checkbox) => {
292
- const text = tooltipText[item.tooltipKey];
293
- return {
294
- ...checkbox,
295
- customSubjects: checkbox.count,
296
- tooltip: text ? text[checkbox.group] : undefined,
297
- };
298
- });
299
- return { ...acc, [item.apiPath]: [...subjectCounts] };
300
- }, {});
252
+ }
301
253
 
302
- <FacetFilter
303
- data={filterData}
304
- facetSectionConfig={facetSectionVariables}
305
- facetsConfig={facetsConfig}
306
- CustomFacetSection={CustomFacetSection}
307
- CustomFacetView={CustomFacetView}
308
- />
254
+ const ClearAllFiltersButton = () => generateClearAllFilterBtn(CustomClearAllFiltersBtn);
309
255
  ```
@@ -26,18 +26,11 @@ const FacetFilterController = props => {
26
26
  * 2. subject state
27
27
  */
28
28
  const {
29
- activeFilters,
29
+ filterState,
30
30
  data,
31
31
  facetsConfig,
32
32
  facetSectionConfig
33
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
- }
41
34
  const updateFacetState = filterSections => {
42
35
  const updateSections = [...filterSections];
43
36
  if (!_lodash.default.isEmpty(filterState)) {
@@ -45,8 +38,7 @@ const FacetFilterController = props => {
45
38
  updateSections.forEach(sideBar => {
46
39
  if (sideBar.type === _Types.InputTypes.CHECKBOX && sideBar.datafield === key) {
47
40
  sideBar.facetValues.forEach(item => {
48
- // item.isChecked = value[item.name] ? value[item.name] : false;
49
- item.isChecked = value.indexOf(item.name) > -1;
41
+ item.isChecked = value[item.name] ? value[item.name] : false;
50
42
  });
51
43
  }
52
44
  if (sideBar.type === _Types.InputTypes.SLIDER && sideBar.datafield === key) {
@@ -120,30 +112,11 @@ const FacetFilterController = props => {
120
112
  } = updateFacet;
121
113
  if (data[apiForFiltering]) {
122
114
  if (Array.isArray(data[apiForFiltering])) {
123
- const validValues = [];
124
115
  const updateField = data[apiForFiltering].map(item => {
125
116
  const addField = _objectSpread({}, item);
126
117
  addField.name = item[field];
127
- validValues.push(addField.name);
128
118
  return addField;
129
119
  });
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
120
  updateFacet.facetValues = updateField;
148
121
  }
149
122
  /**
@@ -167,7 +140,7 @@ const FacetFilterController = props => {
167
140
  * Generate facet sections state
168
141
  *
169
142
  */
170
- const displayFacets = facetsConfig.filter(facet => facet.show);
143
+ const displayFacets = facetsConfig.filter(facet => facet.show).slice(0, 16);
171
144
  const facetStates = addFacetValues(displayFacets);
172
145
  const updateState = updateFacetState(facetStates);
173
146
  const facetSections = arrangeBySections(updateState);
@@ -9,6 +9,7 @@ var _core = require("@material-ui/core");
9
9
  var _FacetFilterStyle = _interopRequireDefault(require("./FacetFilterStyle"));
10
10
  var _FacetSectionView = _interopRequireDefault(require("./components/section/FacetSectionView"));
11
11
  var _ReduxFacetView = _interopRequireDefault(require("./components/facet/ReduxFacetView"));
12
+ var _FilterItems = _interopRequireDefault(require("./components/inputs/FilterItems"));
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14
  /* eslint-disable arrow-body-style */
14
15
  /* eslint-disable padded-blocks */
@@ -28,7 +29,11 @@ const BentoFacetFilter = _ref => {
28
29
  }, section.items.map(facet => /*#__PURE__*/_react.default.createElement(_ReduxFacetView.default, {
29
30
  facet: facet,
30
31
  CustomView: CustomFacetView
31
- }))))));
32
+ }, /*#__PURE__*/_react.default.createElement(_core.List, {
33
+ className: "List_".concat(facet.label)
34
+ }, /*#__PURE__*/_react.default.createElement(_FilterItems.default, {
35
+ facet: facet
36
+ }))))))));
32
37
  };
33
38
  var _default = (0, _core.withStyles)(_FacetFilterStyle.default)(BentoFacetFilter);
34
39
  exports.default = _default;
@@ -31,12 +31,12 @@ const FacetView = _ref => {
31
31
  autoComplete,
32
32
  upload
33
33
  } = _ref;
34
- const [expand, setExpand] = (0, _react.useState)(true);
34
+ const [expand, setExpand] = (0, _react.useState)(false);
35
35
  const onExpandFacet = () => setExpand(!expand);
36
36
 
37
37
  /**
38
- * expand section incase of active local search
39
- */
38
+ * expand section incase of active local search
39
+ */
40
40
  (0, _react.useEffect)(() => {
41
41
  if (autoComplete && autoComplete.length > 0 || upload && upload.length > 0) {
42
42
  setExpand(true);
@@ -82,11 +82,11 @@ const FacetView = _ref => {
82
82
  className: (0, _clsx.default)(classes.subSectionSummaryText, {
83
83
  ["activeFacet".concat(facet.section)]: isActiveFacet
84
84
  })
85
- }, facet.label)), (facet.type === _Types.InputTypes.SLIDER || facetValues.length === 0) && /*#__PURE__*/_react.default.createElement("div", {
85
+ }, facet.label)), facetValues.length === 0 && /*#__PURE__*/_react.default.createElement("div", {
86
86
  className: classes.NonSortGroup
87
87
  }, /*#__PURE__*/_react.default.createElement("span", {
88
88
  className: classes.NonSortGroupItem
89
- }, "No data for this field")), (facet.type === _Types.InputTypes.SLIDER || facetValues.length > 0) && /*#__PURE__*/_react.default.createElement("div", {
89
+ }, "No data for this field")), facetValues.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
90
90
  className: classes.sortGroup
91
91
  }, /*#__PURE__*/_react.default.createElement("span", {
92
92
  className: classes.sortGroupIcon
@@ -18,8 +18,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
18
  /* eslint-disable object-curly-newline */
19
19
  /* eslint-disable object-shorthand */
20
20
  /* eslint-disable react/jsx-one-expression-per-line */
21
- /* eslint-disable no-useless-escape */
22
21
 
22
+ const alignment = 'flex-start';
23
23
  const CheckBoxView = _ref => {
24
24
  let {
25
25
  classes,
@@ -29,19 +29,16 @@ const CheckBoxView = _ref => {
29
29
  facet
30
30
  } = _ref;
31
31
  const {
32
+ name,
33
+ subjects,
32
34
  isChecked = false,
33
35
  index,
34
36
  section,
35
- tooltip
37
+ tooltip,
38
+ label
36
39
  } = checkboxItem;
37
- const {
38
- field = 'group',
39
- count = 'subjects',
40
- customCount = text => "(".concat(text, ")")
41
- } = facet;
42
40
  const indexType = index % 2 === 0 ? 'Even' : 'Odd';
43
- const checkedSection = "".concat(section).toLowerCase().replace(/\ /g, '_');
44
- const name = checkboxItem[field] || 'N/A';
41
+ const checkedSection = "".concat(section).toLowerCase().replace(' ', '_');
45
42
  const handleToggle = () => {
46
43
  const toggleCheckBoxItem = {
47
44
  name: name,
@@ -56,7 +53,9 @@ const CheckBoxView = _ref => {
56
53
  ["".concat(checkedSection, "NameUnChecked")]: !isChecked,
57
54
  ["".concat(checkedSection, "NameChecked")]: isChecked
58
55
  })
59
- }, /*#__PURE__*/_react.default.createElement(_core.Typography, {
56
+ }, label ? /*#__PURE__*/_react.default.createElement(_core.Typography, {
57
+ className: classes.checkboxLabel
58
+ }, label) : /*#__PURE__*/_react.default.createElement(_core.Typography, {
60
59
  className: classes.checkboxName
61
60
  }, name));
62
61
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.ListItem, {
@@ -75,8 +74,7 @@ const CheckBoxView = _ref => {
75
74
  icon: /*#__PURE__*/_react.default.createElement(_icons.CheckBoxOutlineBlank, {
76
75
  style: {
77
76
  fontSize: 18
78
- },
79
- className: checkedSection
77
+ }
80
78
  }),
81
79
  onClick: handleToggle,
82
80
  checked: isChecked,
@@ -96,14 +94,12 @@ const CheckBoxView = _ref => {
96
94
  title: tooltip
97
95
  }, /*#__PURE__*/_react.default.createElement("div", {
98
96
  className: datafield
99
- }, name)) : /*#__PURE__*/_react.default.createElement(LabelComponent, null), /*#__PURE__*/_react.default.createElement(_core.ListItemText, {
100
- className: "".concat(checkedSection, "_md_space")
101
- }), /*#__PURE__*/_react.default.createElement(_core.Typography, {
97
+ }, /*#__PURE__*/_react.default.createElement(LabelComponent, null))) : /*#__PURE__*/_react.default.createElement(LabelComponent, null), /*#__PURE__*/_react.default.createElement(_core.ListItemText, null), /*#__PURE__*/_react.default.createElement(_core.Typography, {
102
98
  className: (0, _clsx.default)("".concat(checkedSection, "Subjects"), {
103
99
  ["".concat(checkedSection, "SubjectUnChecked")]: !isChecked,
104
100
  ["".concat(checkedSection, "SubjectChecked")]: isChecked
105
101
  })
106
- }, customCount(checkboxItem[count] || 0))), /*#__PURE__*/_react.default.createElement(_core.Divider, {
102
+ }, "(".concat(subjects, ")"))), /*#__PURE__*/_react.default.createElement(_core.Divider, {
107
103
  style: {
108
104
  backgroundColor: isChecked ? '#FFFFFF' : '#b1b1b1',
109
105
  margin: '0px',
@@ -46,35 +46,33 @@ const sortBySection = _ref => {
46
46
  let {
47
47
  facetValues,
48
48
  sort_type,
49
- sortBy,
50
- field,
51
- count = 'subjects'
49
+ sortBy
52
50
  } = _ref;
53
51
  const sortfacetValues = [...facetValues];
54
52
  if (!sortfacetValues) {
55
53
  return facetValues;
56
54
  }
57
55
  if (sortBy === sortType.NUMERIC) {
58
- sortfacetValues.sort((a, b) => b[count] - a[count]);
56
+ sortfacetValues.sort((a, b) => b.subjects - a.subjects);
59
57
  } else {
60
- sortfacetValues.sort((a, b) => lowerCaseString(a[field]) > lowerCaseString(b[field]) || -(lowerCaseString(a[field]) < lowerCaseString(b[field])));
58
+ sortfacetValues.sort((a, b) => lowerCaseString(a.name) > lowerCaseString(b.name) || -(lowerCaseString(a.name) < lowerCaseString(b.name)));
61
59
  }
62
60
  if (sort_type === sortType.CUSTOM_NUMBER && sortBy !== sortType.NUMERIC) {
63
61
  sortfacetValues.sort((a, b) => {
64
- const aNumbs = getNumberArray(a[field]);
65
- const bNumbs = getNumberArray(b[field]);
62
+ const aNumbs = getNumberArray(a.name);
63
+ const bNumbs = getNumberArray(b.name);
66
64
  const aNumb = Number(aNumbs[0]);
67
65
  const bNumb = Number(bNumbs[0]);
68
66
  return aNumbs.length === bNumbs.length ? aNumb > bNumb : -(aNumb <= bNumb);
69
67
  });
70
68
  }
71
69
  if (sort_type === sortType.RANGE && sortBy !== sortType.NUMERIC) {
72
- sortfacetValues.sort((a, b) => startIndex(a[field]) > startIndex(b[field]) || -(startIndex(a[field]) < startIndex(b[field])));
70
+ sortfacetValues.sort((a, b) => startIndex(a.name) > startIndex(b.name) || -(startIndex(a.name) < startIndex(b.name)));
73
71
  }
74
72
  /**
75
73
  * Display checked item always on top
76
74
  */
77
- // const sortedValues = sortByCheckedItem([...sortfacetValues]);
78
- return sortfacetValues;
75
+ const sortedValues = sortByCheckedItem([...sortfacetValues]);
76
+ return sortedValues;
79
77
  };
80
78
  exports.sortBySection = sortBySection;
package/package.json CHANGED
@@ -1,17 +1,14 @@
1
1
  {
2
2
  "name": "@bento-core/facet-filter",
3
- "version": "1.0.1-ins.3",
4
- "description": "### Bento core sidebar design:",
3
+ "version": "1.0.1-popsci.0",
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
  },
@@ -28,8 +25,5 @@
28
25
  },
29
26
  "author": "CTOS Bento Team",
30
27
  "license": "ISC",
31
- "bugs": {
32
- "url": "https://github.com/CBIIT/bento-frontend/issues"
33
- },
34
- "homepage": "https://github.com/CBIIT/bento-frontend#readme"
28
+ "gitHead": "38d37ee5dd6ce60b6320cbeeaa458ad7a5710dbb"
35
29
  }
@@ -21,20 +21,12 @@ const FacetFilterController = (props) => {
21
21
  * 2. subject state
22
22
  */
23
23
  const {
24
- activeFilters,
24
+ filterState,
25
25
  data,
26
26
  facetsConfig,
27
27
  facetSectionConfig,
28
28
  } = props;
29
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
-
38
30
  const updateFacetState = (filterSections) => {
39
31
  const updateSections = [...filterSections];
40
32
  if (!_.isEmpty(filterState)) {
@@ -42,8 +34,7 @@ const FacetFilterController = (props) => {
42
34
  updateSections.forEach((sideBar) => {
43
35
  if (sideBar.type === InputTypes.CHECKBOX && sideBar.datafield === key) {
44
36
  sideBar.facetValues.forEach((item) => {
45
- // item.isChecked = value[item.name] ? value[item.name] : false;
46
- item.isChecked = value.indexOf(item.name) > -1;
37
+ item.isChecked = value[item.name] ? value[item.name] : false;
47
38
  });
48
39
  }
49
40
  if (sideBar.type === InputTypes.SLIDER && sideBar.datafield === key) {
@@ -106,30 +97,11 @@ const FacetFilterController = (props) => {
106
97
  } = updateFacet;
107
98
  if (data[apiForFiltering]) {
108
99
  if (Array.isArray(data[apiForFiltering])) {
109
- const validValues = [];
110
100
  const updateField = data[apiForFiltering].map((item) => {
111
101
  const addField = { ...item };
112
102
  addField.name = item[field];
113
- validValues.push(addField.name);
114
103
  return addField;
115
104
  });
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
105
  updateFacet.facetValues = updateField;
134
106
  }
135
107
  /**
@@ -153,7 +125,7 @@ const FacetFilterController = (props) => {
153
125
  * Generate facet sections state
154
126
  *
155
127
  */
156
- const displayFacets = facetsConfig.filter((facet) => facet.show);
128
+ const displayFacets = facetsConfig.filter((facet) => facet.show).slice(0, 16);
157
129
  const facetStates = addFacetValues(displayFacets);
158
130
  const updateState = updateFacetState(facetStates);
159
131
  const facetSections = arrangeBySections(updateState);
@@ -3,11 +3,13 @@
3
3
  import React from 'react';
4
4
  import {
5
5
  Divider,
6
+ List,
6
7
  withStyles,
7
8
  } from '@material-ui/core';
8
9
  import styles from './FacetFilterStyle';
9
10
  import FacetSectionView from './components/section/FacetSectionView';
10
11
  import FacetView from './components/facet/ReduxFacetView';
12
+ import FilterItems from './components/inputs/FilterItems';
11
13
 
12
14
  const BentoFacetFilter = ({
13
15
  sideBarSections,
@@ -31,7 +33,13 @@ const BentoFacetFilter = ({
31
33
  <FacetView
32
34
  facet={facet}
33
35
  CustomView={CustomFacetView}
34
- />
36
+ >
37
+ <List className={`List_${facet.label}`}>
38
+ <FilterItems
39
+ facet={facet}
40
+ />
41
+ </List>
42
+ </FacetView>
35
43
  ))}
36
44
  </FacetSectionView>
37
45
  </>
@@ -1,9 +1,6 @@
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';
9
6
  import CustomAccordionSummary from '../summary/AccordionSummaryView';
@@ -22,15 +19,17 @@ const FacetView = ({
22
19
  autoComplete,
23
20
  upload,
24
21
  }) => {
25
- const [expand, setExpand] = useState(true);
22
+ const [expand, setExpand] = useState(false);
26
23
  const onExpandFacet = () => setExpand(!expand);
27
24
 
28
25
  /**
29
- * expand section incase of active local search
30
- */
26
+ * expand section incase of active local search
27
+ */
31
28
  useEffect(() => {
32
- if ((autoComplete && autoComplete.length > 0)
33
- || (upload && upload.length > 0)) {
29
+ if (
30
+ (autoComplete && autoComplete.length > 0)
31
+ || (upload && upload.length > 0)
32
+ ) {
34
33
  setExpand(true);
35
34
  }
36
35
  }, [autoComplete, upload]);
@@ -68,21 +67,20 @@ const FacetView = ({
68
67
  }}
69
68
  id={facet.section}
70
69
  >
71
- { CustomView ? (
70
+ {CustomView ? (
72
71
  <CustomView
73
72
  facet={facet}
74
73
  facetClasses={
75
- isActiveFacet ? `activeFacet${facet.section}`
76
- : `inactiveFacet${facet.section}`
74
+ isActiveFacet
75
+ ? `activeFacet${facet.section}`
76
+ : `inactiveFacet${facet.section}`
77
77
  }
78
78
  />
79
79
  ) : (
80
80
  <CustomAccordionSummary>
81
81
  <div
82
- id={
83
- `filterGroup_ ${facet.datafield}
84
- ${facet.label}`
85
- }
82
+ id={`filterGroup_ ${facet.datafield}
83
+ ${facet.label}`}
86
84
  className={clsx(classes.subSectionSummaryText, {
87
85
  [`activeFacet${facet.section}`]: isActiveFacet,
88
86
  })}
@@ -91,96 +89,60 @@ const FacetView = ({
91
89
  </div>
92
90
  </CustomAccordionSummary>
93
91
  )}
94
- {
95
- (facet.type === InputTypes.SLIDER || facetValues.length === 0)
96
- && (
92
+ {facetValues.length === 0 && (
97
93
  <div className={classes.NonSortGroup}>
98
- <span
99
- className={classes.NonSortGroupItem}
100
- >
94
+ <span className={classes.NonSortGroupItem}>
101
95
  No data for this field
102
96
  </span>
103
97
  </div>
104
- )
105
- }
106
- {
107
- (facet.type === InputTypes.SLIDER || facetValues.length > 0)
108
- && (
98
+ )}
99
+ {facetValues.length > 0 && (
109
100
  <div className={classes.sortGroup}>
110
101
  <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
- />
102
+ <Icon style={{ fontSize: 10 }} onClick={onClearSection}>
103
+ <img src={clearIcon} height={12} width={12} alt="clear-icon" />
121
104
  </Icon>
122
105
  </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
- )}
106
+ {facet.type === InputTypes.CHECKBOX && facetValues.length > 0 && (
107
+ <>
108
+ <span
109
+ className={clsx(classes.sortGroupItem, {
110
+ [classes.highlight]: sortBy === sortType.ALPHABET,
111
+ })}
112
+ onClick={() => {
113
+ onSortFacet(sortType.ALPHABET);
114
+ }}
115
+ >
116
+ Sort alphabetically
117
+ </span>
118
+ <span
119
+ className={clsx(classes.sortGroupItemCounts, {
120
+ [classes.highlight]: sortBy === sortType.NUMERIC,
121
+ })}
122
+ onClick={() => {
123
+ onSortFacet(sortType.NUMERIC);
124
+ }}
125
+ >
126
+ Sort by count
127
+ </span>
128
+ </>
129
+ )}
152
130
  </div>
153
- )
154
- }
155
- {(expand)
156
- && (
157
- <FilterItems
158
- facet={facet}
159
- sortBy={sortBy}
160
- />
161
- )}
131
+ )}
132
+ {expand && <FilterItems facet={facet} sortBy={sortBy} />}
162
133
  </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
- }
134
+ {!expand && type === InputTypes.CHECKBOX && selectedItems.length > 0 && (
135
+ <>
136
+ <List id="filter_Items">
137
+ <FilterItems facet={displayFacet} />
138
+ </List>
139
+ </>
140
+ )}
141
+ {!expand && selectedItems.length > limitCheckBoxCount && (
142
+ <div className={classes.showMore} onClick={onExpandFacet}>
143
+ ...expand to see all selections
144
+ </div>
145
+ )}
184
146
  </>
185
147
  );
186
148
  };
@@ -5,8 +5,6 @@
5
5
  /* eslint-disable object-curly-newline */
6
6
  /* eslint-disable object-shorthand */
7
7
  /* eslint-disable react/jsx-one-expression-per-line */
8
- /* eslint-disable no-useless-escape */
9
-
10
8
  import React from 'react';
11
9
  import { withStyles } from '@material-ui/core/styles';
12
10
  import {
@@ -24,6 +22,8 @@ import {
24
22
  } from '@material-ui/icons';
25
23
  import styles from './CheckboxStyle';
26
24
 
25
+ const alignment = 'flex-start';
26
+
27
27
  const CheckBoxView = ({
28
28
  classes,
29
29
  checkboxItem,
@@ -32,21 +32,16 @@ const CheckBoxView = ({
32
32
  facet,
33
33
  }) => {
34
34
  const {
35
+ name,
36
+ subjects,
35
37
  isChecked = false,
36
38
  index,
37
39
  section,
38
40
  tooltip,
41
+ label,
39
42
  } = checkboxItem;
40
- const {
41
- field = 'group',
42
- count = 'subjects',
43
- customCount = (text) => `(${text})`,
44
- } = facet;
45
-
46
43
  const indexType = index % 2 === 0 ? 'Even' : 'Odd';
47
- const checkedSection = `${section}`.toLowerCase().replace(/\ /g, '_');
48
-
49
- const name = checkboxItem[field] || 'N/A';
44
+ const checkedSection = `${section}`.toLowerCase().replace(' ', '_');
50
45
 
51
46
  const handleToggle = () => {
52
47
  const toggleCheckBoxItem = {
@@ -65,9 +60,9 @@ const CheckBoxView = ({
65
60
  [`${checkedSection}NameChecked`]: isChecked,
66
61
  })}
67
62
  >
68
- <Typography className={classes.checkboxName}>
69
- {name}
70
- </Typography>
63
+ {label ? (
64
+ <Typography className={classes.checkboxLabel}>{label}</Typography>
65
+ ) : (<Typography className={classes.checkboxName}>{name}</Typography>)}
71
66
  </Box>
72
67
  );
73
68
 
@@ -83,12 +78,7 @@ const CheckBoxView = ({
83
78
  >
84
79
  <Checkbox
85
80
  id={`checkbox_${facet.label}_${name}`}
86
- icon={
87
- <CheckBoxBlankIcon
88
- style={{ fontSize: 18 }}
89
- className={checkedSection}
90
- />
91
- }
81
+ icon={<CheckBoxBlankIcon style={{ fontSize: 18 }} />}
92
82
  onClick={handleToggle}
93
83
  checked={isChecked}
94
84
  checkedIcon={(
@@ -106,20 +96,20 @@ const CheckBoxView = ({
106
96
  { tooltip ? (
107
97
  <Tooltip id={datafield} title={tooltip}>
108
98
  <div className={datafield}>
109
- {name}
99
+ <LabelComponent />
110
100
  </div>
111
101
  </Tooltip>
112
102
  ) : (
113
103
  <LabelComponent />
114
104
  )}
115
- <ListItemText className={`${checkedSection}_md_space`} />
105
+ <ListItemText />
116
106
  <Typography
117
107
  className={clsx(`${checkedSection}Subjects`, {
118
108
  [`${checkedSection}SubjectUnChecked`]: !isChecked,
119
109
  [`${checkedSection}SubjectChecked`]: isChecked,
120
110
  })}
121
111
  >
122
- {customCount(checkboxItem[count] || 0)}
112
+ {`(${subjects})`}
123
113
  </Typography>
124
114
  </ListItem>
125
115
  <Divider
package/src/utils/Sort.js CHANGED
@@ -37,28 +37,22 @@ export const getNumberArray = (range) => {
37
37
  * @param {array} checkboxData
38
38
  * @return {array}
39
39
  */
40
- export const sortBySection = ({
41
- facetValues,
42
- sort_type,
43
- sortBy,
44
- field,
45
- count = 'subjects',
46
- }) => {
40
+ export const sortBySection = ({ facetValues, sort_type, sortBy }) => {
47
41
  const sortfacetValues = [...facetValues];
48
42
  if (!sortfacetValues) {
49
43
  return facetValues;
50
44
  }
51
45
  if (sortBy === sortType.NUMERIC) {
52
- sortfacetValues.sort((a, b) => b[count] - a[count]);
46
+ sortfacetValues.sort((a, b) => b.subjects - a.subjects);
53
47
  } else {
54
- sortfacetValues.sort(((a, b) => (lowerCaseString(a[field]) > lowerCaseString(b[field])
55
- || -(lowerCaseString(a[field]) < lowerCaseString(b[field])))));
48
+ sortfacetValues.sort(((a, b) => (lowerCaseString(a.name) > lowerCaseString(b.name)
49
+ || -(lowerCaseString(a.name) < lowerCaseString(b.name)))));
56
50
  }
57
51
 
58
52
  if (sort_type === sortType.CUSTOM_NUMBER && sortBy !== sortType.NUMERIC) {
59
53
  sortfacetValues.sort((a, b) => {
60
- const aNumbs = getNumberArray(a[field]);
61
- const bNumbs = getNumberArray(b[field]);
54
+ const aNumbs = getNumberArray(a.name);
55
+ const bNumbs = getNumberArray(b.name);
62
56
  const aNumb = Number(aNumbs[0]);
63
57
  const bNumb = Number(bNumbs[0]);
64
58
  return (aNumbs.length === bNumbs.length) ? aNumb > bNumb : -(aNumb <= bNumb);
@@ -66,12 +60,12 @@ export const sortBySection = ({
66
60
  }
67
61
 
68
62
  if (sort_type === sortType.RANGE && sortBy !== sortType.NUMERIC) {
69
- sortfacetValues.sort(((a, b) => (startIndex(a[field]) > startIndex(b[field])
70
- || -(startIndex(a[field]) < startIndex(b[field])))));
63
+ sortfacetValues.sort(((a, b) => (startIndex(a.name) > startIndex(b.name)
64
+ || -(startIndex(a.name) < startIndex(b.name)))));
71
65
  }
72
66
  /**
73
67
  * Display checked item always on top
74
68
  */
75
- // const sortedValues = sortByCheckedItem([...sortfacetValues]);
76
- return sortfacetValues;
69
+ const sortedValues = sortByCheckedItem([...sortfacetValues]);
70
+ return sortedValues;
77
71
  };