@collectionspace/cspace-public-browser 1.5.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.
Files changed (233) hide show
  1. package/LICENSE.md +71 -0
  2. package/README.md +38 -0
  3. package/dist/cspacePublicBrowser.js +4680 -0
  4. package/dist/cspacePublicBrowser.min.js +2 -0
  5. package/dist/cspacePublicBrowser.min.js.LICENSE.txt +56 -0
  6. package/images/check.svg +3 -0
  7. package/images/close.svg +3 -0
  8. package/images/collapse.svg +3 -0
  9. package/images/collapseActive.svg +3 -0
  10. package/images/expand.svg +3 -0
  11. package/images/expandActive.svg +3 -0
  12. package/images/filter.svg +4 -0
  13. package/images/hideLeft.svg +4 -0
  14. package/images/linkBack.svg +4 -0
  15. package/images/linkDown.svg +4 -0
  16. package/images/linkNext.svg +4 -0
  17. package/images/linkPrev.svg +4 -0
  18. package/images/openNew.svg +4 -0
  19. package/images/search.svg +4 -0
  20. package/images/select.svg +4 -0
  21. package/images/top.svg +1 -0
  22. package/lib/actions/detailActions.js +177 -0
  23. package/lib/actions/filterActions.js +16 -0
  24. package/lib/actions/mediaActions.js +63 -0
  25. package/lib/actions/prefsActions.js +84 -0
  26. package/lib/actions/searchActions.js +140 -0
  27. package/lib/actions/searchEntryFormActions.js +19 -0
  28. package/lib/components/App.js +24 -0
  29. package/lib/components/detail/DetailNavBar.js +98 -0
  30. package/lib/components/detail/DetailPanel.js +171 -0
  31. package/lib/components/detail/DetailPanelContainer.js +22 -0
  32. package/lib/components/detail/ExhibitionSection.js +54 -0
  33. package/lib/components/detail/FieldList.js +95 -0
  34. package/lib/components/detail/FieldValueList.js +30 -0
  35. package/lib/components/detail/ImageGallery.js +137 -0
  36. package/lib/components/detail/ImageGalleryContainer.js +19 -0
  37. package/lib/components/detail/InstitutionHoldingList.js +155 -0
  38. package/lib/components/detail/InstitutionHoldingListContainer.js +22 -0
  39. package/lib/components/detail/InstitutionIndex.js +53 -0
  40. package/lib/components/detail/InstitutionIndexContainer.js +15 -0
  41. package/lib/components/detail/InstitutionSection.js +44 -0
  42. package/lib/components/detail/InstitutionSectionContainer.js +15 -0
  43. package/lib/components/layout/Fixed.js +26 -0
  44. package/lib/components/layout/IconButton.js +41 -0
  45. package/lib/components/layout/Panel.js +56 -0
  46. package/lib/components/layout/PanelContainer.js +19 -0
  47. package/lib/components/layout/PanelTitle.js +38 -0
  48. package/lib/components/layout/ScrollTopButton.js +70 -0
  49. package/lib/components/layout/ToggleFilterPanelButton.js +42 -0
  50. package/lib/components/pages/DetailPage.js +93 -0
  51. package/lib/components/pages/DetailPageContainer.js +20 -0
  52. package/lib/components/pages/RootPage.js +41 -0
  53. package/lib/components/pages/SearchPage.js +130 -0
  54. package/lib/components/pages/SearchPageContainer.js +23 -0
  55. package/lib/components/search/entry/SearchEntryForm.js +74 -0
  56. package/lib/components/search/entry/SearchEntryFormContainer.js +20 -0
  57. package/lib/components/search/entry/SearchEntryPanel.js +30 -0
  58. package/lib/components/search/entry/SearchQueryInput.js +89 -0
  59. package/lib/components/search/entry/SearchSubmitButton.js +22 -0
  60. package/lib/components/search/entry/SortSelect.js +89 -0
  61. package/lib/components/search/entry/SortSelectContainer.js +15 -0
  62. package/lib/components/search/result/ClearSearchParamsLink.js +42 -0
  63. package/lib/components/search/result/Filter.js +186 -0
  64. package/lib/components/search/result/FilterContainer.js +22 -0
  65. package/lib/components/search/result/FilterGroup.js +72 -0
  66. package/lib/components/search/result/FilterList.js +48 -0
  67. package/lib/components/search/result/FilterPanel.js +115 -0
  68. package/lib/components/search/result/FilterPanelContainer.js +16 -0
  69. package/lib/components/search/result/FilterSearchInput.js +63 -0
  70. package/lib/components/search/result/RemoveSearchParamLink.js +66 -0
  71. package/lib/components/search/result/SearchError.js +29 -0
  72. package/lib/components/search/result/SearchLoadMore.js +36 -0
  73. package/lib/components/search/result/SearchParamList.js +41 -0
  74. package/lib/components/search/result/SearchPending.js +21 -0
  75. package/lib/components/search/result/SearchResultImage.js +227 -0
  76. package/lib/components/search/result/SearchResultList.js +119 -0
  77. package/lib/components/search/result/SearchResultPanel.js +139 -0
  78. package/lib/components/search/result/SearchResultPanelContainer.js +23 -0
  79. package/lib/components/search/result/SearchResultStats.js +39 -0
  80. package/lib/components/search/result/SearchResultTile.js +61 -0
  81. package/lib/config/anthro.js +123 -0
  82. package/lib/config/bonsai.js +50 -0
  83. package/lib/config/botgarden.js +10 -0
  84. package/lib/config/default.js +530 -0
  85. package/lib/config/fcart.js +36 -0
  86. package/lib/config/herbarium.js +10 -0
  87. package/lib/config/index.js +53 -0
  88. package/lib/config/lhmc.js +10 -0
  89. package/lib/config/materials.js +982 -0
  90. package/lib/config/publicart.js +10 -0
  91. package/lib/constants/actionCodes.js +46 -0
  92. package/lib/constants/ids.js +12 -0
  93. package/lib/helpers/bodyClassName.js +11 -0
  94. package/lib/helpers/esQueryHelpers.js +206 -0
  95. package/lib/helpers/formatHelpers.js +293 -0
  96. package/lib/helpers/searchDimensions.js +28 -0
  97. package/lib/helpers/urlHelpers.js +43 -0
  98. package/lib/index.js +53 -0
  99. package/lib/intl/index.js +16 -0
  100. package/lib/reducers/detailReducer.js +145 -0
  101. package/lib/reducers/filterReducer.js +22 -0
  102. package/lib/reducers/index.js +66 -0
  103. package/lib/reducers/mediaReducer.js +43 -0
  104. package/lib/reducers/prefsReducer.js +27 -0
  105. package/lib/reducers/searchEntryFormReducer.js +24 -0
  106. package/lib/reducers/searchReducer.js +88 -0
  107. package/package.json +118 -0
  108. package/src/actions/detailActions.js +231 -0
  109. package/src/actions/filterActions.js +10 -0
  110. package/src/actions/mediaActions.js +65 -0
  111. package/src/actions/prefsActions.js +95 -0
  112. package/src/actions/searchActions.js +188 -0
  113. package/src/actions/searchEntryFormActions.js +15 -0
  114. package/src/components/App.jsx +18 -0
  115. package/src/components/detail/DetailNavBar.jsx +132 -0
  116. package/src/components/detail/DetailPanel.jsx +215 -0
  117. package/src/components/detail/DetailPanelContainer.js +29 -0
  118. package/src/components/detail/ExhibitionSection.jsx +71 -0
  119. package/src/components/detail/FieldList.jsx +122 -0
  120. package/src/components/detail/FieldValueList.jsx +31 -0
  121. package/src/components/detail/ImageGallery.jsx +153 -0
  122. package/src/components/detail/ImageGalleryContainer.js +17 -0
  123. package/src/components/detail/InstitutionHoldingList.jsx +188 -0
  124. package/src/components/detail/InstitutionHoldingListContainer.js +29 -0
  125. package/src/components/detail/InstitutionIndex.jsx +57 -0
  126. package/src/components/detail/InstitutionIndexContainer.js +11 -0
  127. package/src/components/detail/InstitutionSection.jsx +48 -0
  128. package/src/components/detail/InstitutionSectionContainer.js +11 -0
  129. package/src/components/layout/Fixed.jsx +29 -0
  130. package/src/components/layout/IconButton.jsx +41 -0
  131. package/src/components/layout/Panel.jsx +60 -0
  132. package/src/components/layout/PanelContainer.js +20 -0
  133. package/src/components/layout/PanelTitle.jsx +43 -0
  134. package/src/components/layout/ScrollTopButton.jsx +76 -0
  135. package/src/components/layout/ToggleFilterPanelButton.jsx +43 -0
  136. package/src/components/pages/DetailPage.jsx +101 -0
  137. package/src/components/pages/DetailPageContainer.js +18 -0
  138. package/src/components/pages/RootPage.jsx +37 -0
  139. package/src/components/pages/SearchPage.jsx +160 -0
  140. package/src/components/pages/SearchPageContainer.js +21 -0
  141. package/src/components/search/entry/SearchEntryForm.jsx +82 -0
  142. package/src/components/search/entry/SearchEntryFormContainer.js +22 -0
  143. package/src/components/search/entry/SearchEntryPanel.jsx +28 -0
  144. package/src/components/search/entry/SearchQueryInput.jsx +95 -0
  145. package/src/components/search/entry/SearchSubmitButton.jsx +22 -0
  146. package/src/components/search/entry/SortSelect.jsx +104 -0
  147. package/src/components/search/entry/SortSelectContainer.js +12 -0
  148. package/src/components/search/result/ClearSearchParamsLink.jsx +43 -0
  149. package/src/components/search/result/Filter.jsx +226 -0
  150. package/src/components/search/result/FilterContainer.js +20 -0
  151. package/src/components/search/result/FilterGroup.jsx +83 -0
  152. package/src/components/search/result/FilterList.jsx +51 -0
  153. package/src/components/search/result/FilterPanel.jsx +143 -0
  154. package/src/components/search/result/FilterPanelContainer.js +16 -0
  155. package/src/components/search/result/FilterSearchInput.jsx +68 -0
  156. package/src/components/search/result/RemoveSearchParamLink.jsx +79 -0
  157. package/src/components/search/result/SearchError.jsx +30 -0
  158. package/src/components/search/result/SearchLoadMore.jsx +37 -0
  159. package/src/components/search/result/SearchParamList.jsx +47 -0
  160. package/src/components/search/result/SearchPending.jsx +19 -0
  161. package/src/components/search/result/SearchResultImage.jsx +275 -0
  162. package/src/components/search/result/SearchResultList.jsx +144 -0
  163. package/src/components/search/result/SearchResultPanel.jsx +169 -0
  164. package/src/components/search/result/SearchResultPanelContainer.js +31 -0
  165. package/src/components/search/result/SearchResultStats.jsx +38 -0
  166. package/src/components/search/result/SearchResultTile.jsx +70 -0
  167. package/src/config/anthro.js +153 -0
  168. package/src/config/bonsai.js +50 -0
  169. package/src/config/botgarden.js +3 -0
  170. package/src/config/default.js +604 -0
  171. package/src/config/fcart.js +38 -0
  172. package/src/config/herbarium.js +3 -0
  173. package/src/config/index.js +51 -0
  174. package/src/config/lhmc.js +3 -0
  175. package/src/config/materials.js +1173 -0
  176. package/src/config/publicart.js +3 -0
  177. package/src/constants/actionCodes.js +26 -0
  178. package/src/constants/ids.js +3 -0
  179. package/src/helpers/bodyClassName.js +5 -0
  180. package/src/helpers/esQueryHelpers.js +224 -0
  181. package/src/helpers/formatHelpers.jsx +361 -0
  182. package/src/helpers/searchDimensions.js +21 -0
  183. package/src/helpers/urlHelpers.js +49 -0
  184. package/src/index.jsx +59 -0
  185. package/src/intl/index.js +16 -0
  186. package/src/reducers/detailReducer.js +201 -0
  187. package/src/reducers/filterReducer.js +16 -0
  188. package/src/reducers/index.js +56 -0
  189. package/src/reducers/mediaReducer.js +44 -0
  190. package/src/reducers/prefsReducer.js +24 -0
  191. package/src/reducers/searchEntryFormReducer.js +19 -0
  192. package/src/reducers/searchReducer.js +118 -0
  193. package/styles/colors.css +7 -0
  194. package/styles/cspace/DetailNavBar.css +17 -0
  195. package/styles/cspace/DetailPage.css +3 -0
  196. package/styles/cspace/DetailPanel.css +69 -0
  197. package/styles/cspace/ExhibitionSection.css +9 -0
  198. package/styles/cspace/FieldList.css +15 -0
  199. package/styles/cspace/FieldListField.css +7 -0
  200. package/styles/cspace/FieldListGroup.css +27 -0
  201. package/styles/cspace/FieldValueList.css +19 -0
  202. package/styles/cspace/Filter.css +64 -0
  203. package/styles/cspace/FilterGroup.css +21 -0
  204. package/styles/cspace/FilterPanel.css +45 -0
  205. package/styles/cspace/FilterSearchInput.css +13 -0
  206. package/styles/cspace/Fixed.css +8 -0
  207. package/styles/cspace/IconButton.css +11 -0
  208. package/styles/cspace/ImageGallery.css +43 -0
  209. package/styles/cspace/InstitutionHoldingList.css +109 -0
  210. package/styles/cspace/InstitutionIndex.css +13 -0
  211. package/styles/cspace/InstitutionSection.css +4 -0
  212. package/styles/cspace/Link.css +39 -0
  213. package/styles/cspace/Panel.css +53 -0
  214. package/styles/cspace/PanelTitle.css +48 -0
  215. package/styles/cspace/RemoveSearchParamLink.css +15 -0
  216. package/styles/cspace/RootPage.css +60 -0
  217. package/styles/cspace/ScrollTopButton.css +32 -0
  218. package/styles/cspace/SearchEntryForm.css +4 -0
  219. package/styles/cspace/SearchEntryPanel.css +11 -0
  220. package/styles/cspace/SearchPage.css +2 -0
  221. package/styles/cspace/SearchParamLink.css +21 -0
  222. package/styles/cspace/SearchParamList.css +6 -0
  223. package/styles/cspace/SearchQueryInput.css +30 -0
  224. package/styles/cspace/SearchResultImage.css +29 -0
  225. package/styles/cspace/SearchResultList.css +10 -0
  226. package/styles/cspace/SearchResultPanel.css +31 -0
  227. package/styles/cspace/SearchResultStats.css +4 -0
  228. package/styles/cspace/SearchResultTile.css +67 -0
  229. package/styles/cspace/SearchStatus.css +12 -0
  230. package/styles/cspace/SearchSubmitButton.css +3 -0
  231. package/styles/cspace/SortSelect.css +19 -0
  232. package/styles/cspace/ToggleFilterPanelButton.css +44 -0
  233. package/styles/dimensions.css +9 -0
@@ -0,0 +1,275 @@
1
+ /* global fetch, window, AbortController */
2
+
3
+ import React, { Component } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { defineMessages, FormattedMessage } from 'react-intl';
6
+ import { getItemShortID } from 'cspace-refname';
7
+ import Immutable from 'immutable';
8
+ import { blobUrl } from '../../../helpers/urlHelpers';
9
+ import config from '../../../config';
10
+ import styles from '../../../../styles/cspace/SearchResultImage.css';
11
+
12
+ const propTypes = {
13
+ gatewayUrl: PropTypes.string.isRequired,
14
+ holdingInstitutions: PropTypes.instanceOf(Immutable.List),
15
+ loadImageImmediately: PropTypes.bool,
16
+ mediaCsid: PropTypes.string,
17
+ referenceValue: PropTypes.string.isRequired,
18
+ };
19
+
20
+ const defaultProps = {
21
+ holdingInstitutions: Immutable.List(),
22
+ loadImageImmediately: false,
23
+ mediaCsid: undefined,
24
+ };
25
+
26
+ const messages = defineMessages({
27
+ noimage: {
28
+ id: 'searchResultImage.noimage',
29
+ defaultMessage: 'no image available',
30
+ },
31
+ });
32
+
33
+ export default class SearchResultImage extends Component {
34
+ constructor(props) {
35
+ super();
36
+
37
+ this.handleScroll = this.handleScroll.bind(this);
38
+
39
+ this.ref = React.createRef();
40
+
41
+ this.state = {
42
+ gatewayUrl: props.gatewayUrl,
43
+ };
44
+
45
+ if (AbortController) {
46
+ this.abortController = new AbortController();
47
+ }
48
+ }
49
+
50
+ componentDidMount() {
51
+ const {
52
+ holdingInstitutions,
53
+ loadImageImmediately,
54
+ mediaCsid,
55
+ referenceValue,
56
+ } = this.props;
57
+
58
+ window.setTimeout(() => {
59
+ if (this.isInView()) {
60
+ this.init(referenceValue, mediaCsid, holdingInstitutions);
61
+ } else {
62
+ window.addEventListener('scroll', this.handleScroll);
63
+ }
64
+ }, loadImageImmediately ? 0 : config.get('imageLoadDelay'));
65
+ }
66
+
67
+ componentDidUpdate(prevProps) {
68
+ const {
69
+ gatewayUrl: prevGatewayUrl,
70
+ mediaCsid: prevMediaCsid,
71
+ referenceValue: prevReferenceValue,
72
+ } = prevProps;
73
+
74
+ const {
75
+ holdingInstitutions,
76
+ gatewayUrl,
77
+ mediaCsid,
78
+ referenceValue,
79
+ } = this.props;
80
+
81
+ if (
82
+ mediaCsid !== prevMediaCsid
83
+ || gatewayUrl !== prevGatewayUrl
84
+ || referenceValue !== prevReferenceValue
85
+ ) {
86
+ // FIXME: Make this component stateless.
87
+ // eslint-disable-next-line react/no-did-update-set-state
88
+ this.setState({
89
+ gatewayUrl,
90
+ });
91
+
92
+ this.init(referenceValue, mediaCsid, holdingInstitutions);
93
+ }
94
+ }
95
+
96
+ componentWillUnmount() {
97
+ if (this.abortController) {
98
+ this.abortController.abort();
99
+ }
100
+
101
+ window.removeEventListener('scroll', this.handleScroll);
102
+ }
103
+
104
+ handleScroll() {
105
+ if (this.isInView()) {
106
+ window.setTimeout(() => {
107
+ if (this.isInView()) {
108
+ const {
109
+ holdingInstitutions,
110
+ mediaCsid,
111
+ referenceValue,
112
+ } = this.props;
113
+
114
+ window.removeEventListener('scroll', this.handleScroll);
115
+
116
+ this.init(referenceValue, mediaCsid, holdingInstitutions);
117
+ }
118
+ }, config.get('imageLoadDelay'));
119
+ }
120
+ }
121
+
122
+ getMediaCsid(gatewayUrl, indexName, referenceValue) {
123
+ const url = `${gatewayUrl}/es/doc/_search`;
124
+ const referenceField = config.get('referenceField');
125
+
126
+ const query = {
127
+ _source: 'collectionspace_denorm:mediaCsid',
128
+ query: {
129
+ term: {
130
+ [referenceField]: referenceValue,
131
+ },
132
+ },
133
+ size: 1,
134
+ terminate_after: 1,
135
+ };
136
+
137
+ return fetch(url, {
138
+ method: 'POST',
139
+ headers: { 'Content-Type': 'application/json' },
140
+ body: JSON.stringify(query),
141
+ signal: this.abortController ? this.abortController.signal : undefined,
142
+ })
143
+ .then((response) => response.json())
144
+ // eslint-disable-next-line no-underscore-dangle
145
+ .then((data) => data.hits.hits[0]._source['collectionspace_denorm:mediaCsid'][0])
146
+ .catch(() => undefined);
147
+ }
148
+
149
+ init(referenceValue, mediaCsid, holdingInstitutions) {
150
+ if (typeof mediaCsid !== 'undefined') {
151
+ this.setState({
152
+ mediaCsid,
153
+ });
154
+
155
+ return;
156
+ }
157
+
158
+ // Attempt to resove a mediaCsid from holding instutitions. This is really only used by the
159
+ // materials browser. In other profiles, the media csid will have been received in the search
160
+ // result.
161
+
162
+ const cachedGatewayMediaCsid = window.sessionStorage.getItem(`image-${referenceValue}`);
163
+
164
+ if (cachedGatewayMediaCsid) {
165
+ const [cachedGatewayUrl, cachedMediaCsid] = cachedGatewayMediaCsid.split(',');
166
+
167
+ this.setState({
168
+ gatewayUrl: cachedGatewayUrl,
169
+ mediaCsid: cachedMediaCsid,
170
+ });
171
+
172
+ return;
173
+ }
174
+
175
+ const institutions = holdingInstitutions.filter((value) => !!value);
176
+
177
+ if (institutions.size === 0) {
178
+ this.setState({
179
+ mediaCsid: null,
180
+ });
181
+
182
+ return;
183
+ }
184
+
185
+ const findImage = institutions.reduce((promise, institution) => promise.catch(() => {
186
+ const instShortId = getItemShortID(institution);
187
+ const instGatewayUrl = config.get(['institutions', instShortId, 'gatewayUrl']);
188
+ const instIndexName = config.get(['institutions', instShortId, 'esIndexName']);
189
+
190
+ if (!instGatewayUrl) {
191
+ return Promise.reject();
192
+ }
193
+
194
+ return (
195
+ this.getMediaCsid(instGatewayUrl, instIndexName, referenceValue)
196
+ .then((instMediaCsid) => {
197
+ if (!instMediaCsid) {
198
+ return Promise.reject();
199
+ }
200
+
201
+ return Promise.resolve({ instGatewayUrl, instMediaCsid });
202
+ })
203
+ );
204
+ }), Promise.reject());
205
+
206
+ findImage
207
+ .then(({ instGatewayUrl, instMediaCsid }) => {
208
+ try {
209
+ window.sessionStorage.setItem(
210
+ `image-${referenceValue}`,
211
+ `${instGatewayUrl},${instMediaCsid}`,
212
+ );
213
+ } catch (err) {
214
+ // Ignore storage error.
215
+ }
216
+
217
+ this.setState({
218
+ gatewayUrl: instGatewayUrl,
219
+ mediaCsid: instMediaCsid,
220
+ });
221
+ })
222
+ .catch(() => {});
223
+ }
224
+
225
+ isInView() {
226
+ const domNode = this.ref.current;
227
+
228
+ if (domNode) {
229
+ const rect = domNode.getBoundingClientRect();
230
+
231
+ return (
232
+ rect.top >= 0
233
+ && rect.top < window.innerHeight
234
+ );
235
+ }
236
+
237
+ return false;
238
+ }
239
+
240
+ render() {
241
+ const {
242
+ gatewayUrl,
243
+ mediaCsid,
244
+ } = this.state;
245
+
246
+ if (mediaCsid === null) {
247
+ return (
248
+ <div
249
+ aria-hidden
250
+ className={styles.noimage}
251
+ >
252
+ {/* eslint-disable-next-line react/jsx-props-no-spreading */}
253
+ <FormattedMessage {...messages.noimage} />
254
+ </div>
255
+ );
256
+ }
257
+
258
+ const imageUrl = mediaCsid && blobUrl(gatewayUrl, mediaCsid, config.get('searchResultImageDerivative'));
259
+
260
+ let style;
261
+
262
+ if (imageUrl) {
263
+ style = {
264
+ backgroundImage: `url(${imageUrl})`,
265
+ };
266
+ }
267
+
268
+ return (
269
+ <div className={styles.common} style={style} ref={this.ref} />
270
+ );
271
+ }
272
+ }
273
+
274
+ SearchResultImage.propTypes = propTypes;
275
+ SearchResultImage.defaultProps = defaultProps;
@@ -0,0 +1,144 @@
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Immutable from 'immutable';
4
+ import { defineMessages, FormattedMessage } from 'react-intl';
5
+ import SearchError from './SearchError';
6
+ import SearchLoadMore from './SearchLoadMore';
7
+ import SearchPending from './SearchPending';
8
+ import SearchResultTile from './SearchResultTile';
9
+ import config from '../../../config';
10
+ import { calculateSearchPageSize } from '../../../helpers/searchDimensions';
11
+ import styles from '../../../../styles/cspace/SearchResultList.css';
12
+
13
+ const propTypes = {
14
+ error: PropTypes.instanceOf(Error),
15
+ hits: PropTypes.instanceOf(Immutable.List),
16
+ isPending: PropTypes.bool,
17
+ onHitsUpdated: PropTypes.func,
18
+ onLoadMoreClick: PropTypes.func,
19
+ params: PropTypes.instanceOf(Immutable.Map).isRequired,
20
+ showLoadMore: PropTypes.bool,
21
+ };
22
+
23
+ const defaultProps = {
24
+ error: undefined,
25
+ hits: Immutable.List(),
26
+ isPending: false,
27
+ onHitsUpdated: () => undefined,
28
+ onLoadMoreClick: () => undefined,
29
+ showLoadMore: false,
30
+ };
31
+
32
+ const messages = defineMessages({
33
+ noResult: {
34
+ id: 'searchResultList.noResult',
35
+ defaultMessage: 'No results found',
36
+ },
37
+ });
38
+
39
+ export default class SearchResultList extends Component {
40
+ componentDidUpdate(prevProps) {
41
+ const {
42
+ hits,
43
+ onHitsUpdated,
44
+ } = this.props;
45
+
46
+ const {
47
+ hits: prevHits,
48
+ } = prevProps;
49
+
50
+ if (hits !== prevHits) {
51
+ onHitsUpdated();
52
+ }
53
+ }
54
+
55
+ renderError() {
56
+ const {
57
+ error,
58
+ } = this.props;
59
+
60
+ if (!error) {
61
+ return undefined;
62
+ }
63
+
64
+ return (
65
+ <SearchError error={error} />
66
+ );
67
+ }
68
+
69
+ renderLoadMore() {
70
+ const {
71
+ isPending,
72
+ onLoadMoreClick,
73
+ showLoadMore,
74
+ } = this.props;
75
+
76
+ if (!showLoadMore || isPending) {
77
+ return undefined;
78
+ }
79
+
80
+ return (
81
+ <SearchLoadMore onClick={onLoadMoreClick} />
82
+ );
83
+ }
84
+
85
+ renderPending() {
86
+ const {
87
+ isPending,
88
+ } = this.props;
89
+
90
+ if (!isPending) {
91
+ return undefined;
92
+ }
93
+
94
+ return (
95
+ <SearchPending />
96
+ );
97
+ }
98
+
99
+ renderHits() {
100
+ const {
101
+ error,
102
+ params,
103
+ hits,
104
+ isPending,
105
+ } = this.props;
106
+
107
+ if (hits.size === 0 && !isPending && !error) {
108
+ return (
109
+ <p>
110
+ {/* eslint-disable-next-line react/jsx-props-no-spreading */}
111
+ <FormattedMessage {...messages.noResult} />
112
+ </p>
113
+ );
114
+ }
115
+
116
+ const gatewayUrl = config.get('gatewayUrl');
117
+ const pageSize = calculateSearchPageSize();
118
+
119
+ return hits.map((result, index) => (
120
+ <SearchResultTile
121
+ gatewayUrl={gatewayUrl}
122
+ loadImageImmediately={index < pageSize}
123
+ index={index}
124
+ key={result.getIn(['_source', 'ecm:name'])}
125
+ params={params}
126
+ result={result}
127
+ />
128
+ ));
129
+ }
130
+
131
+ render() {
132
+ return (
133
+ <div className={styles.common}>
134
+ {this.renderHits()}
135
+ {this.renderLoadMore()}
136
+ {this.renderPending()}
137
+ {this.renderError()}
138
+ </div>
139
+ );
140
+ }
141
+ }
142
+
143
+ SearchResultList.propTypes = propTypes;
144
+ SearchResultList.defaultProps = defaultProps;
@@ -0,0 +1,169 @@
1
+ /* global window */
2
+
3
+ import React, { Component } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import Immutable from 'immutable';
6
+ import SearchParamList from './SearchParamList';
7
+ import SearchResultList from './SearchResultList';
8
+ import SearchResultStats from './SearchResultStats';
9
+ import SortSelect from '../entry/SortSelectContainer';
10
+ import config from '../../../config';
11
+ import { SORT_ID } from '../../../constants/ids';
12
+ import { calculateSearchPageSize, tileHeight } from '../../../helpers/searchDimensions';
13
+ import styles from '../../../../styles/cspace/SearchResultPanel.css';
14
+
15
+ const propTypes = {
16
+ error: PropTypes.instanceOf(Error),
17
+ isPending: PropTypes.bool,
18
+ nextOffset: PropTypes.number,
19
+ onHitsUpdated: PropTypes.func,
20
+ result: PropTypes.instanceOf(Immutable.Map),
21
+ params: PropTypes.instanceOf(Immutable.Map),
22
+ search: PropTypes.func,
23
+ setSearchPageSize: PropTypes.func,
24
+ };
25
+
26
+ const defaultProps = {
27
+ error: undefined,
28
+ isPending: false,
29
+ nextOffset: undefined,
30
+ onHitsUpdated: undefined,
31
+ params: Immutable.Map(),
32
+ result: undefined,
33
+ search: () => undefined,
34
+ setSearchPageSize: () => undefined,
35
+ };
36
+
37
+ export default class SearchResultPanel extends Component {
38
+ constructor() {
39
+ super();
40
+
41
+ this.handleLoadMoreClick = this.handleLoadMoreClick.bind(this);
42
+ this.handleScroll = this.handleScroll.bind(this);
43
+
44
+ this.ref = React.createRef();
45
+ }
46
+
47
+ componentDidMount() {
48
+ const {
49
+ setSearchPageSize,
50
+ } = this.props;
51
+
52
+ window.addEventListener('scroll', this.handleScroll, false);
53
+
54
+ setSearchPageSize(calculateSearchPageSize());
55
+
56
+ this.search();
57
+ }
58
+
59
+ componentDidUpdate(prevProps) {
60
+ const {
61
+ params,
62
+ } = this.props;
63
+
64
+ const {
65
+ params: prevParams,
66
+ } = prevProps;
67
+
68
+ if (params !== prevParams) {
69
+ this.search();
70
+ }
71
+ }
72
+
73
+ componentWillUnmount() {
74
+ window.removeEventListener('scroll', this.handleScroll, false);
75
+ }
76
+
77
+ handleLoadMoreClick() {
78
+ this.search();
79
+ }
80
+
81
+ handleScroll() {
82
+ const {
83
+ nextOffset,
84
+ } = this.props;
85
+
86
+ if (nextOffset < config.get('pageAutoLoadLimit')) {
87
+ const {
88
+ search,
89
+ } = this.props;
90
+
91
+ const rect = this.ref.current.getBoundingClientRect();
92
+ const bottomOffset = rect.bottom - window.innerHeight;
93
+
94
+ if (bottomOffset <= tileHeight) {
95
+ search(config.get('pageLoadDelay'));
96
+ }
97
+ }
98
+ }
99
+
100
+ search(fetchDelay) {
101
+ const {
102
+ search,
103
+ } = this.props;
104
+
105
+ search(fetchDelay);
106
+ }
107
+
108
+ renderError() {
109
+ const {
110
+ error,
111
+ } = this.props;
112
+
113
+ return (
114
+ <div>{error.message}</div>
115
+ );
116
+ }
117
+
118
+ renderResult() {
119
+ const {
120
+ error,
121
+ isPending,
122
+ nextOffset,
123
+ onHitsUpdated,
124
+ params,
125
+ result,
126
+ } = this.props;
127
+
128
+ const hitCount = result && result.get('total');
129
+ const hits = result && result.get('hits');
130
+
131
+ const showLoadMore = result
132
+ && hits.size < hitCount
133
+ && nextOffset >= config.get('pageAutoLoadLimit');
134
+
135
+ return (
136
+ <>
137
+ <header>
138
+ <SearchParamList params={params} />
139
+
140
+ <div>
141
+ <SearchResultStats count={hitCount} />
142
+ <SortSelect value={params.get(SORT_ID)} />
143
+ </div>
144
+ </header>
145
+
146
+ <SearchResultList
147
+ error={error}
148
+ isPending={isPending}
149
+ onHitsUpdated={onHitsUpdated}
150
+ onLoadMoreClick={this.handleLoadMoreClick}
151
+ params={params}
152
+ hits={hits}
153
+ showLoadMore={showLoadMore}
154
+ />
155
+ </>
156
+ );
157
+ }
158
+
159
+ render() {
160
+ return (
161
+ <div className={styles.common} ref={this.ref}>
162
+ {this.renderResult()}
163
+ </div>
164
+ );
165
+ }
166
+ }
167
+
168
+ SearchResultPanel.propTypes = propTypes;
169
+ SearchResultPanel.defaultProps = defaultProps;
@@ -0,0 +1,31 @@
1
+ import { connect } from 'react-redux';
2
+ import SearchResultPanel from './SearchResultPanel';
3
+
4
+ import {
5
+ search,
6
+ setSearchPageSize,
7
+ } from '../../../actions/searchActions';
8
+
9
+ import {
10
+ getSearchError,
11
+ getSearchNextOffset,
12
+ getSearchResult,
13
+ isSearchPending,
14
+ } from '../../../reducers';
15
+
16
+ const mapStateToProps = (state) => ({
17
+ error: getSearchError(state),
18
+ isPending: isSearchPending(state),
19
+ nextOffset: getSearchNextOffset(state),
20
+ result: getSearchResult(state),
21
+ });
22
+
23
+ const mapDispatchToProps = {
24
+ search,
25
+ setSearchPageSize,
26
+ };
27
+
28
+ export default connect(
29
+ mapStateToProps,
30
+ mapDispatchToProps,
31
+ )(SearchResultPanel);
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { defineMessages, FormattedMessage } from 'react-intl';
4
+ import styles from '../../../../styles/cspace/SearchResultStats.css';
5
+
6
+ const propTypes = {
7
+ count: PropTypes.number,
8
+ };
9
+
10
+ const defaultProps = {
11
+ count: undefined,
12
+ };
13
+
14
+ const messages = defineMessages({
15
+ count: {
16
+ id: 'searchResultStats.count',
17
+ defaultMessage: `{count, plural,
18
+ one {# item}
19
+ other {# items}
20
+ } found`,
21
+ },
22
+ });
23
+
24
+ export default function SearchResultStats(props) {
25
+ const {
26
+ count,
27
+ } = props;
28
+
29
+ return (
30
+ <div className={styles.common} aria-live="polite">
31
+ {/* eslint-disable-next-line react/jsx-props-no-spreading */}
32
+ {count ? <FormattedMessage {...messages.count} values={{ count }} /> : undefined}
33
+ </div>
34
+ );
35
+ }
36
+
37
+ SearchResultStats.propTypes = propTypes;
38
+ SearchResultStats.defaultProps = defaultProps;