@bento-core/query-bar 1.0.1-icdc.1 → 1.0.1-icdc.11

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,30 @@ 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,
66
+ /**
67
+ * key to access label text
68
+ * @var {boolean}
69
+ */
70
+ group: 'group',
71
+
72
+ /**
73
+ * root path of bento app {window.location.href} or react PUBLIC_URL
74
+ * PR (https://github.com/CBIIT/bento-icdc-frontend/pull/953)
75
+ * @var {string}
76
+ */
77
+ rootPath: null,
78
+ /**
79
+ * display query URL
80
+ * @var {boolean}
81
+ * PR (https://github.com/CBIIT/bento-icdc-frontend/pull/953)
82
+ */
83
+ viewQueryURL: false,
84
+
61
85
  },
62
86
 
63
87
  /* Component Helper Functions */
@@ -115,6 +139,7 @@ const CONFIG = {
115
139
  * @returns {void}
116
140
  */
117
141
  resetFacetSlider: (section) => {},
142
+
118
143
  },
119
144
  };
120
145
  ```
@@ -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>
@@ -0,0 +1,210 @@
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 ViewFullLinkComponent = _ref => {
20
+ let {
21
+ classes,
22
+ url,
23
+ maxWidth = 1200
24
+ } = _ref;
25
+ const linkRef = (0, _react.useRef)(null);
26
+ const [expandLink, setExpand] = (0, _react.useState)(false);
27
+
28
+ /**
29
+ * Compute url link width based on the windowsize
30
+ */
31
+ (0, _react.useEffect)(() => {
32
+ var _linkRef$current;
33
+ const urlWidth = linkRef === null || linkRef === void 0 ? void 0 : (_linkRef$current = linkRef.current) === null || _linkRef$current === void 0 ? void 0 : _linkRef$current.offsetWidth;
34
+ if (urlWidth > maxWidth / 2) {
35
+ setExpand(true);
36
+ }
37
+ }, []);
38
+ const expandUrl = () => {
39
+ setExpand(!expandLink);
40
+ };
41
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
42
+ ref: linkRef,
43
+ className: classes.link
44
+ }, /*#__PURE__*/_react.default.createElement("span", {
45
+ className: (0, _clsx.default)(classes.viewLink, {
46
+ [classes.collapseLink]: expandLink
47
+ })
48
+ }, /*#__PURE__*/_react.default.createElement("span", {
49
+ className: classes.urlView
50
+ }, url), expandLink && /*#__PURE__*/_react.default.createElement("span", {
51
+ className: classes.expandLinkBtn,
52
+ type: "button",
53
+ onClick: expandUrl
54
+ }, "..."))));
55
+ };
56
+ const QueryUrl = _ref2 => {
57
+ var _queryRef$current;
58
+ let {
59
+ classes,
60
+ filterItems,
61
+ localFind,
62
+ rootPath
63
+ } = _ref2;
64
+ const [display, setDisplay] = (0, _react.useState)(false);
65
+ const toggleDisplay = () => setDisplay(!display);
66
+ const [expand, setExpand] = (0, _react.useState)(false);
67
+ const [open, toggleOpen] = (0, _react.useState)(false);
68
+ const {
69
+ autocomplete = [],
70
+ upload
71
+ } = localFind;
72
+ const pathFilterParams = filterItems.reduce((acc, item) => {
73
+ const {
74
+ datafield,
75
+ items = []
76
+ } = item;
77
+ acc[datafield] = items;
78
+ return acc;
79
+ }, {});
80
+ const query = JSON.stringify(_objectSpread(_objectSpread({}, pathFilterParams), {}, {
81
+ autocomplete,
82
+ upload
83
+ }));
84
+ const url = encodeURI(rootPath.concat(query));
85
+ const copyUrl = async () => {
86
+ toggleOpen(!open);
87
+ await navigator.clipboard.writeText(url);
88
+ };
89
+ const queryRef = (0, _react.useRef)(null);
90
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
91
+ ref: queryRef,
92
+ className: classes.urlContainer
93
+ }, /*#__PURE__*/_react.default.createElement(_core.Button, {
94
+ onClick: toggleDisplay,
95
+ className: classes.viewLinkToggleBtn
96
+ }, display ? 'Hide Query URL' : 'Show Query URL'), display && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, expand ? /*#__PURE__*/_react.default.createElement("span", {
97
+ type: "button",
98
+ onClick: () => setExpand(!expand),
99
+ className: (0, _clsx.default)(classes.link, classes.viewLink, classes.expandLink)
100
+ }, url) : /*#__PURE__*/_react.default.createElement(ViewFullLinkComponent, {
101
+ url: url,
102
+ classes: classes,
103
+ maxWidth: queryRef === null || queryRef === void 0 ? void 0 : (_queryRef$current = queryRef.current) === null || _queryRef$current === void 0 ? void 0 : _queryRef$current.offsetWidth
104
+ }), /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
105
+ arrow: true,
106
+ title: "Copy to Clipboard"
107
+ }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
108
+ onClick: copyUrl,
109
+ className: classes.copyIconBtn
110
+ }, /*#__PURE__*/_react.default.createElement("img", {
111
+ src: _CopyIcon.default,
112
+ alt: "copy icon"
113
+ }))))), /*#__PURE__*/_react.default.createElement(_core.Dialog, {
114
+ open: open,
115
+ "aria-labelledby": "alert-dialog-title",
116
+ "aria-describedby": "alert-dialog-description",
117
+ className: (0, _clsx.default)(classes.dialogBox, 'dialogBox')
118
+ }, /*#__PURE__*/_react.default.createElement(_core.DialogContent, {
119
+ className: classes.okText
120
+ }, /*#__PURE__*/_react.default.createElement(_core.DialogContentText, {
121
+ id: "alert-dialog-description"
122
+ }, "Your query URL has been copied!")), /*#__PURE__*/_react.default.createElement(_core.DialogActions, null, /*#__PURE__*/_react.default.createElement(_core.Button, {
123
+ onClick: () => toggleOpen(!open)
124
+ }, "OK"))));
125
+ };
126
+ const styles = () => ({
127
+ urlContainer: {
128
+ display: 'flex',
129
+ marginTop: '10px',
130
+ minHeight: '10px'
131
+ },
132
+ link: {
133
+ lineBreak: 'anywhere',
134
+ overflow: 'hidden',
135
+ fontFamily: 'Nunito',
136
+ fontSize: '12px',
137
+ fontWeight: '500',
138
+ lineHeight: '16px',
139
+ letterSpacing: '0em',
140
+ padding: '5px',
141
+ borderRadius: '5px',
142
+ float: 'left',
143
+ color: '#1D79A8',
144
+ backgroundColor: '#fff',
145
+ maxWidth: '80%'
146
+ },
147
+ viewLink: {
148
+ margin: '0'
149
+ },
150
+ collapseLink: {
151
+ maxHeight: '1em',
152
+ display: 'block',
153
+ // display: '-webkit-box',
154
+ '-webkit-box-orient': 'vertical',
155
+ '-webkit-line-clamp': '1',
156
+ overflow: 'hidden'
157
+ },
158
+ expandLink: {
159
+ cursor: 'pointer'
160
+ },
161
+ expandLinkBtn: {
162
+ float: 'left',
163
+ '&:hover': {
164
+ cursor: 'pointer'
165
+ }
166
+ },
167
+ viewLinkToggleBtn: {
168
+ height: '20px',
169
+ fontFamily: 'Nunito',
170
+ fontSize: '12px',
171
+ fontWeight: '500',
172
+ lineHeight: '16px',
173
+ letterSpacing: '0em',
174
+ textAlign: 'left',
175
+ backgroundColor: '#1D79A8',
176
+ textTransform: 'none',
177
+ color: '#fff',
178
+ float: 'left',
179
+ margin: '0px 10px 0px 0px',
180
+ '&:hover': {
181
+ backgroundColor: '#1D79A8',
182
+ color: '#fff'
183
+ }
184
+ },
185
+ urlView: {
186
+ float: 'left',
187
+ width: 'calc(100% - 13px)',
188
+ minWidth: '840px',
189
+ '@media (max-width: 2560px)': {
190
+ maxWidth: '1800px'
191
+ },
192
+ '@media (max-width: 2000px)': {
193
+ maxWidth: '1400px'
194
+ },
195
+ '@media (max-width: 1600px)': {
196
+ maxWidth: '1200px'
197
+ },
198
+ '@media (max-width: 1300px)': {
199
+ maxWidth: '1050px'
200
+ }
201
+ },
202
+ copyIconBtn: {
203
+ padding: '0px',
204
+ height: '20px',
205
+ marginLeft: '10px',
206
+ float: 'left'
207
+ }
208
+ });
209
+ var _default = (0, _core.withStyles)(styles)(QueryUrl);
210
+ 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,7 +38,13 @@ 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;
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;
40
43
  const displayAllActiveFilters = config && typeof config.displayAllActiveFilters === 'boolean' ? config.displayAllActiveFilters : _config.default.config.displayAllActiveFilters;
44
+
45
+ // const group = config && typeof config.group === 'string'
46
+ // ? config.group : DEFAULT_CONFIG.config.group;
47
+
41
48
  const clearAll = functions && typeof functions.clearAll === 'function' ? functions.clearAll : _config.default.functions.clearAll;
42
49
  const clearUpload = functions && typeof functions.clearUpload === 'function' ? functions.clearUpload : _config.default.functions.clearUpload;
43
50
  const clearAutocomplete = functions && typeof functions.clearAutocomplete === 'function' ? functions.clearAutocomplete : _config.default.functions.clearAutocomplete;
@@ -76,7 +83,6 @@ const QueryBarGenerator = function QueryBarGenerator() {
76
83
  return facet;
77
84
  }
78
85
  const {
79
- data,
80
86
  items
81
87
  } = facet;
82
88
  const itemKeys = Object.keys(items);
@@ -84,34 +90,25 @@ const QueryBarGenerator = function QueryBarGenerator() {
84
90
 
85
91
  /* Find any SELECTED CHECKBOXES that do NOT have any data
86
92
  * and remove them from the list of selected checkboxes artificially */
87
- itemKeys.forEach(item => {
88
- if (data.findIndex(d => d.group === item) < 0) {
89
- itemKeys.splice(itemKeys.indexOf(item), 1);
90
- }
91
- });
92
- // return { ...facet, items: itemKeys };
93
+ // itemKeys.forEach((item) => {
94
+ // if (data.findIndex((d) => d.group === item) < 0) {
95
+ // itemKeys.splice(itemKeys.indexOf(item), 1);
96
+ // }
97
+ // });
98
+
93
99
  /**
94
- * Maintain consistant behavior with facet filter component
95
- * Display the active filter items based on the count value
96
- * Display active filter items in query bar only if count is greater than 0
97
- * behavior similar to filter component
100
+ * commenting out line 89-93
101
+ * to display all the active filters in the query bar
102
+ * ICDC-3287
98
103
  */
99
- const displayItems = itemKeys.reduce((accumulator, item) => {
100
- const itemList = data.filter(d => d.group === item && d.count > 0) || [];
101
- if (itemList.length > 0) {
102
- const labels = itemList.map(filter => filter.group);
103
- accumulator.push(labels);
104
- }
105
- return accumulator;
106
- }, []);
107
104
  return _objectSpread(_objectSpread({}, facet), {}, {
108
- items: displayItems
105
+ items: itemKeys
109
106
  });
110
107
  }).filter(facet => facet.items.length > 0);
111
108
  if ((mappedInputs.length || autocomplete.length || upload.length) <= 0) {
112
109
  return null;
113
110
  }
114
- return /*#__PURE__*/_react.default.createElement("div", {
111
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
115
112
  className: classes.queryWrapper
116
113
  }, /*#__PURE__*/_react.default.createElement(_core.Button, {
117
114
  className: classes.clearQueryButton,
@@ -128,7 +125,7 @@ const QueryBarGenerator = function QueryBarGenerator() {
128
125
  }, "INPUT CASE SET") : null, autocomplete.length ? /*#__PURE__*/_react.default.createElement("span", null, ' ', /*#__PURE__*/_react.default.createElement("span", {
129
126
  className: (0, _clsx.default)(classes.filterName, classes.localFindBackground),
130
127
  onClick: clearAutocomplete
131
- }, "Case IDs"), ' ', ' ', /*#__PURE__*/_react.default.createElement("span", {
128
+ }, "Case ID"), ' ', ' ', /*#__PURE__*/_react.default.createElement("span", {
132
129
  className: classes.operators
133
130
  }, 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", {
134
131
  className: classes.bracketsOpen
@@ -160,7 +157,12 @@ const QueryBarGenerator = function QueryBarGenerator() {
160
157
  classes: classes,
161
158
  onSectionClick: filter.type === CHECKBOX ? resetFacetSection : resetFacetSlider,
162
159
  onItemClick: filter.type === CHECKBOX ? resetFacetCheckbox : resetFacetSlider
163
- })))));
160
+ })))), viewQueryURL && queryURLRootPath && /*#__PURE__*/_react.default.createElement(_QueryUrl.default, {
161
+ classes: classes,
162
+ localFind: localFind,
163
+ filterItems: mappedInputs,
164
+ rootPath: queryURLRootPath
165
+ })));
164
166
  })
165
167
  };
166
168
  };
@@ -17,7 +17,22 @@ var _default = {
17
17
  * overirdes maxItems to display all the active filter items
18
18
  * @var {boolean}
19
19
  */
20
- displayAllActiveFilters: false
20
+ displayAllActiveFilters: false,
21
+ /**
22
+ * key to access label text
23
+ * @var {boolean}
24
+ */
25
+ group: 'group',
26
+ /**
27
+ * root path of bento app
28
+ * @var {boolean}
29
+ */
30
+ rootPath: null,
31
+ /**
32
+ * display query URL
33
+ * @var {boolean}
34
+ */
35
+ viewQueryURL: false
21
36
  },
22
37
  /* Component Helper Functions */
23
38
  functions: {
package/package.json CHANGED
@@ -1,17 +1,14 @@
1
1
  {
2
2
  "name": "@bento-core/query-bar",
3
- "version": "1.0.1-icdc.1",
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.11",
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>
@@ -0,0 +1,241 @@
1
+ import React, { useState, useEffect, 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 ViewFullLinkComponent = ({
16
+ classes,
17
+ url,
18
+ maxWidth = 1200,
19
+ }) => {
20
+ const linkRef = useRef(null);
21
+ const [expandLink, setExpand] = useState(false);
22
+
23
+ /**
24
+ * Compute url link width based on the windowsize
25
+ */
26
+ useEffect(() => {
27
+ const urlWidth = linkRef?.current?.offsetWidth;
28
+ if (urlWidth > maxWidth / 2) {
29
+ setExpand(true);
30
+ }
31
+ }, []);
32
+
33
+ const expandUrl = () => {
34
+ setExpand(!expandLink);
35
+ };
36
+
37
+ return (
38
+ <>
39
+ <span ref={linkRef} className={classes.link}>
40
+ <span
41
+ className={clsx(classes.viewLink,
42
+ { [classes.collapseLink]: expandLink })}
43
+ >
44
+ <span className={classes.urlView}>
45
+ {url}
46
+ </span>
47
+ {(expandLink) && (
48
+ <span
49
+ className={classes.expandLinkBtn}
50
+ type="button"
51
+ onClick={expandUrl}
52
+ >
53
+ ...
54
+ </span>
55
+ )}
56
+ </span>
57
+ </span>
58
+ </>
59
+ );
60
+ };
61
+
62
+ const QueryUrl = ({
63
+ classes,
64
+ filterItems,
65
+ localFind,
66
+ rootPath,
67
+ }) => {
68
+ const [display, setDisplay] = useState(false);
69
+ const toggleDisplay = () => setDisplay(!display);
70
+
71
+ const [expand, setExpand] = useState(false);
72
+
73
+ const [open, toggleOpen] = useState(false);
74
+
75
+ const { autocomplete = [], upload } = localFind;
76
+
77
+ const pathFilterParams = filterItems.reduce((acc, item) => {
78
+ const { datafield, items = [] } = item;
79
+ acc[datafield] = items;
80
+ return acc;
81
+ }, {});
82
+
83
+ const query = JSON.stringify({
84
+ ...pathFilterParams,
85
+ autocomplete,
86
+ upload,
87
+ });
88
+ const url = encodeURI(rootPath.concat(query));
89
+
90
+ const copyUrl = async () => {
91
+ toggleOpen(!open);
92
+ await navigator.clipboard.writeText(url);
93
+ };
94
+
95
+ const queryRef = useRef(null);
96
+
97
+ return (
98
+ <>
99
+ <div ref={queryRef} className={classes.urlContainer}>
100
+ <Button
101
+ onClick={toggleDisplay}
102
+ className={classes.viewLinkToggleBtn}
103
+ >
104
+ { (display) ? 'Hide Query URL' : 'Show Query URL'}
105
+ </Button>
106
+ {
107
+ (display) && (
108
+ <>
109
+ {(expand) ? (
110
+ <span
111
+ type="button"
112
+ onClick={() => setExpand(!expand)}
113
+ className={clsx(classes.link, classes.viewLink, classes.expandLink)}
114
+ >
115
+ {url}
116
+ </span>
117
+ ) : (
118
+ <ViewFullLinkComponent
119
+ url={url}
120
+ classes={classes}
121
+ maxWidth={queryRef?.current?.offsetWidth}
122
+ />
123
+ )}
124
+ <Tooltip
125
+ arrow
126
+ title="Copy to Clipboard"
127
+ >
128
+ <IconButton onClick={copyUrl} className={classes.copyIconBtn}>
129
+ <img src={CopyIcon} alt="copy icon" />
130
+ </IconButton>
131
+ </Tooltip>
132
+ </>
133
+ )
134
+ }
135
+ </div>
136
+ <Dialog
137
+ open={open}
138
+ aria-labelledby="alert-dialog-title"
139
+ aria-describedby="alert-dialog-description"
140
+ className={clsx(classes.dialogBox, 'dialogBox')}
141
+ >
142
+ <DialogContent className={classes.okText}>
143
+ <DialogContentText id="alert-dialog-description">
144
+ Your query URL has been copied!
145
+ </DialogContentText>
146
+ </DialogContent>
147
+ <DialogActions>
148
+ <Button onClick={() => toggleOpen(!open)}>
149
+ OK
150
+ </Button>
151
+ </DialogActions>
152
+ </Dialog>
153
+ </>
154
+ );
155
+ };
156
+
157
+ const styles = () => ({
158
+ urlContainer: {
159
+ display: 'flex',
160
+ marginTop: '10px',
161
+ minHeight: '10px',
162
+ },
163
+ link: {
164
+ lineBreak: 'anywhere',
165
+ overflow: 'hidden',
166
+ fontFamily: 'Nunito',
167
+ fontSize: '12px',
168
+ fontWeight: '500',
169
+ lineHeight: '16px',
170
+ letterSpacing: '0em',
171
+ padding: '5px',
172
+ borderRadius: '5px',
173
+ float: 'left',
174
+ color: '#1D79A8',
175
+ backgroundColor: '#fff',
176
+ maxWidth: '80%',
177
+ },
178
+ viewLink: {
179
+ margin: '0',
180
+ },
181
+ collapseLink: {
182
+ maxHeight: '1em',
183
+ display: 'block',
184
+ // display: '-webkit-box',
185
+ '-webkit-box-orient': 'vertical',
186
+ '-webkit-line-clamp': '1',
187
+ overflow: 'hidden',
188
+ },
189
+ expandLink: {
190
+ cursor: 'pointer',
191
+ },
192
+ expandLinkBtn: {
193
+ float: 'left',
194
+ '&:hover': {
195
+ cursor: 'pointer',
196
+ },
197
+ },
198
+ viewLinkToggleBtn: {
199
+ height: '20px',
200
+ fontFamily: 'Nunito',
201
+ fontSize: '12px',
202
+ fontWeight: '500',
203
+ lineHeight: '16px',
204
+ letterSpacing: '0em',
205
+ textAlign: 'left',
206
+ backgroundColor: '#1D79A8',
207
+ textTransform: 'none',
208
+ color: '#fff',
209
+ float: 'left',
210
+ margin: '0px 10px 0px 0px',
211
+ '&:hover': {
212
+ backgroundColor: '#1D79A8',
213
+ color: '#fff',
214
+ },
215
+ },
216
+ urlView: {
217
+ float: 'left',
218
+ width: 'calc(100% - 13px)',
219
+ minWidth: '840px',
220
+ '@media (max-width: 2560px)': {
221
+ maxWidth: '1800px',
222
+ },
223
+ '@media (max-width: 2000px)': {
224
+ maxWidth: '1400px',
225
+ },
226
+ '@media (max-width: 1600px)': {
227
+ maxWidth: '1200px',
228
+ },
229
+ '@media (max-width: 1300px)': {
230
+ maxWidth: '1050px',
231
+ },
232
+ },
233
+ copyIconBtn: {
234
+ padding: '0px',
235
+ height: '20px',
236
+ marginLeft: '10px',
237
+ float: 'left',
238
+ },
239
+ });
240
+
241
+ export default withStyles(styles)(QueryUrl);
@@ -5,6 +5,7 @@ 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,10 +24,21 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
23
24
  ? config.maxItems
24
25
  : DEFAULT_CONFIG.config.maxItems;
25
26
 
27
+ const queryURLRootPath = config && typeof config.rootPath === 'string'
28
+ ? config.rootPath
29
+ : DEFAULT_CONFIG.config.rootPath;
30
+
31
+ const viewQueryURL = config && typeof config.viewQueryURL === 'boolean'
32
+ ? config.viewQueryURL
33
+ : DEFAULT_CONFIG.config.viewQueryURL;
34
+
26
35
  const displayAllActiveFilters = config && typeof config.displayAllActiveFilters === 'boolean'
27
36
  ? config.displayAllActiveFilters
28
37
  : DEFAULT_CONFIG.config.displayAllActiveFilters;
29
38
 
39
+ // const group = config && typeof config.group === 'string'
40
+ // ? config.group : DEFAULT_CONFIG.config.group;
41
+
30
42
  const clearAll = functions && typeof functions.clearAll === 'function'
31
43
  ? functions.clearAll
32
44
  : DEFAULT_CONFIG.functions.clearAll;
@@ -77,34 +89,24 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
77
89
  .map((facet) => {
78
90
  if (facet.type !== CHECKBOX) { return facet; }
79
91
 
80
- const { data, items } = facet;
92
+ const { items } = facet;
81
93
  const itemKeys = Object.keys(items);
82
94
  itemKeys.sort((a, b) => a.localeCompare(b));
83
95
 
84
96
  /* Find any SELECTED CHECKBOXES that do NOT have any data
85
97
  * and remove them from the list of selected checkboxes artificially */
86
- itemKeys.forEach((item) => {
87
- if (data.findIndex((d) => d.group === item) < 0) {
88
- itemKeys.splice(itemKeys.indexOf(item), 1);
89
- }
90
- });
91
- // return { ...facet, items: itemKeys };
98
+ // itemKeys.forEach((item) => {
99
+ // if (data.findIndex((d) => d.group === item) < 0) {
100
+ // itemKeys.splice(itemKeys.indexOf(item), 1);
101
+ // }
102
+ // });
103
+
92
104
  /**
93
- * Maintain consistant behavior with facet filter component
94
- * Display the active filter items based on the count value
95
- * Display active filter items in query bar only if count is greater than 0
96
- * behavior similar to filter component
105
+ * commenting out line 89-93
106
+ * to display all the active filters in the query bar
107
+ * ICDC-3287
97
108
  */
98
- const displayItems = itemKeys.reduce((accumulator, item) => {
99
- const itemList = data.filter((d) => (d.group === item && d.count > 0)) || [];
100
- if (itemList.length > 0) {
101
- const labels = itemList.map((filter) => filter.group);
102
- accumulator.push(labels);
103
- }
104
- return accumulator;
105
- }, []);
106
-
107
- return { ...facet, items: displayItems };
109
+ return { ...facet, items: itemKeys };
108
110
  })
109
111
  .filter((facet) => facet.items.length > 0);
110
112
 
@@ -113,131 +115,143 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
113
115
  }
114
116
 
115
117
  return (
116
- <div className={classes.queryWrapper}>
117
- <Button
118
- className={classes.clearQueryButton}
119
- color="primary"
120
- variant="outlined"
121
- onClick={clearAll}
122
- >
123
- Clear Query
124
- </Button>
125
- <span className={classes.divider} />
126
- <span className={classes.queryContainer}>
127
- {/* Local Find Selections */}
128
- {/* TODO: Refactor this into a separate component */}
129
- {(autocomplete.length || upload.length) ? (
130
- <span>
131
- {/* Standalone case set button */}
132
- {(upload.length && !autocomplete.length)
133
- ? (
134
- <span
135
- className={clsx(classes.filterCheckboxes, classes.localFindBackground)}
136
- onClick={clearUpload}
137
- >
138
- INPUT CASE SET
139
- </span>
140
- ) : null}
141
- {autocomplete.length
142
- ? (
143
- <span>
144
- {' '}
145
- <span
146
- className={clsx(classes.filterName, classes.localFindBackground)}
147
- onClick={clearAutocomplete}
148
- >
149
- Case IDs
150
- </span>
151
- {' '}
152
- {' '}
153
- <span className={classes.operators}>
154
- {(autocomplete.length === 1 && !upload.length) ? 'IS ' : 'IN '}
155
- </span>
156
- </span>
157
- ) : null}
118
+ <>
119
+ <div className={classes.queryWrapper}>
120
+ <Button
121
+ className={classes.clearQueryButton}
122
+ color="primary"
123
+ variant="outlined"
124
+ onClick={clearAll}
125
+ >
126
+ Clear Query
127
+ </Button>
128
+ <span className={classes.divider} />
129
+ <span className={classes.queryContainer}>
130
+ {/* Local Find Selections */}
131
+ {/* TODO: Refactor this into a separate component */}
132
+ {(autocomplete.length || upload.length) ? (
158
133
  <span>
159
- {(((upload.length > 0 ? 1 : 0) + autocomplete.length) > 1)
160
- ? <span className={classes.bracketsOpen}>(</span>
161
- : null}
162
- {upload.length && autocomplete.length ? (
163
- <>
164
- {' '}
134
+ {/* Standalone case set button */}
135
+ {(upload.length && !autocomplete.length)
136
+ ? (
165
137
  <span
166
- className={clsx(classes.filterCheckboxes, classes.localFind)}
138
+ className={clsx(classes.filterCheckboxes, classes.localFindBackground)}
167
139
  onClick={clearUpload}
168
140
  >
169
141
  INPUT CASE SET
170
142
  </span>
171
- {' '}
172
- </>
173
- ) : null}
174
- {autocomplete.slice(0, noOfItems).map((d, idx) => (
175
- <>
143
+ ) : null}
144
+ {autocomplete.length
145
+ ? (
146
+ <span>
147
+ {' '}
148
+ <span
149
+ className={clsx(classes.filterName, classes.localFindBackground)}
150
+ onClick={clearAutocomplete}
151
+ >
152
+ Case ID
153
+ </span>
154
+ {' '}
155
+ {' '}
156
+ <span className={classes.operators}>
157
+ {(autocomplete.length === 1 && !upload.length) ? 'IS ' : 'IN '}
158
+ </span>
159
+ </span>
160
+ ) : null}
161
+ <span>
162
+ {(((upload.length > 0 ? 1 : 0) + autocomplete.length) > 1)
163
+ ? <span className={classes.bracketsOpen}>(</span>
164
+ : null}
165
+ {upload.length && autocomplete.length ? (
166
+ <>
167
+ {' '}
168
+ <span
169
+ className={clsx(classes.filterCheckboxes, classes.localFind)}
170
+ onClick={clearUpload}
171
+ >
172
+ INPUT CASE SET
173
+ </span>
174
+ {' '}
175
+ </>
176
+ ) : null}
177
+ {autocomplete.slice(0, noOfItems).map((d, idx) => (
178
+ <>
179
+ <span
180
+ className={clsx(classes.filterCheckboxes, classes.facetSectionCases)}
181
+ key={idx}
182
+ onClick={() => deleteAutocompleteItem(d.title)}
183
+ >
184
+ {d.title}
185
+ </span>
186
+ {idx === (noOfItems - 1) ? null : ' '}
187
+ </>
188
+ ))}
189
+ {autocomplete.length > maxItems && (
190
+ <>
191
+ {
192
+ displayAllActiveFilters
193
+ ? (
194
+ <span
195
+ className={classes.expandBtn}
196
+ onClick={() => setExpand(!expand)}
197
+ >
198
+ ...
199
+ </span>
200
+ )
201
+ : '...'
202
+ }
203
+ </>
204
+ )}
205
+ {(expand && autocomplete.length > maxItems) && (
176
206
  <span
177
- className={clsx(classes.filterCheckboxes, classes.facetSectionCases)}
178
- key={idx}
179
- onClick={() => deleteAutocompleteItem(d.title)}
207
+ className={classes.collapseBtn}
208
+ onClick={() => setExpand(!expand)}
180
209
  >
181
- {d.title}
210
+ {' LESS'}
182
211
  </span>
183
- {idx === (noOfItems - 1) ? null : ' '}
184
- </>
185
- ))}
186
- {autocomplete.length > maxItems && (
187
- <>
188
- {
189
- displayAllActiveFilters
190
- ? (
191
- <span
192
- className={classes.expandBtn}
193
- onClick={() => setExpand(!expand)}
194
- >
195
- ...
196
- </span>
197
- )
198
- : '...'
199
- }
200
- </>
201
- )}
202
- {(expand && autocomplete.length > maxItems) && (
203
- <span
204
- className={classes.collapseBtn}
205
- onClick={() => setExpand(!expand)}
206
- >
207
- {' LESS'}
208
- </span>
209
- )}
210
- {(((upload.length > 0 ? 1 : 0) + autocomplete.length) > 1)
211
- ? <span className={classes.bracketsClose}>)</span>
212
- : null}
212
+ )}
213
+ {(((upload.length > 0 ? 1 : 0) + autocomplete.length) > 1)
214
+ ? <span className={classes.bracketsClose}>)</span>
215
+ : null}
216
+ </span>
213
217
  </span>
214
- </span>
215
- ) : null}
216
-
217
- {/* Facet Sidebar Selections */}
218
- {((autocomplete.length || upload.length) && mappedInputs.length)
219
- ? <span className={classes.operators}> AND </span>
220
- : null}
221
- {mappedInputs.map((filter, index) => (
222
- <span className={clsName(filter.section)}>
223
- <Filter
224
- index={index}
225
- type={filter.type}
226
- data={filter}
227
- maxItems={maxItems}
228
- displayAllActiveFilters={displayAllActiveFilters}
218
+ ) : null}
219
+
220
+ {/* Facet Sidebar Selections */}
221
+ {((autocomplete.length || upload.length) && mappedInputs.length)
222
+ ? <span className={classes.operators}> AND </span>
223
+ : null}
224
+ {mappedInputs.map((filter, index) => (
225
+ <span className={clsName(filter.section)}>
226
+ <Filter
227
+ index={index}
228
+ type={filter.type}
229
+ data={filter}
230
+ maxItems={maxItems}
231
+ displayAllActiveFilters={displayAllActiveFilters}
232
+ classes={classes}
233
+ onSectionClick={filter.type === CHECKBOX
234
+ ? resetFacetSection
235
+ : resetFacetSlider}
236
+ onItemClick={filter.type === CHECKBOX
237
+ ? resetFacetCheckbox
238
+ : resetFacetSlider}
239
+ />
240
+ </span>
241
+ ))}
242
+ </span>
243
+ {
244
+ (viewQueryURL && queryURLRootPath) && (
245
+ <QueryUrl
229
246
  classes={classes}
230
- onSectionClick={filter.type === CHECKBOX
231
- ? resetFacetSection
232
- : resetFacetSlider}
233
- onItemClick={filter.type === CHECKBOX
234
- ? resetFacetCheckbox
235
- : resetFacetSlider}
247
+ localFind={localFind}
248
+ filterItems={mappedInputs}
249
+ rootPath={queryURLRootPath}
236
250
  />
237
- </span>
238
- ))}
239
- </span>
240
- </div>
251
+ )
252
+ }
253
+ </div>
254
+ </>
241
255
  );
242
256
  }),
243
257
  };
@@ -12,6 +12,21 @@ 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
+ * root path of bento app
22
+ * @var {boolean}
23
+ */
24
+ rootPath: null,
25
+ /**
26
+ * display query URL
27
+ * @var {boolean}
28
+ */
29
+ viewQueryURL: false,
15
30
  },
16
31
 
17
32
  /* Component Helper Functions */