@bento-core/query-bar 1.0.1-icdc.2 → 1.0.1-icdc.21

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
@@ -58,6 +58,11 @@ const CONFIG = {
58
58
  * @var {number}
59
59
  */
60
60
  maxItems: 2,
61
+ /**
62
+ * overirdes maxItems to display all the active filter items
63
+ * @var {boolean}
64
+ */
65
+ displayAllActiveFilters: false,
61
66
  },
62
67
 
63
68
  /* Component Helper Functions */
@@ -139,4 +144,4 @@ This component, which is generated by the provided generator, accepts the follow
139
144
  />
140
145
  ```
141
146
 
142
- > **Warning**: The `statusReducer` prop requires the dashboard API data merged with the `facetsConfig` property. Please see the example in the demo implementation [here](https://github.com/CBIIT/bento-frontend/blob/7efd62cd3da0c29326e523055d30118244dc2f2f/packages/bento-frontend/src/pages/dashTemplate/filterQueryBar/QueryBarView.js#LL20C14-L20C14).
147
+ > **Warning**: The `statusReducer` prop requires the dashboard API data merged with the `facetsConfig` property. Please see the example in the demo implementation [here](https://github.com/CBIIT/bento-frontend/blob/7efd62cd3da0c29326e523055d30118244dc2f2f/packages/bento-frontend/src/pages/dashTemplate/filterQueryBar/QueryBarView.js#LL20C14-L20C14).
@@ -0,0 +1,3 @@
1
+ <svg width="16" height="19" viewBox="0 0 16 19" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M13 9.75715C13 10.0452 12.78 10.2714 12.5 10.2714H7.5C7.22 10.2714 7 10.0452 7 9.75715C7 9.46915 7.22 9.24287 7.5 9.24287H12.5C12.78 9.24287 13 9.46915 13 9.75715ZM12.5 11.3H7.5C7.22 11.3 7 11.5263 7 11.8143C7 12.1023 7.22 12.3286 7.5 12.3286H12.5C12.78 12.3286 13 12.1023 13 11.8143C13 11.5263 12.78 11.3 12.5 11.3ZM12.5 13.3572H7.5C7.22 13.3572 7 13.5834 7 13.8714C7 14.1594 7.22 14.3857 7.5 14.3857H12.5C12.78 14.3857 13 14.1594 13 13.8714C13 13.5834 12.78 13.3572 12.5 13.3572ZM16 8.21429V16.4429C16 17.5743 15.1 18.5 14 18.5H6C4.9 18.5 4 17.5743 4 16.4429V15.4143H2C0.9 15.4143 0 14.4886 0 13.3572V4.10001C0 2.96858 0.9 2.04286 2 2.04286H4.5C4.5 1.18915 5.17 0.500008 6 0.500008C6.83 0.500008 7.5 1.18915 7.5 2.04286H10C11.1 2.04286 12 2.96858 12 4.10001V6.15715H14C15.1 6.15715 16 7.08287 16 8.21429ZM6 6.15715H11V4.10001C11 3.53429 10.55 3.07144 10 3.07144H9V4.10001H3V3.07144H2C1.45 3.07144 1 3.53429 1 4.10001V13.3572C1 13.9229 1.45 14.3857 2 14.3857H4V8.21429C4 7.08287 4.9 6.15715 6 6.15715ZM15 8.21429C15 7.64858 14.55 7.18572 14 7.18572H6C5.45 7.18572 5 7.64858 5 8.21429V16.4429C5 17.0086 5.45 17.4714 6 17.4714H14C14.55 17.4714 15 17.0086 15 16.4429V8.21429Z" fill="#142D64"/>
3
+ </svg>
@@ -16,20 +16,14 @@ var _default = _ref => {
16
16
  classes,
17
17
  maxItems,
18
18
  onSectionClick,
19
- onItemClick,
20
- displayAllActiveFilters
19
+ onItemClick
21
20
  } = _ref;
22
21
  const {
23
22
  items,
24
23
  section
25
24
  } = data;
26
- const [expand, setExpand] = (0, _react.useState)(false);
25
+ const [expand, setExpand] = (0, _react.useState)(true);
27
26
  const noOfItems = expand ? items.length : maxItems;
28
- (0, _react.useEffect)(() => {
29
- if (items.length <= maxItems && expand) {
30
- setExpand(!expand);
31
- }
32
- }, [items]);
33
27
  const clsName = function clsName() {
34
28
  let text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
35
29
  let attr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
@@ -48,10 +42,10 @@ var _default = _ref => {
48
42
  className: (0, _clsx.default)(classes.filterCheckboxes, classes[clsName(section)]),
49
43
  key: idx,
50
44
  onClick: () => onItemClick(data, d)
51
- }, d), idx === maxItems - 1 ? null : ' ')), items.length > maxItems && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, displayAllActiveFilters ? /*#__PURE__*/_react.default.createElement("span", {
45
+ }, d), idx === maxItems - 1 ? null : ' ')), items.length > maxItems && !expand && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
52
46
  className: classes.expandBtn,
53
47
  onClick: () => setExpand(!expand)
54
- }, "...") : '...'), expand && items.length > maxItems && /*#__PURE__*/_react.default.createElement("span", {
48
+ }, "...")), expand && items.length > maxItems && /*#__PURE__*/_react.default.createElement("span", {
55
49
  className: classes.collapseBtn,
56
50
  onClick: () => setExpand(!expand)
57
51
  }, ' LESS'), items.length > 1 && /*#__PURE__*/_react.default.createElement("span", {
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _clsx = _interopRequireDefault(require("clsx"));
9
+ var _core = require("@material-ui/core");
10
+ var _CopyIcon = _interopRequireDefault(require("../assets/CopyIcon.svg"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ 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); }
13
+ 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; }
14
+ 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; }
15
+ 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; }
16
+ 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; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
+ 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); }
19
+ const QueryUrl = _ref => {
20
+ let {
21
+ classes,
22
+ filterItems,
23
+ localFind = {},
24
+ rootPath
25
+ } = _ref;
26
+ const [display, setDisplay] = (0, _react.useState)(false);
27
+ const toggleDisplay = () => setDisplay(!display);
28
+ const [open, toggleOpen] = (0, _react.useState)(false);
29
+ const pathFilterParams = filterItems.reduce((acc, item) => {
30
+ const {
31
+ datafield,
32
+ items = []
33
+ } = item;
34
+ acc[datafield] = items;
35
+ return acc;
36
+ }, {});
37
+ const query = JSON.stringify(_objectSpread(_objectSpread({}, pathFilterParams), localFind));
38
+ const url = encodeURI(rootPath.concat(query));
39
+ const copyUrl = async () => {
40
+ toggleOpen(!open);
41
+ await navigator.clipboard.writeText(url);
42
+ };
43
+ const queryRef = (0, _react.useRef)(null);
44
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
45
+ ref: queryRef,
46
+ className: classes.urlContainer
47
+ }, /*#__PURE__*/_react.default.createElement(_core.Button, {
48
+ onClick: toggleDisplay,
49
+ className: classes.viewLinkToggleBtn
50
+ }, display ? 'Hide Query URL' : 'Show Query URL'), display && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
51
+ type: "button",
52
+ className: (0, _clsx.default)(classes.viewLink)
53
+ }, url), /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
54
+ arrow: true,
55
+ title: "Copy to Clipboard"
56
+ }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
57
+ onClick: copyUrl,
58
+ className: classes.copyIconBtn
59
+ }, /*#__PURE__*/_react.default.createElement("img", {
60
+ src: _CopyIcon.default,
61
+ alt: "copy icon"
62
+ }))))), /*#__PURE__*/_react.default.createElement(_core.Dialog, {
63
+ open: open,
64
+ onClose: () => toggleOpen(!open),
65
+ "aria-labelledby": "alert-dialog-title",
66
+ "aria-describedby": "alert-dialog-description",
67
+ className: (0, _clsx.default)(classes.dialogBox, 'dialogBox')
68
+ }, /*#__PURE__*/_react.default.createElement(_core.DialogContent, {
69
+ className: classes.okText
70
+ }, /*#__PURE__*/_react.default.createElement(_core.DialogContentText, {
71
+ id: "alert-dialog-description"
72
+ }, "Your query URL has been copied!")), /*#__PURE__*/_react.default.createElement(_core.DialogActions, null, /*#__PURE__*/_react.default.createElement(_core.Button, {
73
+ onClick: () => toggleOpen(!open)
74
+ }, "OK"))));
75
+ };
76
+ const styles = () => ({
77
+ urlContainer: {
78
+ display: 'flex',
79
+ marginTop: '3px',
80
+ minHeight: '10px'
81
+ },
82
+ viewLink: {
83
+ overflow: 'hidden',
84
+ textOverflow: 'ellipsis',
85
+ fontFamily: 'Nunito',
86
+ fontSize: '12px',
87
+ fontWeight: '500',
88
+ lineHeight: '16px',
89
+ letterSpacing: '0em',
90
+ padding: '2px 5px',
91
+ borderRadius: '5px',
92
+ float: 'left',
93
+ color: '#1D79A8',
94
+ backgroundColor: '#fff',
95
+ margin: '0',
96
+ whiteSpace: 'nowrap',
97
+ wordBreak: 'break-all',
98
+ '@media (max-width: 2560px)': {
99
+ maxWidth: '1800px'
100
+ },
101
+ '@media (max-width: 2000px)': {
102
+ maxWidth: '1500px'
103
+ },
104
+ '@media (max-width: 1600px)': {
105
+ maxWidth: '1100px'
106
+ },
107
+ '@media (max-width: 1300px)': {
108
+ maxWidth: '900px'
109
+ }
110
+ },
111
+ urlViewBtn: {
112
+ cursor: 'pointer'
113
+ },
114
+ viewLinkToggleBtn: {
115
+ padding: '5px 10px 5px 10px',
116
+ height: '20px',
117
+ fontFamily: 'Nunito',
118
+ fontSize: '12px',
119
+ fontWeight: '500',
120
+ lineHeight: '16px',
121
+ letterSpacing: '0em',
122
+ textAlign: 'left',
123
+ backgroundColor: '#1D79A8',
124
+ textTransform: 'none',
125
+ color: '#fff',
126
+ float: 'left',
127
+ margin: '0px 10px 0px 0px',
128
+ whiteSpace: 'nowrap',
129
+ '&:hover': {
130
+ backgroundColor: '#1D79A8',
131
+ color: '#fff'
132
+ }
133
+ },
134
+ copyIconBtn: {
135
+ padding: '0px',
136
+ height: '20px',
137
+ marginLeft: '10px',
138
+ float: 'left'
139
+ }
140
+ });
141
+ var _default = (0, _core.withStyles)(styles)(QueryUrl);
142
+ exports.default = _default;
@@ -11,6 +11,7 @@ var _clsx = _interopRequireDefault(require("clsx"));
11
11
  var _FilterMap = require("../components/FilterMap");
12
12
  var _styles = _interopRequireDefault(require("./styles"));
13
13
  var _config = _interopRequireDefault(require("./config"));
14
+ var _QueryUrl = _interopRequireDefault(require("../components/QueryUrl"));
14
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
16
  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); }
16
17
  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; }
@@ -37,9 +38,8 @@ const QueryBarGenerator = function QueryBarGenerator() {
37
38
  } = _facetFilter.InputTypes;
38
39
  const styles = () => _objectSpread(_objectSpread({}, (0, _styles.default)()), customStyles);
39
40
  const maxItems = config && typeof config.maxItems === 'number' ? config.maxItems : _config.default.config.maxItems;
40
- const displayAllActiveFilters = config && typeof config.displayAllActiveFilters === 'boolean' ? config.displayAllActiveFilters : _config.default.config.displayAllActiveFilters;
41
- const group = config && typeof config.group === 'string' ? config.group : _config.default.config.group;
42
- const count = config && typeof config.count === 'string' ? config.count : _config.default.config.count;
41
+ const queryURLRootPath = config && typeof config.rootPath === 'string' ? config.rootPath : _config.default.config.rootPath;
42
+ const viewQueryURL = config && typeof config.viewQueryURL === 'boolean' ? config.viewQueryURL : _config.default.config.viewQueryURL;
43
43
  const clearAll = functions && typeof functions.clearAll === 'function' ? functions.clearAll : _config.default.functions.clearAll;
44
44
  const clearUpload = functions && typeof functions.clearUpload === 'function' ? functions.clearUpload : _config.default.functions.clearUpload;
45
45
  const clearAutocomplete = functions && typeof functions.clearAutocomplete === 'function' ? functions.clearAutocomplete : _config.default.functions.clearAutocomplete;
@@ -64,13 +64,8 @@ const QueryBarGenerator = function QueryBarGenerator() {
64
64
  autocomplete,
65
65
  upload
66
66
  } = localFind;
67
- const [expand, setExpand] = (0, _react.useState)(false);
67
+ const [expand, setExpand] = (0, _react.useState)(true);
68
68
  const noOfItems = expand ? autocomplete.length : maxItems;
69
- (0, _react.useEffect)(() => {
70
- if (autocomplete.length <= maxItems && expand) {
71
- setExpand(!expand);
72
- }
73
- }, [autocomplete]);
74
69
 
75
70
  // Remove any sections without checkboxes selected
76
71
  const mappedInputs = statusReducer.filter(facet => facet.section && facet.type).map(facet => {
@@ -78,37 +73,17 @@ const QueryBarGenerator = function QueryBarGenerator() {
78
73
  return facet;
79
74
  }
80
75
  const {
81
- data,
82
76
  items
83
77
  } = facet;
84
78
  const itemKeys = Object.keys(items);
85
79
  itemKeys.sort((a, b) => a.localeCompare(b));
86
80
 
87
- /* Find any SELECTED CHECKBOXES that do NOT have any data
88
- * and remove them from the list of selected checkboxes artificially */
89
- itemKeys.forEach(item => {
90
- if (data.findIndex(d => d.group === item) < 0) {
91
- itemKeys.splice(itemKeys.indexOf(item), 1);
92
- }
93
- });
94
- // return { ...facet, items: itemKeys };
95
81
  /**
96
- * Maintain consistant behavior with facet filter component
97
- * Display the active filter items based on the count value
98
- * Display active filter items in query bar only if count is greater than 0
99
- * behavior similar to filter component
82
+ * to display all the active filters in the query bar
83
+ * ICDC-3287
100
84
  */
101
- // const { group, count } = config;
102
- const displayItems = itemKeys.reduce((accumulator, item) => {
103
- const itemList = data.filter(d => d[group] === item && d[count] > 0) || [];
104
- if (itemList.length > 0) {
105
- const labels = itemList.map(filter => filter[group]);
106
- accumulator.push(labels);
107
- }
108
- return accumulator;
109
- }, []);
110
85
  return _objectSpread(_objectSpread({}, facet), {}, {
111
- items: displayItems
86
+ items: itemKeys
112
87
  });
113
88
  }).filter(facet => facet.items.length > 0);
114
89
  if ((mappedInputs.length || autocomplete.length || upload.length) <= 0) {
@@ -121,7 +96,7 @@ const QueryBarGenerator = function QueryBarGenerator() {
121
96
  color: "primary",
122
97
  variant: "outlined",
123
98
  onClick: clearAll
124
- }, "Clear Query"), /*#__PURE__*/_react.default.createElement("span", {
99
+ }, "Clear"), /*#__PURE__*/_react.default.createElement("span", {
125
100
  className: classes.divider
126
101
  }), /*#__PURE__*/_react.default.createElement("span", {
127
102
  className: classes.queryContainer
@@ -131,7 +106,7 @@ const QueryBarGenerator = function QueryBarGenerator() {
131
106
  }, "INPUT CASE SET") : null, autocomplete.length ? /*#__PURE__*/_react.default.createElement("span", null, ' ', /*#__PURE__*/_react.default.createElement("span", {
132
107
  className: (0, _clsx.default)(classes.filterName, classes.localFindBackground),
133
108
  onClick: clearAutocomplete
134
- }, "Case IDs"), ' ', ' ', /*#__PURE__*/_react.default.createElement("span", {
109
+ }, "Case ID"), ' ', ' ', /*#__PURE__*/_react.default.createElement("span", {
135
110
  className: classes.operators
136
111
  }, autocomplete.length === 1 && !upload.length ? 'IS ' : 'IN ')) : null, /*#__PURE__*/_react.default.createElement("span", null, (upload.length > 0 ? 1 : 0) + autocomplete.length > 1 ? /*#__PURE__*/_react.default.createElement("span", {
137
112
  className: classes.bracketsOpen
@@ -142,10 +117,10 @@ const QueryBarGenerator = function QueryBarGenerator() {
142
117
  className: (0, _clsx.default)(classes.filterCheckboxes, classes.facetSectionCases),
143
118
  key: idx,
144
119
  onClick: () => deleteAutocompleteItem(d.title)
145
- }, d.title), idx === noOfItems - 1 ? null : ' ')), autocomplete.length > maxItems && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, displayAllActiveFilters ? /*#__PURE__*/_react.default.createElement("span", {
120
+ }, d.title), idx === noOfItems - 1 ? null : ' ')), autocomplete.length > maxItems && !expand && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
146
121
  className: classes.expandBtn,
147
122
  onClick: () => setExpand(!expand)
148
- }, "...") : '...'), expand && autocomplete.length > maxItems && /*#__PURE__*/_react.default.createElement("span", {
123
+ }, "...")), expand && autocomplete.length > maxItems && /*#__PURE__*/_react.default.createElement("span", {
149
124
  className: classes.collapseBtn,
150
125
  onClick: () => setExpand(!expand)
151
126
  }, ' LESS'), (upload.length > 0 ? 1 : 0) + autocomplete.length > 1 ? /*#__PURE__*/_react.default.createElement("span", {
@@ -159,11 +134,15 @@ const QueryBarGenerator = function QueryBarGenerator() {
159
134
  type: filter.type,
160
135
  data: filter,
161
136
  maxItems: maxItems,
162
- displayAllActiveFilters: displayAllActiveFilters,
163
137
  classes: classes,
164
138
  onSectionClick: filter.type === CHECKBOX ? resetFacetSection : resetFacetSlider,
165
139
  onItemClick: filter.type === CHECKBOX ? resetFacetCheckbox : resetFacetSlider
166
- })))));
140
+ })))), viewQueryURL && queryURLRootPath && /*#__PURE__*/_react.default.createElement(_QueryUrl.default, {
141
+ classes: classes,
142
+ localFind: localFind,
143
+ filterItems: mappedInputs,
144
+ rootPath: queryURLRootPath
145
+ }));
167
146
  })
168
147
  };
169
148
  };
@@ -18,16 +18,7 @@ var _default = {
18
18
  * @var {boolean}
19
19
  */
20
20
  displayAllActiveFilters: false,
21
- /**
22
- * key to access label text
23
- * @var {boolean}
24
- */
25
- group: 'group',
26
- /**
27
- * key to access count value
28
- * @var {boolean}
29
- */
30
- count: 'subjects'
21
+ viewQueryURL: false
31
22
  },
32
23
  /* Component Helper Functions */
33
24
  functions: {
@@ -9,7 +9,7 @@ exports.default = void 0;
9
9
  */
10
10
  var _default = () => ({
11
11
  queryWrapper: {
12
- height: '120px',
12
+ minHeight: '77px',
13
13
  backgroundColor: '#f1f1f1',
14
14
  padding: '14px 14px 0px 35px',
15
15
  overflowY: 'auto'
package/package.json CHANGED
@@ -1,17 +1,14 @@
1
1
  {
2
2
  "name": "@bento-core/query-bar",
3
- "version": "1.0.1-icdc.2",
4
- "description": "This package provides the Query Bar component that displays the current Facet Search and Local Find filters on the Dashboard/Explore page. It also provides the direct ability to reset all or some of the filters with the click of a button. It is designed to be implemented directly with the:",
3
+ "version": "1.0.1-icdc.21",
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,10 +24,5 @@
27
24
  "lodash": "^4.17.20"
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",
35
- "devDependencies": {}
27
+ "license": "ISC"
36
28
  }
@@ -0,0 +1,3 @@
1
+ <svg width="16" height="19" viewBox="0 0 16 19" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M13 9.75715C13 10.0452 12.78 10.2714 12.5 10.2714H7.5C7.22 10.2714 7 10.0452 7 9.75715C7 9.46915 7.22 9.24287 7.5 9.24287H12.5C12.78 9.24287 13 9.46915 13 9.75715ZM12.5 11.3H7.5C7.22 11.3 7 11.5263 7 11.8143C7 12.1023 7.22 12.3286 7.5 12.3286H12.5C12.78 12.3286 13 12.1023 13 11.8143C13 11.5263 12.78 11.3 12.5 11.3ZM12.5 13.3572H7.5C7.22 13.3572 7 13.5834 7 13.8714C7 14.1594 7.22 14.3857 7.5 14.3857H12.5C12.78 14.3857 13 14.1594 13 13.8714C13 13.5834 12.78 13.3572 12.5 13.3572ZM16 8.21429V16.4429C16 17.5743 15.1 18.5 14 18.5H6C4.9 18.5 4 17.5743 4 16.4429V15.4143H2C0.9 15.4143 0 14.4886 0 13.3572V4.10001C0 2.96858 0.9 2.04286 2 2.04286H4.5C4.5 1.18915 5.17 0.500008 6 0.500008C6.83 0.500008 7.5 1.18915 7.5 2.04286H10C11.1 2.04286 12 2.96858 12 4.10001V6.15715H14C15.1 6.15715 16 7.08287 16 8.21429ZM6 6.15715H11V4.10001C11 3.53429 10.55 3.07144 10 3.07144H9V4.10001H3V3.07144H2C1.45 3.07144 1 3.53429 1 4.10001V13.3572C1 13.9229 1.45 14.3857 2 14.3857H4V8.21429C4 7.08287 4.9 6.15715 6 6.15715ZM15 8.21429C15 7.64858 14.55 7.18572 14 7.18572H6C5.45 7.18572 5 7.64858 5 8.21429V16.4429C5 17.0086 5.45 17.4714 6 17.4714H14C14.55 17.4714 15 17.0086 15 16.4429V8.21429Z" fill="#142D64"/>
3
+ </svg>
@@ -1,21 +1,14 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useState } from 'react';
2
2
  import clsx from 'clsx';
3
3
 
4
4
  export default ({
5
5
  index, data, classes, maxItems,
6
6
  onSectionClick, onItemClick,
7
- displayAllActiveFilters,
8
7
  }) => {
9
8
  const { items, section } = data;
10
- const [expand, setExpand] = useState(false);
9
+ const [expand, setExpand] = useState(true);
11
10
  const noOfItems = expand ? items.length : maxItems;
12
11
 
13
- useEffect(() => {
14
- if (items.length <= maxItems && expand) {
15
- setExpand(!expand);
16
- }
17
- }, [items]);
18
-
19
12
  const clsName = (text = '', attr = '') => `facetSection${text.replace(/\s+/g, '')}${attr}`;
20
13
 
21
14
  return (
@@ -49,20 +42,14 @@ export default ({
49
42
  {idx === (maxItems - 1) ? null : ' '}
50
43
  </>
51
44
  ))}
52
- {items.length > maxItems && (
45
+ {(items.length > maxItems && !expand) && (
53
46
  <>
54
- {
55
- displayAllActiveFilters
56
- ? (
57
- <span
58
- className={classes.expandBtn}
59
- onClick={() => setExpand(!expand)}
60
- >
61
- ...
62
- </span>
63
- )
64
- : '...'
65
- }
47
+ <span
48
+ className={classes.expandBtn}
49
+ onClick={() => setExpand(!expand)}
50
+ >
51
+ ...
52
+ </span>
66
53
  </>
67
54
  )}
68
55
  {(expand && items.length > maxItems) && (
@@ -0,0 +1,163 @@
1
+ import React, { useState, useRef } from 'react';
2
+ import clsx from 'clsx';
3
+ import {
4
+ Button,
5
+ IconButton,
6
+ Tooltip,
7
+ Dialog,
8
+ DialogActions,
9
+ DialogContent,
10
+ DialogContentText,
11
+ withStyles,
12
+ } from '@material-ui/core';
13
+ import CopyIcon from '../assets/CopyIcon.svg';
14
+
15
+ const QueryUrl = ({
16
+ classes,
17
+ filterItems,
18
+ localFind = {},
19
+ rootPath,
20
+ }) => {
21
+ const [display, setDisplay] = useState(false);
22
+ const toggleDisplay = () => setDisplay(!display);
23
+
24
+ const [open, toggleOpen] = useState(false);
25
+
26
+ const pathFilterParams = filterItems.reduce((acc, item) => {
27
+ const { datafield, items = [] } = item;
28
+ acc[datafield] = items;
29
+ return acc;
30
+ }, {});
31
+
32
+ const query = JSON.stringify({
33
+ ...pathFilterParams,
34
+ ...localFind,
35
+ });
36
+ const url = encodeURI(rootPath.concat(query));
37
+
38
+ const copyUrl = async () => {
39
+ toggleOpen(!open);
40
+ await navigator.clipboard.writeText(url);
41
+ };
42
+
43
+ const queryRef = useRef(null);
44
+
45
+ return (
46
+ <>
47
+ <div ref={queryRef} className={classes.urlContainer}>
48
+ <Button
49
+ onClick={toggleDisplay}
50
+ className={classes.viewLinkToggleBtn}
51
+ >
52
+ { (display) ? 'Hide Query URL' : 'Show Query URL'}
53
+ </Button>
54
+ {
55
+ (display) && (
56
+ <>
57
+ <div
58
+ type="button"
59
+ className={clsx(classes.viewLink)}
60
+ >
61
+ {url}
62
+ </div>
63
+ <Tooltip
64
+ arrow
65
+ title="Copy to Clipboard"
66
+ >
67
+ <IconButton onClick={copyUrl} className={classes.copyIconBtn}>
68
+ <img src={CopyIcon} alt="copy icon" />
69
+ </IconButton>
70
+ </Tooltip>
71
+ </>
72
+ )
73
+ }
74
+ </div>
75
+ <Dialog
76
+ open={open}
77
+ onClose={() => toggleOpen(!open)}
78
+ aria-labelledby="alert-dialog-title"
79
+ aria-describedby="alert-dialog-description"
80
+ className={clsx(classes.dialogBox, 'dialogBox')}
81
+ >
82
+ <DialogContent className={classes.okText}>
83
+ <DialogContentText id="alert-dialog-description">
84
+ Your query URL has been copied!
85
+ </DialogContentText>
86
+ </DialogContent>
87
+ <DialogActions>
88
+ <Button onClick={() => toggleOpen(!open)}>
89
+ OK
90
+ </Button>
91
+ </DialogActions>
92
+ </Dialog>
93
+ </>
94
+ );
95
+ };
96
+
97
+ const styles = () => ({
98
+ urlContainer: {
99
+ display: 'flex',
100
+ marginTop: '3px',
101
+ minHeight: '10px',
102
+ },
103
+ viewLink: {
104
+ overflow: 'hidden',
105
+ textOverflow: 'ellipsis',
106
+ fontFamily: 'Nunito',
107
+ fontSize: '12px',
108
+ fontWeight: '500',
109
+ lineHeight: '16px',
110
+ letterSpacing: '0em',
111
+ padding: '2px 5px',
112
+ borderRadius: '5px',
113
+ float: 'left',
114
+ color: '#1D79A8',
115
+ backgroundColor: '#fff',
116
+ margin: '0',
117
+ whiteSpace: 'nowrap',
118
+ wordBreak: 'break-all',
119
+ '@media (max-width: 2560px)': {
120
+ maxWidth: '1800px',
121
+ },
122
+ '@media (max-width: 2000px)': {
123
+ maxWidth: '1500px',
124
+ },
125
+ '@media (max-width: 1600px)': {
126
+ maxWidth: '1100px',
127
+ },
128
+ '@media (max-width: 1300px)': {
129
+ maxWidth: '900px',
130
+ },
131
+ },
132
+ urlViewBtn: {
133
+ cursor: 'pointer',
134
+ },
135
+ viewLinkToggleBtn: {
136
+ padding: '5px 10px 5px 10px',
137
+ height: '20px',
138
+ fontFamily: 'Nunito',
139
+ fontSize: '12px',
140
+ fontWeight: '500',
141
+ lineHeight: '16px',
142
+ letterSpacing: '0em',
143
+ textAlign: 'left',
144
+ backgroundColor: '#1D79A8',
145
+ textTransform: 'none',
146
+ color: '#fff',
147
+ float: 'left',
148
+ margin: '0px 10px 0px 0px',
149
+ whiteSpace: 'nowrap',
150
+ '&:hover': {
151
+ backgroundColor: '#1D79A8',
152
+ color: '#fff',
153
+ },
154
+ },
155
+ copyIconBtn: {
156
+ padding: '0px',
157
+ height: '20px',
158
+ marginLeft: '10px',
159
+ float: 'left',
160
+ },
161
+ });
162
+
163
+ export default withStyles(styles)(QueryUrl);
@@ -1,10 +1,11 @@
1
- import React, { useState, useEffect } from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { withStyles, Button } from '@material-ui/core';
3
3
  import { InputTypes } from '@bento-core/facet-filter';
4
4
  import clsx from 'clsx';
5
5
  import { Filter } from '../components/FilterMap';
6
6
  import DEFAULT_STYLES from './styles';
7
7
  import DEFAULT_CONFIG from './config';
8
+ import QueryUrl from '../components/QueryUrl';
8
9
 
9
10
  /**
10
11
  * Generate a pre-configured Explore Query Bar component
@@ -23,15 +24,13 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
23
24
  ? config.maxItems
24
25
  : DEFAULT_CONFIG.config.maxItems;
25
26
 
26
- const displayAllActiveFilters = config && typeof config.displayAllActiveFilters === 'boolean'
27
- ? config.displayAllActiveFilters
28
- : DEFAULT_CONFIG.config.displayAllActiveFilters;
27
+ const queryURLRootPath = config && typeof config.rootPath === 'string'
28
+ ? config.rootPath
29
+ : DEFAULT_CONFIG.config.rootPath;
29
30
 
30
- const group = config && typeof config.group === 'string'
31
- ? config.group : DEFAULT_CONFIG.config.group;
32
-
33
- const count = config && typeof config.count === 'string'
34
- ? config.count : DEFAULT_CONFIG.config.count;
31
+ const viewQueryURL = config && typeof config.viewQueryURL === 'boolean'
32
+ ? config.viewQueryURL
33
+ : DEFAULT_CONFIG.config.viewQueryURL;
35
34
 
36
35
  const clearAll = functions && typeof functions.clearAll === 'function'
37
36
  ? functions.clearAll
@@ -69,49 +68,23 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
69
68
 
70
69
  const { autocomplete, upload } = localFind;
71
70
 
72
- const [expand, setExpand] = useState(false);
71
+ const [expand, setExpand] = useState(true);
73
72
  const noOfItems = expand ? autocomplete.length : maxItems;
74
73
 
75
- useEffect(() => {
76
- if (autocomplete.length <= maxItems && expand) {
77
- setExpand(!expand);
78
- }
79
- }, [autocomplete]);
80
-
81
74
  // Remove any sections without checkboxes selected
82
75
  const mappedInputs = statusReducer.filter((facet) => facet.section && facet.type)
83
76
  .map((facet) => {
84
77
  if (facet.type !== CHECKBOX) { return facet; }
85
78
 
86
- const { data, items } = facet;
79
+ const { items } = facet;
87
80
  const itemKeys = Object.keys(items);
88
81
  itemKeys.sort((a, b) => a.localeCompare(b));
89
82
 
90
- /* Find any SELECTED CHECKBOXES that do NOT have any data
91
- * and remove them from the list of selected checkboxes artificially */
92
- itemKeys.forEach((item) => {
93
- if (data.findIndex((d) => d.group === item) < 0) {
94
- itemKeys.splice(itemKeys.indexOf(item), 1);
95
- }
96
- });
97
- // return { ...facet, items: itemKeys };
98
83
  /**
99
- * Maintain consistant behavior with facet filter component
100
- * Display the active filter items based on the count value
101
- * Display active filter items in query bar only if count is greater than 0
102
- * behavior similar to filter component
84
+ * to display all the active filters in the query bar
85
+ * ICDC-3287
103
86
  */
104
- // const { group, count } = config;
105
- const displayItems = itemKeys.reduce((accumulator, item) => {
106
- const itemList = data.filter((d) => (d[group] === item && d[count] > 0)) || [];
107
- if (itemList.length > 0) {
108
- const labels = itemList.map((filter) => filter[group]);
109
- accumulator.push(labels);
110
- }
111
- return accumulator;
112
- }, []);
113
-
114
- return { ...facet, items: displayItems };
87
+ return { ...facet, items: itemKeys };
115
88
  })
116
89
  .filter((facet) => facet.items.length > 0);
117
90
 
@@ -127,7 +100,7 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
127
100
  variant="outlined"
128
101
  onClick={clearAll}
129
102
  >
130
- Clear Query
103
+ Clear
131
104
  </Button>
132
105
  <span className={classes.divider} />
133
106
  <span className={classes.queryContainer}>
@@ -153,7 +126,7 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
153
126
  className={clsx(classes.filterName, classes.localFindBackground)}
154
127
  onClick={clearAutocomplete}
155
128
  >
156
- Case IDs
129
+ Case ID
157
130
  </span>
158
131
  {' '}
159
132
  {' '}
@@ -190,20 +163,14 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
190
163
  {idx === (noOfItems - 1) ? null : ' '}
191
164
  </>
192
165
  ))}
193
- {autocomplete.length > maxItems && (
166
+ {(autocomplete.length > maxItems && !expand) && (
194
167
  <>
195
- {
196
- displayAllActiveFilters
197
- ? (
198
- <span
199
- className={classes.expandBtn}
200
- onClick={() => setExpand(!expand)}
201
- >
202
- ...
203
- </span>
204
- )
205
- : '...'
206
- }
168
+ <span
169
+ className={classes.expandBtn}
170
+ onClick={() => setExpand(!expand)}
171
+ >
172
+ ...
173
+ </span>
207
174
  </>
208
175
  )}
209
176
  {(expand && autocomplete.length > maxItems) && (
@@ -220,7 +187,6 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
220
187
  </span>
221
188
  </span>
222
189
  ) : null}
223
-
224
190
  {/* Facet Sidebar Selections */}
225
191
  {((autocomplete.length || upload.length) && mappedInputs.length)
226
192
  ? <span className={classes.operators}> AND </span>
@@ -232,7 +198,6 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
232
198
  type={filter.type}
233
199
  data={filter}
234
200
  maxItems={maxItems}
235
- displayAllActiveFilters={displayAllActiveFilters}
236
201
  classes={classes}
237
202
  onSectionClick={filter.type === CHECKBOX
238
203
  ? resetFacetSection
@@ -244,6 +209,16 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
244
209
  </span>
245
210
  ))}
246
211
  </span>
212
+ {
213
+ (viewQueryURL && queryURLRootPath) && (
214
+ <QueryUrl
215
+ classes={classes}
216
+ localFind={localFind}
217
+ filterItems={mappedInputs}
218
+ rootPath={queryURLRootPath}
219
+ />
220
+ )
221
+ }
247
222
  </div>
248
223
  );
249
224
  }),
@@ -12,16 +12,7 @@ export default {
12
12
  * @var {boolean}
13
13
  */
14
14
  displayAllActiveFilters: false,
15
- /**
16
- * key to access label text
17
- * @var {boolean}
18
- */
19
- group: 'group',
20
- /**
21
- * key to access count value
22
- * @var {boolean}
23
- */
24
- count: 'subjects',
15
+ viewQueryURL: false,
25
16
  },
26
17
 
27
18
  /* Component Helper Functions */
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export default () => ({
5
5
  queryWrapper: {
6
- height: '120px',
6
+ minHeight: '77px',
7
7
  backgroundColor: '#f1f1f1',
8
8
  padding: '14px 14px 0px 35px',
9
9
  overflowY: 'auto',