@blaze-cms/plugin-search-ui 0.110.0-alpha.1
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/CHANGELOG.md +345 -0
- package/LICENSE +674 -0
- package/README.md +45 -0
- package/babel.config.js +3 -0
- package/jest.config.js +5 -0
- package/lib/application/query/index.js +32 -0
- package/lib/application/query/index.js.map +1 -0
- package/lib/components/SearchAdmin/RecentSearches/RecentSearches.js +62 -0
- package/lib/components/SearchAdmin/RecentSearches/RecentSearches.js.map +1 -0
- package/lib/components/SearchAdmin/RecentSearches/index.js +16 -0
- package/lib/components/SearchAdmin/RecentSearches/index.js.map +1 -0
- package/lib/components/SearchAdmin/SearchAdmin.js +191 -0
- package/lib/components/SearchAdmin/SearchAdmin.js.map +1 -0
- package/lib/components/SearchAdmin/SearchBar/SearchBar.js +72 -0
- package/lib/components/SearchAdmin/SearchBar/SearchBar.js.map +1 -0
- package/lib/components/SearchAdmin/SearchBar/index.js +16 -0
- package/lib/components/SearchAdmin/SearchBar/index.js.map +1 -0
- package/lib/components/SearchAdmin/SearchResults/SearchResults.js +200 -0
- package/lib/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -0
- package/lib/components/SearchAdmin/SearchResults/index.js +16 -0
- package/lib/components/SearchAdmin/SearchResults/index.js.map +1 -0
- package/lib/components/SearchAdmin/TriggerModal/TriggerModal.js +30 -0
- package/lib/components/SearchAdmin/TriggerModal/TriggerModal.js.map +1 -0
- package/lib/components/SearchAdmin/TriggerModal/index.js +16 -0
- package/lib/components/SearchAdmin/TriggerModal/index.js.map +1 -0
- package/lib/components/SearchAdmin/index.js +16 -0
- package/lib/components/SearchAdmin/index.js.map +1 -0
- package/lib/components/SearchPublishedContent/SearchPublishedContent.js +216 -0
- package/lib/components/SearchPublishedContent/SearchPublishedContent.js.map +1 -0
- package/lib/components/SearchPublishedContent/index.js +16 -0
- package/lib/components/SearchPublishedContent/index.js.map +1 -0
- package/lib/components/useLocalStorage/index.js +16 -0
- package/lib/components/useLocalStorage/index.js.map +1 -0
- package/lib/components/useLocalStorage/useLocalStorage.js +36 -0
- package/lib/components/useLocalStorage/useLocalStorage.js.map +1 -0
- package/lib/components/useSearch/index.js +16 -0
- package/lib/components/useSearch/index.js.map +1 -0
- package/lib/components/useSearch/useSearch.js +154 -0
- package/lib/components/useSearch/useSearch.js.map +1 -0
- package/lib/components/useSearchResults/index.js +16 -0
- package/lib/components/useSearchResults/index.js.map +1 -0
- package/lib/components/useSearchResults/useSearchResults.js +102 -0
- package/lib/components/useSearchResults/useSearchResults.js.map +1 -0
- package/lib/constants.js +25 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.js +34 -0
- package/lib/index.js.map +1 -0
- package/lib-es/application/query/index.js +34 -0
- package/lib-es/application/query/index.js.map +1 -0
- package/lib-es/components/SearchAdmin/RecentSearches/RecentSearches.js +40 -0
- package/lib-es/components/SearchAdmin/RecentSearches/RecentSearches.js.map +1 -0
- package/lib-es/components/SearchAdmin/RecentSearches/index.js +3 -0
- package/lib-es/components/SearchAdmin/RecentSearches/index.js.map +1 -0
- package/lib-es/components/SearchAdmin/SearchAdmin.js +126 -0
- package/lib-es/components/SearchAdmin/SearchAdmin.js.map +1 -0
- package/lib-es/components/SearchAdmin/SearchBar/SearchBar.js +54 -0
- package/lib-es/components/SearchAdmin/SearchBar/SearchBar.js.map +1 -0
- package/lib-es/components/SearchAdmin/SearchBar/index.js +3 -0
- package/lib-es/components/SearchAdmin/SearchBar/index.js.map +1 -0
- package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js +120 -0
- package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -0
- package/lib-es/components/SearchAdmin/SearchResults/index.js +3 -0
- package/lib-es/components/SearchAdmin/SearchResults/index.js.map +1 -0
- package/lib-es/components/SearchAdmin/TriggerModal/TriggerModal.js +16 -0
- package/lib-es/components/SearchAdmin/TriggerModal/TriggerModal.js.map +1 -0
- package/lib-es/components/SearchAdmin/TriggerModal/index.js +3 -0
- package/lib-es/components/SearchAdmin/TriggerModal/index.js.map +1 -0
- package/lib-es/components/SearchAdmin/index.js +3 -0
- package/lib-es/components/SearchAdmin/index.js.map +1 -0
- package/lib-es/components/SearchPublishedContent/SearchPublishedContent.js +157 -0
- package/lib-es/components/SearchPublishedContent/SearchPublishedContent.js.map +1 -0
- package/lib-es/components/SearchPublishedContent/index.js +3 -0
- package/lib-es/components/SearchPublishedContent/index.js.map +1 -0
- package/lib-es/components/useLocalStorage/index.js +3 -0
- package/lib-es/components/useLocalStorage/index.js.map +1 -0
- package/lib-es/components/useLocalStorage/useLocalStorage.js +19 -0
- package/lib-es/components/useLocalStorage/useLocalStorage.js.map +1 -0
- package/lib-es/components/useSearch/index.js +3 -0
- package/lib-es/components/useSearch/index.js.map +1 -0
- package/lib-es/components/useSearch/useSearch.js +100 -0
- package/lib-es/components/useSearch/useSearch.js.map +1 -0
- package/lib-es/components/useSearchResults/index.js +3 -0
- package/lib-es/components/useSearchResults/index.js.map +1 -0
- package/lib-es/components/useSearchResults/useSearchResults.js +57 -0
- package/lib-es/components/useSearchResults/useSearchResults.js.map +1 -0
- package/lib-es/constants.js +10 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/index.js +5 -0
- package/lib-es/index.js.map +1 -0
- package/package.json +56 -0
- package/src/application/query/index.js +28 -0
- package/src/components/SearchAdmin/RecentSearches/RecentSearches.js +33 -0
- package/src/components/SearchAdmin/RecentSearches/index.js +3 -0
- package/src/components/SearchAdmin/SearchAdmin.js +129 -0
- package/src/components/SearchAdmin/SearchBar/SearchBar.js +58 -0
- package/src/components/SearchAdmin/SearchBar/index.js +3 -0
- package/src/components/SearchAdmin/SearchResults/SearchResults.js +112 -0
- package/src/components/SearchAdmin/SearchResults/index.js +3 -0
- package/src/components/SearchAdmin/TriggerModal/TriggerModal.js +17 -0
- package/src/components/SearchAdmin/TriggerModal/index.js +3 -0
- package/src/components/SearchAdmin/index.js +3 -0
- package/src/components/SearchPublishedContent/SearchPublishedContent.js +157 -0
- package/src/components/SearchPublishedContent/index.js +3 -0
- package/src/components/useLocalStorage/index.js +3 -0
- package/src/components/useLocalStorage/useLocalStorage.js +18 -0
- package/src/components/useSearch/index.js +3 -0
- package/src/components/useSearch/useSearch.js +85 -0
- package/src/components/useSearchResults/index.js +3 -0
- package/src/components/useSearchResults/useSearchResults.js +38 -0
- package/src/constants.js +19 -0
- package/src/index.js +5 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
const SearchBar = ({
|
|
5
|
+
handleKeyDown,
|
|
6
|
+
searchInputRef,
|
|
7
|
+
handleSearchTerm,
|
|
8
|
+
searchTerm,
|
|
9
|
+
toggleSearchModal,
|
|
10
|
+
close,
|
|
11
|
+
search,
|
|
12
|
+
placeholder
|
|
13
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
14
|
+
className: "search__wrapper"
|
|
15
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
16
|
+
onKeyDown: handleKeyDown,
|
|
17
|
+
ref: searchInputRef,
|
|
18
|
+
placeholder: placeholder,
|
|
19
|
+
type: "text",
|
|
20
|
+
onChange: handleSearchTerm,
|
|
21
|
+
value: searchTerm
|
|
22
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
23
|
+
onClick: search,
|
|
24
|
+
role: "button",
|
|
25
|
+
className: "icon-button icon-button--search icon-button--toggle"
|
|
26
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
27
|
+
className: "material-icons"
|
|
28
|
+
}, "search")), close && /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
className: "modal__close"
|
|
30
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
31
|
+
className: "material-icons",
|
|
32
|
+
onClick: toggleSearchModal,
|
|
33
|
+
role: "button"
|
|
34
|
+
}, "close")));
|
|
35
|
+
|
|
36
|
+
SearchBar.propTypes = {
|
|
37
|
+
close: PropTypes.bool,
|
|
38
|
+
handleKeyDown: PropTypes.func.isRequired,
|
|
39
|
+
searchInputRef: PropTypes.object,
|
|
40
|
+
handleSearchTerm: PropTypes.func.isRequired,
|
|
41
|
+
searchTerm: PropTypes.string,
|
|
42
|
+
toggleSearchModal: PropTypes.func,
|
|
43
|
+
search: PropTypes.func.isRequired,
|
|
44
|
+
placeholder: PropTypes.string
|
|
45
|
+
};
|
|
46
|
+
SearchBar.defaultProps = {
|
|
47
|
+
searchTerm: '',
|
|
48
|
+
close: true,
|
|
49
|
+
placeholder: 'Search...',
|
|
50
|
+
toggleSearchModal: null,
|
|
51
|
+
searchInputRef: null
|
|
52
|
+
};
|
|
53
|
+
export default SearchBar;
|
|
54
|
+
//# sourceMappingURL=SearchBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SearchAdmin/SearchBar/SearchBar.js"],"names":["React","PropTypes","SearchBar","handleKeyDown","searchInputRef","handleSearchTerm","searchTerm","toggleSearchModal","close","search","placeholder","propTypes","bool","func","isRequired","object","string","defaultProps"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;;AAEA,MAAMC,SAAS,GAAG,CAAC;AACjBC,EAAAA,aADiB;AAEjBC,EAAAA,cAFiB;AAGjBC,EAAAA,gBAHiB;AAIjBC,EAAAA,UAJiB;AAKjBC,EAAAA,iBALiB;AAMjBC,EAAAA,KANiB;AAOjBC,EAAAA,MAPiB;AAQjBC,EAAAA;AARiB,CAAD,kBAUhB;AAAK,EAAA,SAAS,EAAC;AAAf,gBACE;AACE,EAAA,SAAS,EAAEP,aADb;AAEE,EAAA,GAAG,EAAEC,cAFP;AAGE,EAAA,WAAW,EAAEM,WAHf;AAIE,EAAA,IAAI,EAAC,MAJP;AAKE,EAAA,QAAQ,EAAEL,gBALZ;AAME,EAAA,KAAK,EAAEC;AANT,EADF,eASE;AACE,EAAA,OAAO,EAAEG,MADX;AAEE,EAAA,IAAI,EAAC,QAFP;AAGE,EAAA,SAAS,EAAC;AAHZ,gBAIE;AAAG,EAAA,SAAS,EAAC;AAAb,YAJF,CATF,EAeGD,KAAK,iBACJ;AAAK,EAAA,SAAS,EAAC;AAAf,gBACE;AAAG,EAAA,SAAS,EAAC,gBAAb;AAA8B,EAAA,OAAO,EAAED,iBAAvC;AAA0D,EAAA,IAAI,EAAC;AAA/D,WADF,CAhBJ,CAVF;;AAmCAL,SAAS,CAACS,SAAV,GAAsB;AACpBH,EAAAA,KAAK,EAAEP,SAAS,CAACW,IADG;AAEpBT,EAAAA,aAAa,EAAEF,SAAS,CAACY,IAAV,CAAeC,UAFV;AAGpBV,EAAAA,cAAc,EAAEH,SAAS,CAACc,MAHN;AAIpBV,EAAAA,gBAAgB,EAAEJ,SAAS,CAACY,IAAV,CAAeC,UAJb;AAKpBR,EAAAA,UAAU,EAAEL,SAAS,CAACe,MALF;AAMpBT,EAAAA,iBAAiB,EAAEN,SAAS,CAACY,IANT;AAOpBJ,EAAAA,MAAM,EAAER,SAAS,CAACY,IAAV,CAAeC,UAPH;AAQpBJ,EAAAA,WAAW,EAAET,SAAS,CAACe;AARH,CAAtB;AAWAd,SAAS,CAACe,YAAV,GAAyB;AACvBX,EAAAA,UAAU,EAAE,EADW;AAEvBE,EAAAA,KAAK,EAAE,IAFgB;AAGvBE,EAAAA,WAAW,EAAE,WAHU;AAIvBH,EAAAA,iBAAiB,EAAE,IAJI;AAKvBH,EAAAA,cAAc,EAAE;AALO,CAAzB;AAQA,eAAeF,SAAf","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst SearchBar = ({\n handleKeyDown,\n searchInputRef,\n handleSearchTerm,\n searchTerm,\n toggleSearchModal,\n close,\n search,\n placeholder\n}) => (\n <div className=\"search__wrapper\">\n <input\n onKeyDown={handleKeyDown}\n ref={searchInputRef}\n placeholder={placeholder}\n type=\"text\"\n onChange={handleSearchTerm}\n value={searchTerm}\n />\n <span\n onClick={search}\n role=\"button\"\n className=\"icon-button icon-button--search icon-button--toggle\">\n <i className=\"material-icons\">search</i>\n </span>\n {close && (\n <div className=\"modal__close\">\n <i className=\"material-icons\" onClick={toggleSearchModal} role=\"button\">\n close\n </i>\n </div>\n )}\n </div>\n);\n\nSearchBar.propTypes = {\n close: PropTypes.bool,\n handleKeyDown: PropTypes.func.isRequired,\n searchInputRef: PropTypes.object,\n handleSearchTerm: PropTypes.func.isRequired,\n searchTerm: PropTypes.string,\n toggleSearchModal: PropTypes.func,\n search: PropTypes.func.isRequired,\n placeholder: PropTypes.string\n};\n\nSearchBar.defaultProps = {\n searchTerm: '',\n close: true,\n placeholder: 'Search...',\n toggleSearchModal: null,\n searchInputRef: null\n};\n\nexport default SearchBar;\n"],"file":"SearchBar.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SearchAdmin/SearchBar/index.js"],"names":["SearchBar"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,aAAtB;AAEA,eAAeA,SAAf","sourcesContent":["import SearchBar from './SearchBar';\n\nexport default SearchBar;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
2
|
+
|
|
3
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import VirtualList from 'react-tiny-virtual-list';
|
|
7
|
+
import { withRouter } from 'react-router-dom';
|
|
8
|
+
import { SEARCH_RESULTS_OVER_SCAN_BUFFER, SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST, SEARCH_RESULTS_ITEM_SIZE, FILE } from '../../../constants';
|
|
9
|
+
|
|
10
|
+
const SearchResults = ({
|
|
11
|
+
currentValue,
|
|
12
|
+
loading,
|
|
13
|
+
results,
|
|
14
|
+
total,
|
|
15
|
+
setQueryParams,
|
|
16
|
+
closeModal,
|
|
17
|
+
history
|
|
18
|
+
}) => {
|
|
19
|
+
const [verifiedRanges, setVerifiedRanges] = useState([]);
|
|
20
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
21
|
+
|
|
22
|
+
const handleRenderedItems = async ({
|
|
23
|
+
startIndex
|
|
24
|
+
}) => {
|
|
25
|
+
const rowsLength = results.length;
|
|
26
|
+
const loadIndex = Math.floor(rowsLength / 2) - SEARCH_RESULTS_OVER_SCAN_BUFFER;
|
|
27
|
+
|
|
28
|
+
if (loadIndex > 0 && loadIndex < startIndex && !verifiedRanges.includes(loadIndex)) {
|
|
29
|
+
setQueryParams({
|
|
30
|
+
value: currentValue,
|
|
31
|
+
offset: results.length
|
|
32
|
+
});
|
|
33
|
+
setVerifiedRanges([...verifiedRanges, loadIndex]);
|
|
34
|
+
setCurrentIndex(startIndex + SEARCH_RESULTS_OVER_SCAN_BUFFER);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getNavigationRoute = ({
|
|
39
|
+
id,
|
|
40
|
+
docType
|
|
41
|
+
}) => docType === FILE ? `/media/edit/${id}` : `/data-listing/${docType}/update/${id}`;
|
|
42
|
+
|
|
43
|
+
const navigate = ({
|
|
44
|
+
id,
|
|
45
|
+
docType
|
|
46
|
+
}) => {
|
|
47
|
+
history.push(getNavigationRoute({
|
|
48
|
+
id,
|
|
49
|
+
docType
|
|
50
|
+
}));
|
|
51
|
+
closeModal();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getDateFormat = date => {
|
|
55
|
+
const newDate = new Date(date);
|
|
56
|
+
const day = `0${newDate.getDate()}`.slice(-2);
|
|
57
|
+
const month = `0${newDate.getMonth() + 1}`.slice(-2);
|
|
58
|
+
const year = String(newDate.getYear()).slice(-2);
|
|
59
|
+
return `${day}.${month}.${year}`;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement("span", null, "Loading..."), /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
className: "modal__content modal__content--search"
|
|
64
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
className: "header header--list"
|
|
66
|
+
}, /*#__PURE__*/React.createElement("h2", null, total, " results")), /*#__PURE__*/React.createElement(VirtualList, {
|
|
67
|
+
width: "100%",
|
|
68
|
+
height: window.innerHeight - SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST,
|
|
69
|
+
itemCount: results.length,
|
|
70
|
+
itemSize: SEARCH_RESULTS_ITEM_SIZE,
|
|
71
|
+
overscanCount: SEARCH_RESULTS_OVER_SCAN_BUFFER,
|
|
72
|
+
scrollToIndex: currentIndex,
|
|
73
|
+
onItemsRendered: handleRenderedItems,
|
|
74
|
+
renderItem: ({
|
|
75
|
+
index,
|
|
76
|
+
style
|
|
77
|
+
}) => {
|
|
78
|
+
const {
|
|
79
|
+
id,
|
|
80
|
+
docType,
|
|
81
|
+
updated,
|
|
82
|
+
name
|
|
83
|
+
} = results[index];
|
|
84
|
+
const updatedDate = updated ? getDateFormat(updated) : null;
|
|
85
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
86
|
+
key: index,
|
|
87
|
+
style: style,
|
|
88
|
+
className: "list__item--resultWrapper"
|
|
89
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
90
|
+
className: "list__item list__item--result"
|
|
91
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
92
|
+
className: "list__item-row list__item-row--result"
|
|
93
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
94
|
+
className: "badge badge--primary"
|
|
95
|
+
}, docType, " ", updatedDate), /*#__PURE__*/React.createElement("a", {
|
|
96
|
+
href: getNavigationRoute({
|
|
97
|
+
id,
|
|
98
|
+
docType
|
|
99
|
+
}),
|
|
100
|
+
onClick: () => navigate({
|
|
101
|
+
id,
|
|
102
|
+
docType
|
|
103
|
+
}),
|
|
104
|
+
className: "list__item-text list__item-text--result"
|
|
105
|
+
}, name))));
|
|
106
|
+
}
|
|
107
|
+
})));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
SearchResults.propTypes = {
|
|
111
|
+
loading: PropTypes.bool.isRequired,
|
|
112
|
+
results: PropTypes.array.isRequired,
|
|
113
|
+
total: PropTypes.number.isRequired,
|
|
114
|
+
setQueryParams: PropTypes.func.isRequired,
|
|
115
|
+
closeModal: PropTypes.func.isRequired,
|
|
116
|
+
history: PropTypes.object.isRequired,
|
|
117
|
+
currentValue: PropTypes.string.isRequired
|
|
118
|
+
};
|
|
119
|
+
export default withRouter(SearchResults);
|
|
120
|
+
//# sourceMappingURL=SearchResults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SearchAdmin/SearchResults/SearchResults.js"],"names":["React","useState","PropTypes","VirtualList","withRouter","SEARCH_RESULTS_OVER_SCAN_BUFFER","SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST","SEARCH_RESULTS_ITEM_SIZE","FILE","SearchResults","currentValue","loading","results","total","setQueryParams","closeModal","history","verifiedRanges","setVerifiedRanges","currentIndex","setCurrentIndex","handleRenderedItems","startIndex","rowsLength","length","loadIndex","Math","floor","includes","value","offset","getNavigationRoute","id","docType","navigate","push","getDateFormat","date","newDate","Date","day","getDate","slice","month","getMonth","year","String","getYear","window","innerHeight","index","style","updated","name","updatedDate","propTypes","bool","isRequired","array","number","func","object","string"],"mappings":"AAAA;;AACA;AACA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,WAAP,MAAwB,yBAAxB;AACA,SAASC,UAAT,QAA2B,kBAA3B;AACA,SACEC,+BADF,EAEEC,wCAFF,EAGEC,wBAHF,EAIEC,IAJF,QAKO,oBALP;;AAOA,MAAMC,aAAa,GAAG,CAAC;AACrBC,EAAAA,YADqB;AAErBC,EAAAA,OAFqB;AAGrBC,EAAAA,OA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AD,CAAhB,GAA4B,IAAvD;AACA,0BACE;AAAK,QAAA,GAAG,EAAEF,KAAV;AAAiB,QAAA,KAAK,EAAEC,KAAxB;AAA+B,QAAA,SAAS,EAAC;AAAzC,sBACE;AAAK,QAAA,SAAS,EAAC;AAAf,sBACE;AAAK,QAAA,SAAS,EAAC;AAAf,sBACE;AAAM,QAAA,SAAS,EAAC;AAAhB,SACGlB,OADH,OACaqB,WADb,CADF,eAIE;AACE,QAAA,IAAI,EAAEvB,kBAAkB,CAAC;AACvBC,UAAAA,EADuB;AAEvBC,UAAAA;AAFuB,SAAD,CAD1B;AAKE,QAAA,OAAO,EAAE,MACPC,QAAQ,CAAC;AACPF,UAAAA,EADO;AAEPC,UAAAA;AAFO,SAAD,CANZ;AAWE,QAAA,SAAS,EAAC;AAXZ,SAYGoB,IAZH,CAJF,CADF,CADF,CADF;AAyBD;AApCH,IAJF,CAFF,CADF;AAgDD,CAtFD;;AAwFA5C,aAAa,CAAC8C,SAAd,GAA0B;AACxB5C,EAAAA,OAAO,EAAET,SAAS,CAACsD,IAAV,CAAeC,UADA;AAExB7C,EAAAA,OAAO,EAAEV,SAAS,CAACwD,KAAV,CAAgBD,UAFD;AAGxB5C,EAAAA,KAAK,EAAEX,SAAS,CAACyD,MAAV,CAAiBF,UAHA;AAIxB3C,EAAAA,cAAc,EAAEZ,SAAS,CAAC0D,IAAV,CAAeH,UAJP;AAKxB1C,EAAAA,UAAU,EAAEb,SAAS,CAAC0D,IAAV,CAAeH,UALH;AAMxBzC,EAAAA,OAAO,EAAEd,SAAS,CAAC2D,MAAV,CAAiBJ,UANF;AAOxB/C,EAAAA,YAAY,EAAER,SAAS,CAAC4D,MAAV,CAAiBL;AAPP,CAA1B;AAUA,eAAerD,UAAU,CAACK,aAAD,CAAzB","sourcesContent":["/* eslint-disable jsx-a11y/anchor-is-valid */\n/* eslint-disable jsx-a11y/no-static-element-interactions */\nimport React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport VirtualList from 'react-tiny-virtual-list';\nimport { withRouter } from 'react-router-dom';\nimport {\n SEARCH_RESULTS_OVER_SCAN_BUFFER,\n SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST,\n SEARCH_RESULTS_ITEM_SIZE,\n FILE\n} from '../../../constants';\n\nconst SearchResults = ({\n currentValue,\n loading,\n results,\n total,\n setQueryParams,\n closeModal,\n history\n}) => {\n const [verifiedRanges, setVerifiedRanges] = useState([]);\n const [currentIndex, setCurrentIndex] = useState(0);\n\n const handleRenderedItems = async ({ startIndex }) => {\n const rowsLength = results.length;\n const loadIndex = Math.floor(rowsLength / 2) - SEARCH_RESULTS_OVER_SCAN_BUFFER;\n if (loadIndex > 0 && loadIndex < startIndex && !verifiedRanges.includes(loadIndex)) {\n setQueryParams({ value: currentValue, offset: results.length });\n setVerifiedRanges([...verifiedRanges, loadIndex]);\n setCurrentIndex(startIndex + SEARCH_RESULTS_OVER_SCAN_BUFFER);\n }\n };\n\n const getNavigationRoute = ({ id, docType }) =>\n docType === FILE ? `/media/edit/${id}` : `/data-listing/${docType}/update/${id}`;\n\n const navigate = ({ id, docType }) => {\n history.push(getNavigationRoute({ id, docType }));\n closeModal();\n };\n\n const getDateFormat = date => {\n const newDate = new Date(date);\n const day = `0${newDate.getDate()}`.slice(-2);\n const month = `0${newDate.getMonth() + 1}`.slice(-2);\n const year = String(newDate.getYear()).slice(-2);\n return `${day}.${month}.${year}`;\n };\n\n return (\n <>\n {loading && <span>Loading...</span>}\n <div className=\"modal__content modal__content--search\">\n <div className=\"header header--list\">\n <h2>{total} results</h2>\n </div>\n <VirtualList\n width=\"100%\"\n height={window.innerHeight - SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST}\n itemCount={results.length}\n itemSize={SEARCH_RESULTS_ITEM_SIZE}\n overscanCount={SEARCH_RESULTS_OVER_SCAN_BUFFER}\n scrollToIndex={currentIndex}\n onItemsRendered={handleRenderedItems}\n renderItem={({ index, style }) => {\n const { id, docType, updated, name } = results[index];\n const updatedDate = updated ? getDateFormat(updated) : null;\n return (\n <div key={index} style={style} className=\"list__item--resultWrapper\">\n <div className=\"list__item list__item--result\">\n <div className=\"list__item-row list__item-row--result\">\n <span className=\"badge badge--primary\">\n {docType} {updatedDate}\n </span>\n <a\n href={getNavigationRoute({\n id,\n docType\n })}\n onClick={() =>\n navigate({\n id,\n docType\n })\n }\n className=\"list__item-text list__item-text--result\">\n {name}\n </a>\n </div>\n </div>\n </div>\n );\n }}\n />\n </div>\n </>\n );\n};\n\nSearchResults.propTypes = {\n loading: PropTypes.bool.isRequired,\n results: PropTypes.array.isRequired,\n total: PropTypes.number.isRequired,\n setQueryParams: PropTypes.func.isRequired,\n closeModal: PropTypes.func.isRequired,\n history: PropTypes.object.isRequired,\n currentValue: PropTypes.string.isRequired\n};\n\nexport default withRouter(SearchResults);\n"],"file":"SearchResults.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SearchAdmin/SearchResults/index.js"],"names":["SearchResults"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,iBAA1B;AAEA,eAAeA,aAAf","sourcesContent":["import SearchResults from './SearchResults';\n\nexport default SearchResults;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
const TriggerModal = ({
|
|
5
|
+
toggleSearchModal
|
|
6
|
+
}) => /*#__PURE__*/React.createElement("span", {
|
|
7
|
+
role: "button",
|
|
8
|
+
className: "material-icons searchModal-search-icon",
|
|
9
|
+
onClick: toggleSearchModal
|
|
10
|
+
}, "search");
|
|
11
|
+
|
|
12
|
+
TriggerModal.propTypes = {
|
|
13
|
+
toggleSearchModal: PropTypes.func.isRequired
|
|
14
|
+
};
|
|
15
|
+
export default TriggerModal;
|
|
16
|
+
//# sourceMappingURL=TriggerModal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SearchAdmin/TriggerModal/TriggerModal.js"],"names":["React","PropTypes","TriggerModal","toggleSearchModal","propTypes","func","isRequired"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;;AAEA,MAAMC,YAAY,GAAG,CAAC;AAAEC,EAAAA;AAAF,CAAD,kBACnB;AACE,EAAA,IAAI,EAAC,QADP;AAEE,EAAA,SAAS,EAAC,wCAFZ;AAGE,EAAA,OAAO,EAAEA;AAHX,YADF;;AASAD,YAAY,CAACE,SAAb,GAAyB;AACvBD,EAAAA,iBAAiB,EAAEF,SAAS,CAACI,IAAV,CAAeC;AADX,CAAzB;AAIA,eAAeJ,YAAf","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst TriggerModal = ({ toggleSearchModal }) => (\n <span\n role=\"button\"\n className=\"material-icons searchModal-search-icon\"\n onClick={toggleSearchModal}>\n search\n </span>\n);\n\nTriggerModal.propTypes = {\n toggleSearchModal: PropTypes.func.isRequired\n};\n\nexport default TriggerModal;\n"],"file":"TriggerModal.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/SearchAdmin/TriggerModal/index.js"],"names":["TriggerModal"],"mappings":"AAAA,OAAOA,YAAP,MAAyB,gBAAzB;AAEA,eAAeA,YAAf","sourcesContent":["import TriggerModal from './TriggerModal';\n\nexport default TriggerModal;\n"],"file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SearchAdmin/index.js"],"names":["SearchAdmin"],"mappings":"AAAA,OAAOA,WAAP,MAAwB,eAAxB;AAEA,eAAeA,WAAf","sourcesContent":["import SearchAdmin from './SearchAdmin';\n\nexport default SearchAdmin;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { useDebounce } from '@blaze-react/utils/lib/customHooks';
|
|
5
|
+
import useSearchResults from '../useSearchResults';
|
|
6
|
+
import { SEARCH_PUBLISHED, DEFAULT_RESULTS_KEYS, SEARCH_BUTTON } from '../../constants';
|
|
7
|
+
|
|
8
|
+
const SearchPublishedContent = ({
|
|
9
|
+
entities,
|
|
10
|
+
children,
|
|
11
|
+
resultKeys,
|
|
12
|
+
getIsOpenSearchBar,
|
|
13
|
+
SearchIcon,
|
|
14
|
+
CloseIcon,
|
|
15
|
+
className,
|
|
16
|
+
onChange,
|
|
17
|
+
placeholder,
|
|
18
|
+
onEnterPress,
|
|
19
|
+
inputRef,
|
|
20
|
+
isSearchBarOpen,
|
|
21
|
+
fields
|
|
22
|
+
}) => {
|
|
23
|
+
const [displaySearchBar, setDisplaySearchBar] = useState(isSearchBarOpen);
|
|
24
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
25
|
+
const [previousSearchTerm, setPreviousSearchTerm] = useState(null);
|
|
26
|
+
const debouncedSearchTerm = useDebounce(searchTerm, 500);
|
|
27
|
+
const [{
|
|
28
|
+
loading,
|
|
29
|
+
results
|
|
30
|
+
}, setQueryParams] = useSearchResults({
|
|
31
|
+
queryKey: SEARCH_PUBLISHED,
|
|
32
|
+
resultKeys,
|
|
33
|
+
entities,
|
|
34
|
+
fields
|
|
35
|
+
});
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (isSearchBarOpen !== displaySearchBar) {
|
|
38
|
+
setDisplaySearchBar(isSearchBarOpen);
|
|
39
|
+
}
|
|
40
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
[isSearchBarOpen]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (inputRef && inputRef.current && displaySearchBar) {
|
|
44
|
+
inputRef.current.focus();
|
|
45
|
+
}
|
|
46
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
|
+
[displaySearchBar]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {
|
|
50
|
+
setQueryParams({
|
|
51
|
+
value: debouncedSearchTerm
|
|
52
|
+
});
|
|
53
|
+
setPreviousSearchTerm(debouncedSearchTerm);
|
|
54
|
+
}
|
|
55
|
+
}, [debouncedSearchTerm, previousSearchTerm, setQueryParams]);
|
|
56
|
+
|
|
57
|
+
const handleOnChange = ({
|
|
58
|
+
target: {
|
|
59
|
+
value = ''
|
|
60
|
+
} = {}
|
|
61
|
+
}) => {
|
|
62
|
+
onChange(value);
|
|
63
|
+
setSearchTerm(value);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const handleKeyPress = event => {
|
|
67
|
+
const onEnter = event.key === 'Enter';
|
|
68
|
+
onEnter && onEnterPress();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleSearchBar = () => {
|
|
72
|
+
const voidSearchTerm = '';
|
|
73
|
+
displaySearchBar && setSearchTerm(voidSearchTerm);
|
|
74
|
+
handleOnChange({
|
|
75
|
+
value: voidSearchTerm
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (isSearchBarOpen !== null) {
|
|
79
|
+
getIsOpenSearchBar(!displaySearchBar);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setDisplaySearchBar(!displaySearchBar);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const searchWrapperClassname = classnames('search__wrapper', {
|
|
86
|
+
'search__wrapper--toggle-display': displaySearchBar,
|
|
87
|
+
'search__wrapper--toggle': !displaySearchBar
|
|
88
|
+
});
|
|
89
|
+
const triggerClassname = classnames('search__icon', {
|
|
90
|
+
open: displaySearchBar
|
|
91
|
+
});
|
|
92
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
93
|
+
className: `search-wrapper ${className}`
|
|
94
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: "search search--header search--toggle"
|
|
96
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
97
|
+
className: searchWrapperClassname
|
|
98
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
99
|
+
"data-testid": "search-input",
|
|
100
|
+
onKeyPress: handleKeyPress,
|
|
101
|
+
placeholder: placeholder,
|
|
102
|
+
type: "text",
|
|
103
|
+
onChange: handleOnChange,
|
|
104
|
+
value: searchTerm,
|
|
105
|
+
ref: inputRef
|
|
106
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
107
|
+
type: "button",
|
|
108
|
+
className: "icon-button icon-button--search icon-button--toggle"
|
|
109
|
+
}, /*#__PURE__*/React.createElement(SearchIcon, null))), /*#__PURE__*/React.createElement("div", {
|
|
110
|
+
role: "button",
|
|
111
|
+
className: triggerClassname,
|
|
112
|
+
onClick: handleSearchBar,
|
|
113
|
+
id: SEARCH_BUTTON,
|
|
114
|
+
title: SEARCH_BUTTON
|
|
115
|
+
}, !displaySearchBar ? /*#__PURE__*/React.createElement(SearchIcon, null) : /*#__PURE__*/React.createElement(CloseIcon, null))), /*#__PURE__*/React.createElement("div", {
|
|
116
|
+
className: "search-modal"
|
|
117
|
+
}, children({
|
|
118
|
+
results: results.length && searchTerm ? results : [],
|
|
119
|
+
loading
|
|
120
|
+
})));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
SearchPublishedContent.propTypes = {
|
|
124
|
+
entities: PropTypes.array,
|
|
125
|
+
children: PropTypes.func.isRequired,
|
|
126
|
+
resultKeys: PropTypes.string,
|
|
127
|
+
getIsOpenSearchBar: PropTypes.func,
|
|
128
|
+
SearchIcon: PropTypes.func,
|
|
129
|
+
CloseIcon: PropTypes.func,
|
|
130
|
+
onChange: PropTypes.func,
|
|
131
|
+
onEnterPress: PropTypes.func,
|
|
132
|
+
className: PropTypes.string,
|
|
133
|
+
placeholder: PropTypes.string,
|
|
134
|
+
inputRef: PropTypes.object,
|
|
135
|
+
isSearchBarOpen: PropTypes.bool,
|
|
136
|
+
fields: PropTypes.array
|
|
137
|
+
};
|
|
138
|
+
SearchPublishedContent.defaultProps = {
|
|
139
|
+
entities: ['published_page'],
|
|
140
|
+
placeholder: '',
|
|
141
|
+
resultKeys: DEFAULT_RESULTS_KEYS,
|
|
142
|
+
onChange: () => {},
|
|
143
|
+
onEnterPress: () => {},
|
|
144
|
+
getIsOpenSearchBar: state => state,
|
|
145
|
+
SearchIcon: () => /*#__PURE__*/React.createElement("i", {
|
|
146
|
+
className: "material-icons"
|
|
147
|
+
}, "search"),
|
|
148
|
+
CloseIcon: () => /*#__PURE__*/React.createElement("i", {
|
|
149
|
+
className: "material-icons"
|
|
150
|
+
}, "close"),
|
|
151
|
+
className: '',
|
|
152
|
+
inputRef: null,
|
|
153
|
+
isSearchBarOpen: null,
|
|
154
|
+
fields: []
|
|
155
|
+
};
|
|
156
|
+
export default SearchPublishedContent;
|
|
157
|
+
//# sourceMappingURL=SearchPublishedContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SearchPublishedContent/SearchPublishedContent.js"],"names":["React","useState","useEffect","classnames","PropTypes","useDebounce","useSearchResults","SEARCH_PUBLISHED","DEFAULT_RESULTS_KEYS","SEARCH_BUTTON","SearchPublishedContent","entities","children","resultKeys","getIsOpenSearchBar","SearchIcon","CloseIcon","className","onChange","placeholder","onEnterPress","inputRef","isSearchBarOpen","fields","displaySearchBar","setDisplaySearchBar","searchTerm","setSearchTerm","previousSearchTerm","setPreviousSearchTerm","debouncedSearchTerm","loading","results","setQueryParams","queryKey","current","focus","value","handleOnChange","target","handleKeyPress","event","onEnter","key","handleSearchBar","voidSearchTerm","searchWrapperClassname","triggerClassname","open","length","propTypes","array","func","isRequired","string","object","bool","defaultProps","state"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,OAAOC,UAAP,MAAuB,YAAvB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,WAAT,QAA4B,oCAA5B;AACA,O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AAkB,EAAEV,SAAS,CAACgD,IAJG;AAKjCrC,EAAAA,UAAU,EAAEX,SAAS,CAACgD,IALW;AAMjCpC,EAAAA,SAAS,EAAEZ,SAAS,CAACgD,IANY;AAOjClC,EAAAA,QAAQ,EAAEd,SAAS,CAACgD,IAPa;AAQjChC,EAAAA,YAAY,EAAEhB,SAAS,CAACgD,IARS;AASjCnC,EAAAA,SAAS,EAAEb,SAAS,CAACkD,MATY;AAUjCnC,EAAAA,WAAW,EAAEf,SAAS,CAACkD,MAVU;AAWjCjC,EAAAA,QAAQ,EAAEjB,SAAS,CAACmD,MAXa;AAYjCjC,EAAAA,eAAe,EAAElB,SAAS,CAACoD,IAZM;AAajCjC,EAAAA,MAAM,EAAEnB,SAAS,CAAC+C;AAbe,CAAnC;AAgBAzC,sBAAsB,CAAC+C,YAAvB,GAAsC;AACpC9C,EAAAA,QAAQ,EAAE,CAAC,gBAAD,CAD0B;AAEpCQ,EAAAA,WAAW,EAAE,EAFuB;AAGpCN,EAAAA,UAAU,EAAEL,oBAHwB;AAIpCU,EAAAA,QAAQ,EAAE,MAAM,CAAE,CAJkB;AAKpCE,EAAAA,YAAY,EAAE,MAAM,CAAE,CALc;AAMpCN,EAAAA,kBAAkB,EAAE4C,KAAK,IAAIA,KANO;AAOpC3C,EAAAA,UAAU,EAAE,mBAAM;AAAG,IAAA,SAAS,EAAC;AAAb,cAPkB;AAQpCC,EAAAA,SAAS,EAAE,mBAAM;AAAG,IAAA,SAAS,EAAC;AAAb,aARmB;AASpCC,EAAAA,SAAS,EAAE,EATyB;AAUpCI,EAAAA,QAAQ,EAAE,IAV0B;AAWpCC,EAAAA,eAAe,EAAE,IAXmB;AAYpCC,EAAAA,MAAM,EAAE;AAZ4B,CAAtC;AAeA,eAAeb,sBAAf","sourcesContent":["import React, { useState, useEffect } from 'react';\nimport classnames from 'classnames';\nimport PropTypes from 'prop-types';\nimport { useDebounce } from '@blaze-react/utils/lib/customHooks';\nimport useSearchResults from '../useSearchResults';\nimport { SEARCH_PUBLISHED, DEFAULT_RESULTS_KEYS, SEARCH_BUTTON } from '../../constants';\n\nconst SearchPublishedContent = ({\n entities,\n children,\n resultKeys,\n getIsOpenSearchBar,\n SearchIcon,\n CloseIcon,\n className,\n onChange,\n placeholder,\n onEnterPress,\n inputRef,\n isSearchBarOpen,\n fields\n}) => {\n const [displaySearchBar, setDisplaySearchBar] = useState(isSearchBarOpen);\n const [searchTerm, setSearchTerm] = useState('');\n const [previousSearchTerm, setPreviousSearchTerm] = useState(null);\n const debouncedSearchTerm = useDebounce(searchTerm, 500);\n const [{ loading, results }, setQueryParams] = useSearchResults({\n queryKey: SEARCH_PUBLISHED,\n resultKeys,\n entities,\n fields\n });\n\n useEffect(\n () => {\n if (isSearchBarOpen !== displaySearchBar) {\n setDisplaySearchBar(isSearchBarOpen);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isSearchBarOpen]\n );\n\n useEffect(\n () => {\n if (inputRef && inputRef.current && displaySearchBar) {\n inputRef.current.focus();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [displaySearchBar]\n );\n\n useEffect(\n () => {\n if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {\n setQueryParams({ value: debouncedSearchTerm });\n setPreviousSearchTerm(debouncedSearchTerm);\n }\n },\n [debouncedSearchTerm, previousSearchTerm, setQueryParams]\n );\n\n const handleOnChange = ({ target: { value = '' } = {} }) => {\n onChange(value);\n setSearchTerm(value);\n };\n\n const handleKeyPress = event => {\n const onEnter = event.key === 'Enter';\n onEnter && onEnterPress();\n };\n\n const handleSearchBar = () => {\n const voidSearchTerm = '';\n displaySearchBar && setSearchTerm(voidSearchTerm);\n handleOnChange({ value: voidSearchTerm });\n if (isSearchBarOpen !== null) {\n getIsOpenSearchBar(!displaySearchBar);\n }\n setDisplaySearchBar(!displaySearchBar);\n };\n\n const searchWrapperClassname = classnames('search__wrapper', {\n 'search__wrapper--toggle-display': displaySearchBar,\n 'search__wrapper--toggle': !displaySearchBar\n });\n\n const triggerClassname = classnames('search__icon', {\n open: displaySearchBar\n });\n\n return (\n <div className={`search-wrapper ${className}`}>\n <div className=\"search search--header search--toggle\">\n <div className={searchWrapperClassname}>\n <input\n data-testid=\"search-input\"\n onKeyPress={handleKeyPress}\n placeholder={placeholder}\n type=\"text\"\n onChange={handleOnChange}\n value={searchTerm}\n ref={inputRef}\n />\n <button type=\"button\" className=\"icon-button icon-button--search icon-button--toggle\">\n <SearchIcon />\n </button>\n </div>\n <div\n role=\"button\"\n className={triggerClassname}\n onClick={handleSearchBar}\n id={SEARCH_BUTTON}\n title={SEARCH_BUTTON}>\n {!displaySearchBar ? <SearchIcon /> : <CloseIcon />}\n </div>\n </div>\n <div className=\"search-modal\">\n {children({ results: results.length && searchTerm ? results : [], loading })}\n </div>\n </div>\n );\n};\n\nSearchPublishedContent.propTypes = {\n entities: PropTypes.array,\n children: PropTypes.func.isRequired,\n resultKeys: PropTypes.string,\n getIsOpenSearchBar: PropTypes.func,\n SearchIcon: PropTypes.func,\n CloseIcon: PropTypes.func,\n onChange: PropTypes.func,\n onEnterPress: PropTypes.func,\n className: PropTypes.string,\n placeholder: PropTypes.string,\n inputRef: PropTypes.object,\n isSearchBarOpen: PropTypes.bool,\n fields: PropTypes.array\n};\n\nSearchPublishedContent.defaultProps = {\n entities: ['published_page'],\n placeholder: '',\n resultKeys: DEFAULT_RESULTS_KEYS,\n onChange: () => {},\n onEnterPress: () => {},\n getIsOpenSearchBar: state => state,\n SearchIcon: () => <i className=\"material-icons\">search</i>,\n CloseIcon: () => <i className=\"material-icons\">close</i>,\n className: '',\n inputRef: null,\n isSearchBarOpen: null,\n fields: []\n};\n\nexport default SearchPublishedContent;\n"],"file":"SearchPublishedContent.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SearchPublishedContent/index.js"],"names":["SearchPublishedContent"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,0BAAnC;AAEA,eAAeA,sBAAf","sourcesContent":["import SearchPublishedContent from './SearchPublishedContent';\n\nexport default SearchPublishedContent;\n"],"file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/useLocalStorage/index.js"],"names":["useLocalStorage"],"mappings":"AAAA,OAAOA,eAAP,MAA4B,mBAA5B;AAEA,eAAeA,eAAf","sourcesContent":["import useLocalStorage from './useLocalStorage';\n\nexport default useLocalStorage;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
function useLocalStorage(key, initialValue) {
|
|
4
|
+
const [storedValue, setStoredValue] = useState(() => {
|
|
5
|
+
const item = window.localStorage.getItem(key);
|
|
6
|
+
return item ? JSON.parse(item) : initialValue;
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const setValue = value => {
|
|
10
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
11
|
+
setStoredValue(valueToStore);
|
|
12
|
+
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return [storedValue, setValue];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default useLocalStorage;
|
|
19
|
+
//# sourceMappingURL=useLocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/useLocalStorage/useLocalStorage.js"],"names":["useState","useLocalStorage","key","initialValue","storedValue","setStoredValue","item","window","localStorage","getItem","JSON","parse","setValue","value","valueToStore","Function","setItem","stringify"],"mappings":"AAAA,SAASA,QAAT,QAAyB,OAAzB;;AAEA,SAASC,eAAT,CAAyBC,GAAzB,EAA8BC,YAA9B,EAA4C;AAC1C,QAAM,CAACC,WAAD,EAAcC,cAAd,IAAgCL,QAAQ,CAAC,MAAM;AACnD,UAAMM,IAAI,GAAGC,MAAM,CAACC,YAAP,CAAoBC,OAApB,CAA4BP,GAA5B,CAAb;AACA,WAAOI,IAAI,GAAGI,IAAI,CAACC,KAAL,CAAWL,IAAX,CAAH,GAAsBH,YAAjC;AACD,GAH6C,CAA9C;;AAKA,QAAMS,QAAQ,GAAGC,KAAK,IAAI;AACxB,UAAMC,YAAY,GAAGD,KAAK,YAAYE,QAAjB,GAA4BF,KAAK,CAACT,WAAD,CAAjC,GAAiDS,KAAtE;AACAR,IAAAA,cAAc,CAACS,YAAD,CAAd;AACAP,IAAAA,MAAM,CAACC,YAAP,CAAoBQ,OAApB,CAA4Bd,GAA5B,EAAiCQ,IAAI,CAACO,SAAL,CAAeH,YAAf,CAAjC;AACD,GAJD;;AAMA,SAAO,CAACV,WAAD,EAAcQ,QAAd,CAAP;AACD;;AAED,eAAeX,eAAf","sourcesContent":["import { useState } from 'react';\n\nfunction useLocalStorage(key, initialValue) {\n const [storedValue, setStoredValue] = useState(() => {\n const item = window.localStorage.getItem(key);\n return item ? JSON.parse(item) : initialValue;\n });\n\n const setValue = value => {\n const valueToStore = value instanceof Function ? value(storedValue) : value;\n setStoredValue(valueToStore);\n window.localStorage.setItem(key, JSON.stringify(valueToStore));\n };\n\n return [storedValue, setValue];\n}\n\nexport default useLocalStorage;\n"],"file":"useLocalStorage.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/useSearch/index.js"],"names":["useSearch"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,aAAtB;AAEA,eAAeA,SAAf","sourcesContent":["import useSearch from './useSearch';\n\nexport default useSearch;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
+
|
|
7
|
+
import { useState, useEffect } from 'react';
|
|
8
|
+
import { useLazyQuery } from 'react-apollo';
|
|
9
|
+
import searchQueries from '../../application/query';
|
|
10
|
+
|
|
11
|
+
function useSearch({
|
|
12
|
+
queryKey,
|
|
13
|
+
resultKeys,
|
|
14
|
+
entities = [],
|
|
15
|
+
fields
|
|
16
|
+
}) {
|
|
17
|
+
const [queryParams, setParams] = useState({
|
|
18
|
+
limit: 20,
|
|
19
|
+
offset: 0,
|
|
20
|
+
value: ''
|
|
21
|
+
});
|
|
22
|
+
const [searchedValue, setSearchedValue] = useState(null);
|
|
23
|
+
const [previousOffset, setPreviousOffset] = useState(null);
|
|
24
|
+
const buildSearchQuery = searchQueries[queryKey];
|
|
25
|
+
const [getSearchResults, {
|
|
26
|
+
loading,
|
|
27
|
+
data: {
|
|
28
|
+
search: {
|
|
29
|
+
results,
|
|
30
|
+
jsonResults,
|
|
31
|
+
total
|
|
32
|
+
}
|
|
33
|
+
} = {
|
|
34
|
+
search: {
|
|
35
|
+
results: [],
|
|
36
|
+
total: 0
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}] = useLazyQuery(buildSearchQuery({
|
|
40
|
+
resultKeys
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
const handleQueryParams = newQueryParams => {
|
|
44
|
+
setParams(_objectSpread(_objectSpread({}, queryParams), newQueryParams));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const {
|
|
49
|
+
limit,
|
|
50
|
+
offset,
|
|
51
|
+
value
|
|
52
|
+
} = queryParams;
|
|
53
|
+
const isNewValueSet = value && value !== searchedValue;
|
|
54
|
+
const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
|
|
55
|
+
const parsedEntities = entities.length ? entities.map(entity => ({
|
|
56
|
+
match: {
|
|
57
|
+
docType: entity
|
|
58
|
+
}
|
|
59
|
+
})) : [];
|
|
60
|
+
|
|
61
|
+
if (isNewValueSet || isNewOffsetSet) {
|
|
62
|
+
getSearchResults({
|
|
63
|
+
variables: {
|
|
64
|
+
limit,
|
|
65
|
+
offset,
|
|
66
|
+
rawQuery: {
|
|
67
|
+
query: {
|
|
68
|
+
bool: {
|
|
69
|
+
must: [{
|
|
70
|
+
query_string: {
|
|
71
|
+
query: value,
|
|
72
|
+
fields,
|
|
73
|
+
type: 'most_fields'
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
bool: {
|
|
77
|
+
should: parsedEntities
|
|
78
|
+
}
|
|
79
|
+
}]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
setSearchedValue(value);
|
|
86
|
+
setPreviousOffset(offset);
|
|
87
|
+
}
|
|
88
|
+
}, [queryParams, queryParams.limit, queryParams.value, queryParams.offset, searchedValue, previousOffset, getSearchResults, entities, fields]);
|
|
89
|
+
return [{
|
|
90
|
+
searchedValue: queryParams.value,
|
|
91
|
+
loading,
|
|
92
|
+
data: {
|
|
93
|
+
results: results || jsonResults,
|
|
94
|
+
total
|
|
95
|
+
}
|
|
96
|
+
}, handleQueryParams];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default useSearch;
|
|
100
|
+
//# sourceMappingURL=useSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/useSearch/useSearch.js"],"names":["useState","useEffect","useLazyQuery","searchQueries","useSearch","queryKey","resultKeys","entities","fields","queryParams","setParams","limit","offset","value","searchedValue","setSearchedValue","previousOffset","setPreviousOffset","buildSearchQuery","getSearchResults","loading","data","search","results","jsonResults","total","handleQueryParams","newQueryParams","isNewValueSet","isNewOffsetSet","parsedEntities","length","map","entity","match","docType","variables","rawQuery","query","bool","must","query_string","type","should"],"mappings":";;;;;;AAAA,SAASA,QAAT,EAAmBC,SAAnB,QAAoC,OAApC;AACA,SAASC,YAAT,QAA6B,cAA7B;AACA,OAAOC,aAAP,MAA0B,yBAA1B;;AAEA,SAASC,SAAT,CAAmB;AAAEC,EAAAA,QAAF;AAAYC,EAAAA,UAAZ;AAAwBC,EAAAA,QAAQ,GAAG,EAAnC;AAAuCC,EAAAA;AAAvC,CAAnB,EAAoE;AAClE,QAAM,CAACC,WAAD,EAAcC,SAAd,IAA2BV,QAAQ,CAAC;AAAEW,IAAAA,KAAK,EAAE,EAAT;AAAaC,IAAAA,MAAM,EAAE,CAArB;AAAwBC,IAAAA,KAAK,EAAE;AAA/B,GAAD,CAAzC;AACA,QAAM,CAACC,aAAD,EAAgBC,gBAAhB,IAAoCf,QAAQ,CAAC,IAAD,CAAlD;AACA,QAAM,CAACgB,cAAD,EAAiBC,iBAAjB,IAAsCjB,QAAQ,CAAC,IAAD,CAApD;AACA,QAAMkB,gBAAgB,GAAGf,aAAa,CAACE,QAAD,CAAtC;AACA,QAAM,CACJc,gBADI,EAEJ;AACEC,IAAAA,OADF;AAEEC,IAAAA,IAAI,EAAE;AAAEC,MAAAA,MAAM,EAAE;AAAEC,QAAAA,OAAF;AAAWC,QAAAA,WAAX;AAAwBC,QAAAA;AAAxB;AAAV,QAA8C;AAClDH,MAAAA,MAAM,EAAE;AAAEC,QAAAA,OAAO,EAAE,EAAX;AAAeE,QAAAA,KAAK,EAAE;AAAtB;AAD0C;AAFtD,GAFI,IAQFvB,YAAY,CAACgB,gBAAgB,CAAC;AAAEZ,IAAAA;AAAF,GAAD,CAAjB,CARhB;;AAUA,QAAMoB,iBAA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d,EAKEE,aALF,EAMEE,cANF,EAOEG,gBAPF,EAQEZ,QARF,EASEC,MATF,CA1CO,CAAT;AAuDA,SAAO,CACL;AAAEM,IAAAA,aAAa,EAAEL,WAAW,CAACI,KAA7B;AAAoCO,IAAAA,OAApC;AAA6CC,IAAAA,IAAI,EAAE;AAAEE,MAAAA,OAAO,EAAEA,OAAO,IAAIC,WAAtB;AAAmCC,MAAAA;AAAnC;AAAnD,GADK,EAELC,iBAFK,CAAP;AAID;;AAED,eAAetB,SAAf","sourcesContent":["import { useState, useEffect } from 'react';\nimport { useLazyQuery } from 'react-apollo';\nimport searchQueries from '../../application/query';\n\nfunction useSearch({ queryKey, resultKeys, entities = [], fields }) {\n const [queryParams, setParams] = useState({ limit: 20, offset: 0, value: '' });\n const [searchedValue, setSearchedValue] = useState(null);\n const [previousOffset, setPreviousOffset] = useState(null);\n const buildSearchQuery = searchQueries[queryKey];\n const [\n getSearchResults,\n {\n loading,\n data: { search: { results, jsonResults, total } } = {\n search: { results: [], total: 0 }\n }\n }\n ] = useLazyQuery(buildSearchQuery({ resultKeys }));\n\n const handleQueryParams = newQueryParams => {\n setParams({ ...queryParams, ...newQueryParams });\n };\n\n useEffect(\n () => {\n const { limit, offset, value } = queryParams;\n const isNewValueSet = value && value !== searchedValue;\n const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;\n const parsedEntities = entities.length\n ? entities.map(entity => ({\n match: { docType: entity }\n }))\n : [];\n\n if (isNewValueSet || isNewOffsetSet) {\n getSearchResults({\n variables: {\n limit,\n offset,\n rawQuery: {\n query: {\n bool: {\n must: [\n {\n query_string: {\n query: value,\n fields,\n type: 'most_fields'\n }\n },\n {\n bool: {\n should: parsedEntities\n }\n }\n ]\n }\n }\n }\n }\n });\n setSearchedValue(value);\n setPreviousOffset(offset);\n }\n },\n [\n queryParams,\n queryParams.limit,\n queryParams.value,\n queryParams.offset,\n searchedValue,\n previousOffset,\n getSearchResults,\n entities,\n fields\n ]\n );\n\n return [\n { searchedValue: queryParams.value, loading, data: { results: results || jsonResults, total } },\n handleQueryParams\n ];\n}\n\nexport default useSearch;\n"],"file":"useSearch.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/useSearchResults/index.js"],"names":["useSearchResults"],"mappings":"AAAA,OAAOA,gBAAP,MAA6B,oBAA7B;AAEA,eAAeA,gBAAf","sourcesContent":["import useSearchResults from './useSearchResults';\n\nexport default useSearchResults;\n"],"file":"index.js"}
|