@bento-core/query-bar 1.0.0-c3dc.7 → 1.0.0-c3dc.9
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/dist/components/QueryUrl.js +9 -3
- package/dist/components/SliderFilter.js +34 -3
- package/dist/generators/QueryBarGenerator.js +4 -2
- package/dist/generators/config.js +10 -1
- package/package.json +2 -2
- package/src/components/QueryUrl.js +10 -3
- package/src/components/SliderFilter.js +47 -13
- package/src/generators/QueryBarGenerator.js +6 -1
- package/src/generators/config.js +10 -0
|
@@ -22,7 +22,8 @@ const QueryUrl = _ref => {
|
|
|
22
22
|
filterItems,
|
|
23
23
|
localFind = {},
|
|
24
24
|
rootPath,
|
|
25
|
-
queryUrlCharacterLimit = 70
|
|
25
|
+
queryUrlCharacterLimit = 70,
|
|
26
|
+
generateUrl
|
|
26
27
|
} = _ref;
|
|
27
28
|
const [display, setDisplay] = (0, _react.useState)(false);
|
|
28
29
|
const toggleDisplay = () => setDisplay(prevDisplay => !prevDisplay);
|
|
@@ -36,13 +37,18 @@ const QueryUrl = _ref => {
|
|
|
36
37
|
acc[datafield] = items;
|
|
37
38
|
return acc;
|
|
38
39
|
}, {});
|
|
39
|
-
const
|
|
40
|
-
const url =
|
|
40
|
+
const queryString = JSON.stringify(_objectSpread(_objectSpread({}, pathFilterParams), localFind));
|
|
41
|
+
const [url, setUrl] = (0, _react.useState)('');
|
|
41
42
|
const copyUrl = async () => {
|
|
42
43
|
toggleOpen();
|
|
43
44
|
await navigator.clipboard.writeText(url);
|
|
44
45
|
};
|
|
45
46
|
const queryRef = (0, _react.useRef)(null);
|
|
47
|
+
(0, _react.useEffect)(() => {
|
|
48
|
+
if (display && generateUrl) {
|
|
49
|
+
generateUrl(queryString, rootPath, setUrl);
|
|
50
|
+
}
|
|
51
|
+
}, [display]);
|
|
46
52
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
47
53
|
ref: queryRef,
|
|
48
54
|
className: classes.urlContainer
|
|
@@ -17,18 +17,49 @@ var _default = _ref => {
|
|
|
17
17
|
} = _ref;
|
|
18
18
|
const {
|
|
19
19
|
items,
|
|
20
|
-
section
|
|
20
|
+
section,
|
|
21
|
+
unknownAges
|
|
21
22
|
} = data;
|
|
23
|
+
const getDisplayContent = () => {
|
|
24
|
+
const baseLabel = data.label;
|
|
25
|
+
const hasRange = items && items.length >= 2;
|
|
26
|
+
|
|
27
|
+
// If unknownAges is 'only', we're showing only unknown ages
|
|
28
|
+
if (unknownAges === 'only') {
|
|
29
|
+
return {
|
|
30
|
+
label: "".concat(baseLabel, " (Unknown Ages Only)"),
|
|
31
|
+
showRange: false,
|
|
32
|
+
rangeText: ''
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// If unknownAges is 'exclude', we're excluding unknown ages from the range
|
|
37
|
+
if (unknownAges === 'exclude') {
|
|
38
|
+
return {
|
|
39
|
+
label: "".concat(baseLabel, " (Unknown Ages Excluded)"),
|
|
40
|
+
showRange: hasRange,
|
|
41
|
+
rangeText: hasRange ? "".concat(items[0], " \u2013 ").concat(items[1]) : ''
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Default: unknownAges is 'include' or not set
|
|
46
|
+
return {
|
|
47
|
+
label: baseLabel,
|
|
48
|
+
showRange: hasRange,
|
|
49
|
+
rangeText: hasRange ? "".concat(items[0], " \u2013 ").concat(items[1]) : ''
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const displayContent = getDisplayContent();
|
|
22
53
|
return /*#__PURE__*/_react.default.createElement("span", null, /*#__PURE__*/_react.default.createElement("span", null, ' ', index !== 0 ? /*#__PURE__*/_react.default.createElement("span", {
|
|
23
54
|
className: classes.operators
|
|
24
55
|
}, " AND ") : '', /*#__PURE__*/_react.default.createElement("span", {
|
|
25
56
|
className: (0, _clsx.default)(classes.filterName, classes["facetSection".concat(section, "Background")]),
|
|
26
57
|
onClick: () => onSectionClick(data)
|
|
27
|
-
},
|
|
58
|
+
}, displayContent.label), ' '), displayContent.showRange && /*#__PURE__*/_react.default.createElement("span", null, ' ', /*#__PURE__*/_react.default.createElement("span", {
|
|
28
59
|
className: classes.operators
|
|
29
60
|
}, "IS BETWEEN", ' '), /*#__PURE__*/_react.default.createElement("span", {
|
|
30
61
|
className: (0, _clsx.default)(classes.filterCheckboxes, classes["facetSection".concat(section)]),
|
|
31
62
|
onClick: () => onItemClick(data, items[0])
|
|
32
|
-
},
|
|
63
|
+
}, displayContent.rangeText)));
|
|
33
64
|
};
|
|
34
65
|
exports.default = _default;
|
|
@@ -45,6 +45,7 @@ const QueryBarGenerator = function QueryBarGenerator() {
|
|
|
45
45
|
const resetFacetSection = functions && typeof functions.resetFacetSection === 'function' ? functions.resetFacetSection : _config.default.functions.resetFacetSection;
|
|
46
46
|
const resetFacetCheckbox = functions && typeof functions.resetFacetCheckbox === 'function' ? functions.resetFacetCheckbox : _config.default.functions.resetFacetCheckbox;
|
|
47
47
|
const resetFacetSlider = functions && typeof functions.resetFacetSlider === 'function' ? functions.resetFacetSlider : _config.default.functions.resetFacetSlider;
|
|
48
|
+
const generateUrl = functions && typeof functions.generateUrl === 'function' ? functions.generateUrl : _config.default.functions.generateUrl;
|
|
48
49
|
return {
|
|
49
50
|
QueryBar: (0, _core.withStyles)(customStyles || _styles.default, {
|
|
50
51
|
withTheme: true
|
|
@@ -81,7 +82,7 @@ const QueryBarGenerator = function QueryBarGenerator() {
|
|
|
81
82
|
return _objectSpread(_objectSpread({}, facet), {}, {
|
|
82
83
|
items: itemKeys
|
|
83
84
|
});
|
|
84
|
-
}).filter(facet => facet.items.length > 0);
|
|
85
|
+
}).filter(facet => facet.items.length > 0 || facet.unknownAges && facet.unknownAges !== 'include');
|
|
85
86
|
if ((mappedInputs.length || autocomplete.length || upload.length) <= 0) {
|
|
86
87
|
return null;
|
|
87
88
|
}
|
|
@@ -164,7 +165,8 @@ const QueryBarGenerator = function QueryBarGenerator() {
|
|
|
164
165
|
localFind: localFind,
|
|
165
166
|
filterItems: mappedInputs,
|
|
166
167
|
rootPath: queryURLRootPath,
|
|
167
|
-
queryUrlCharacterLimit: queryUrlCharacterLimit
|
|
168
|
+
queryUrlCharacterLimit: queryUrlCharacterLimit,
|
|
169
|
+
generateUrl: generateUrl
|
|
168
170
|
}));
|
|
169
171
|
})
|
|
170
172
|
};
|
|
@@ -77,7 +77,16 @@ var _default = {
|
|
|
77
77
|
* @param {object} section the configuration object for the section
|
|
78
78
|
* @returns {void}
|
|
79
79
|
*/
|
|
80
|
-
resetFacetSlider: section => {}
|
|
80
|
+
resetFacetSlider: section => {},
|
|
81
|
+
/**
|
|
82
|
+
* Generate a query URL by calling the interop service
|
|
83
|
+
*
|
|
84
|
+
* @param {string} queryStr the query string to encode
|
|
85
|
+
* @param {string} root the root path for the URL
|
|
86
|
+
* @param {function} setUrlCallback callback function to set the generated URL
|
|
87
|
+
* @returns {Promise<void>}
|
|
88
|
+
*/
|
|
89
|
+
generateUrl: async (queryStr, root, setUrlCallback) => {}
|
|
81
90
|
}
|
|
82
91
|
};
|
|
83
92
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento-core/query-bar",
|
|
3
|
-
"version": "1.0.0-c3dc.
|
|
3
|
+
"version": "1.0.0-c3dc.9",
|
|
4
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:",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"react-redux": "^7.2.1"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@bento-core/facet-filter": "^1.0.1-c3dc.
|
|
26
|
+
"@bento-core/facet-filter": "^1.0.1-c3dc.9",
|
|
27
27
|
"lodash": "^4.17.20"
|
|
28
28
|
},
|
|
29
29
|
"author": "CTOS Bento Team",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useRef } from 'react';
|
|
1
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import {
|
|
4
4
|
Button,
|
|
@@ -18,6 +18,7 @@ const QueryUrl = ({
|
|
|
18
18
|
localFind = {},
|
|
19
19
|
rootPath,
|
|
20
20
|
queryUrlCharacterLimit = 70,
|
|
21
|
+
generateUrl,
|
|
21
22
|
}) => {
|
|
22
23
|
const [display, setDisplay] = useState(false);
|
|
23
24
|
const toggleDisplay = () => setDisplay((prevDisplay) => !prevDisplay);
|
|
@@ -31,11 +32,11 @@ const QueryUrl = ({
|
|
|
31
32
|
return acc;
|
|
32
33
|
}, {});
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
+
const queryString = JSON.stringify({
|
|
35
36
|
...pathFilterParams,
|
|
36
37
|
...localFind,
|
|
37
38
|
});
|
|
38
|
-
const url =
|
|
39
|
+
const [url, setUrl] = useState('');
|
|
39
40
|
|
|
40
41
|
const copyUrl = async () => {
|
|
41
42
|
toggleOpen();
|
|
@@ -44,6 +45,12 @@ const QueryUrl = ({
|
|
|
44
45
|
|
|
45
46
|
const queryRef = useRef(null);
|
|
46
47
|
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (display && generateUrl) {
|
|
50
|
+
generateUrl(queryString, rootPath, setUrl);
|
|
51
|
+
}
|
|
52
|
+
}, [display]);
|
|
53
|
+
|
|
47
54
|
return (
|
|
48
55
|
<>
|
|
49
56
|
<div ref={queryRef} className={classes.urlContainer}>
|
|
@@ -5,7 +5,39 @@ export default ({
|
|
|
5
5
|
index, data, classes,
|
|
6
6
|
onSectionClick, onItemClick,
|
|
7
7
|
}) => {
|
|
8
|
-
const { items, section } = data;
|
|
8
|
+
const { items, section, unknownAges } = data;
|
|
9
|
+
|
|
10
|
+
const getDisplayContent = () => {
|
|
11
|
+
const baseLabel = data.label;
|
|
12
|
+
const hasRange = items && items.length >= 2;
|
|
13
|
+
|
|
14
|
+
// If unknownAges is 'only', we're showing only unknown ages
|
|
15
|
+
if (unknownAges === 'only') {
|
|
16
|
+
return {
|
|
17
|
+
label: `${baseLabel} (Unknown Ages Only)`,
|
|
18
|
+
showRange: false,
|
|
19
|
+
rangeText: '',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// If unknownAges is 'exclude', we're excluding unknown ages from the range
|
|
24
|
+
if (unknownAges === 'exclude') {
|
|
25
|
+
return {
|
|
26
|
+
label: `${baseLabel} (Unknown Ages Excluded)`,
|
|
27
|
+
showRange: hasRange,
|
|
28
|
+
rangeText: hasRange ? `${items[0]} – ${items[1]}` : '',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Default: unknownAges is 'include' or not set
|
|
33
|
+
return {
|
|
34
|
+
label: baseLabel,
|
|
35
|
+
showRange: hasRange,
|
|
36
|
+
rangeText: hasRange ? `${items[0]} – ${items[1]}` : '',
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const displayContent = getDisplayContent();
|
|
9
41
|
|
|
10
42
|
return (
|
|
11
43
|
<span>
|
|
@@ -16,23 +48,25 @@ export default ({
|
|
|
16
48
|
className={clsx(classes.filterName, classes[`facetSection${section}Background`])}
|
|
17
49
|
onClick={() => onSectionClick(data)}
|
|
18
50
|
>
|
|
19
|
-
{
|
|
51
|
+
{displayContent.label}
|
|
20
52
|
</span>
|
|
21
53
|
{' '}
|
|
22
54
|
</span>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<span className={classes.operators}>
|
|
26
|
-
IS BETWEEN
|
|
55
|
+
{displayContent.showRange && (
|
|
56
|
+
<span>
|
|
27
57
|
{' '}
|
|
58
|
+
<span className={classes.operators}>
|
|
59
|
+
IS BETWEEN
|
|
60
|
+
{' '}
|
|
61
|
+
</span>
|
|
62
|
+
<span
|
|
63
|
+
className={clsx(classes.filterCheckboxes, classes[`facetSection${section}`])}
|
|
64
|
+
onClick={() => onItemClick(data, items[0])}
|
|
65
|
+
>
|
|
66
|
+
{displayContent.rangeText}
|
|
67
|
+
</span>
|
|
28
68
|
</span>
|
|
29
|
-
|
|
30
|
-
className={clsx(classes.filterCheckboxes, classes[`facetSection${section}`])}
|
|
31
|
-
onClick={() => onItemClick(data, items[0])}
|
|
32
|
-
>
|
|
33
|
-
{`${items[0]} – ${items[1]}`}
|
|
34
|
-
</span>
|
|
35
|
-
</span>
|
|
69
|
+
)}
|
|
36
70
|
</span>
|
|
37
71
|
);
|
|
38
72
|
};
|
|
@@ -61,6 +61,10 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
|
|
|
61
61
|
? functions.resetFacetSlider
|
|
62
62
|
: DEFAULT_CONFIG.functions.resetFacetSlider;
|
|
63
63
|
|
|
64
|
+
const generateUrl = functions && typeof functions.generateUrl === 'function'
|
|
65
|
+
? functions.generateUrl
|
|
66
|
+
: DEFAULT_CONFIG.functions.generateUrl;
|
|
67
|
+
|
|
64
68
|
return {
|
|
65
69
|
QueryBar: withStyles(customStyles || DEFAULT_STYLES,
|
|
66
70
|
{ withTheme: true })((props) => {
|
|
@@ -87,7 +91,7 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
|
|
|
87
91
|
|
|
88
92
|
return { ...facet, items: itemKeys };
|
|
89
93
|
})
|
|
90
|
-
.filter((facet) => facet.items.length > 0);
|
|
94
|
+
.filter((facet) => facet.items.length > 0 || (facet.unknownAges && facet.unknownAges !== 'include'));
|
|
91
95
|
|
|
92
96
|
if ((mappedInputs.length || autocomplete.length || upload.length) <= 0) {
|
|
93
97
|
return null;
|
|
@@ -247,6 +251,7 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
|
|
|
247
251
|
filterItems={mappedInputs}
|
|
248
252
|
rootPath={queryURLRootPath}
|
|
249
253
|
queryUrlCharacterLimit={queryUrlCharacterLimit}
|
|
254
|
+
generateUrl={generateUrl}
|
|
250
255
|
/>
|
|
251
256
|
)
|
|
252
257
|
}
|
package/src/generators/config.js
CHANGED
|
@@ -80,5 +80,15 @@ export default {
|
|
|
80
80
|
* @returns {void}
|
|
81
81
|
*/
|
|
82
82
|
resetFacetSlider: (section) => {},
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Generate a query URL by calling the interop service
|
|
86
|
+
*
|
|
87
|
+
* @param {string} queryStr the query string to encode
|
|
88
|
+
* @param {string} root the root path for the URL
|
|
89
|
+
* @param {function} setUrlCallback callback function to set the generated URL
|
|
90
|
+
* @returns {Promise<void>}
|
|
91
|
+
*/
|
|
92
|
+
generateUrl: async (queryStr, root, setUrlCallback) => {},
|
|
83
93
|
},
|
|
84
94
|
};
|