@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.
- package/LICENSE.md +71 -0
- package/README.md +38 -0
- package/dist/cspacePublicBrowser.js +4680 -0
- package/dist/cspacePublicBrowser.min.js +2 -0
- package/dist/cspacePublicBrowser.min.js.LICENSE.txt +56 -0
- package/images/check.svg +3 -0
- package/images/close.svg +3 -0
- package/images/collapse.svg +3 -0
- package/images/collapseActive.svg +3 -0
- package/images/expand.svg +3 -0
- package/images/expandActive.svg +3 -0
- package/images/filter.svg +4 -0
- package/images/hideLeft.svg +4 -0
- package/images/linkBack.svg +4 -0
- package/images/linkDown.svg +4 -0
- package/images/linkNext.svg +4 -0
- package/images/linkPrev.svg +4 -0
- package/images/openNew.svg +4 -0
- package/images/search.svg +4 -0
- package/images/select.svg +4 -0
- package/images/top.svg +1 -0
- package/lib/actions/detailActions.js +177 -0
- package/lib/actions/filterActions.js +16 -0
- package/lib/actions/mediaActions.js +63 -0
- package/lib/actions/prefsActions.js +84 -0
- package/lib/actions/searchActions.js +140 -0
- package/lib/actions/searchEntryFormActions.js +19 -0
- package/lib/components/App.js +24 -0
- package/lib/components/detail/DetailNavBar.js +98 -0
- package/lib/components/detail/DetailPanel.js +171 -0
- package/lib/components/detail/DetailPanelContainer.js +22 -0
- package/lib/components/detail/ExhibitionSection.js +54 -0
- package/lib/components/detail/FieldList.js +95 -0
- package/lib/components/detail/FieldValueList.js +30 -0
- package/lib/components/detail/ImageGallery.js +137 -0
- package/lib/components/detail/ImageGalleryContainer.js +19 -0
- package/lib/components/detail/InstitutionHoldingList.js +155 -0
- package/lib/components/detail/InstitutionHoldingListContainer.js +22 -0
- package/lib/components/detail/InstitutionIndex.js +53 -0
- package/lib/components/detail/InstitutionIndexContainer.js +15 -0
- package/lib/components/detail/InstitutionSection.js +44 -0
- package/lib/components/detail/InstitutionSectionContainer.js +15 -0
- package/lib/components/layout/Fixed.js +26 -0
- package/lib/components/layout/IconButton.js +41 -0
- package/lib/components/layout/Panel.js +56 -0
- package/lib/components/layout/PanelContainer.js +19 -0
- package/lib/components/layout/PanelTitle.js +38 -0
- package/lib/components/layout/ScrollTopButton.js +70 -0
- package/lib/components/layout/ToggleFilterPanelButton.js +42 -0
- package/lib/components/pages/DetailPage.js +93 -0
- package/lib/components/pages/DetailPageContainer.js +20 -0
- package/lib/components/pages/RootPage.js +41 -0
- package/lib/components/pages/SearchPage.js +130 -0
- package/lib/components/pages/SearchPageContainer.js +23 -0
- package/lib/components/search/entry/SearchEntryForm.js +74 -0
- package/lib/components/search/entry/SearchEntryFormContainer.js +20 -0
- package/lib/components/search/entry/SearchEntryPanel.js +30 -0
- package/lib/components/search/entry/SearchQueryInput.js +89 -0
- package/lib/components/search/entry/SearchSubmitButton.js +22 -0
- package/lib/components/search/entry/SortSelect.js +89 -0
- package/lib/components/search/entry/SortSelectContainer.js +15 -0
- package/lib/components/search/result/ClearSearchParamsLink.js +42 -0
- package/lib/components/search/result/Filter.js +186 -0
- package/lib/components/search/result/FilterContainer.js +22 -0
- package/lib/components/search/result/FilterGroup.js +72 -0
- package/lib/components/search/result/FilterList.js +48 -0
- package/lib/components/search/result/FilterPanel.js +115 -0
- package/lib/components/search/result/FilterPanelContainer.js +16 -0
- package/lib/components/search/result/FilterSearchInput.js +63 -0
- package/lib/components/search/result/RemoveSearchParamLink.js +66 -0
- package/lib/components/search/result/SearchError.js +29 -0
- package/lib/components/search/result/SearchLoadMore.js +36 -0
- package/lib/components/search/result/SearchParamList.js +41 -0
- package/lib/components/search/result/SearchPending.js +21 -0
- package/lib/components/search/result/SearchResultImage.js +227 -0
- package/lib/components/search/result/SearchResultList.js +119 -0
- package/lib/components/search/result/SearchResultPanel.js +139 -0
- package/lib/components/search/result/SearchResultPanelContainer.js +23 -0
- package/lib/components/search/result/SearchResultStats.js +39 -0
- package/lib/components/search/result/SearchResultTile.js +61 -0
- package/lib/config/anthro.js +123 -0
- package/lib/config/bonsai.js +50 -0
- package/lib/config/botgarden.js +10 -0
- package/lib/config/default.js +530 -0
- package/lib/config/fcart.js +36 -0
- package/lib/config/herbarium.js +10 -0
- package/lib/config/index.js +53 -0
- package/lib/config/lhmc.js +10 -0
- package/lib/config/materials.js +982 -0
- package/lib/config/publicart.js +10 -0
- package/lib/constants/actionCodes.js +46 -0
- package/lib/constants/ids.js +12 -0
- package/lib/helpers/bodyClassName.js +11 -0
- package/lib/helpers/esQueryHelpers.js +206 -0
- package/lib/helpers/formatHelpers.js +293 -0
- package/lib/helpers/searchDimensions.js +28 -0
- package/lib/helpers/urlHelpers.js +43 -0
- package/lib/index.js +53 -0
- package/lib/intl/index.js +16 -0
- package/lib/reducers/detailReducer.js +145 -0
- package/lib/reducers/filterReducer.js +22 -0
- package/lib/reducers/index.js +66 -0
- package/lib/reducers/mediaReducer.js +43 -0
- package/lib/reducers/prefsReducer.js +27 -0
- package/lib/reducers/searchEntryFormReducer.js +24 -0
- package/lib/reducers/searchReducer.js +88 -0
- package/package.json +118 -0
- package/src/actions/detailActions.js +231 -0
- package/src/actions/filterActions.js +10 -0
- package/src/actions/mediaActions.js +65 -0
- package/src/actions/prefsActions.js +95 -0
- package/src/actions/searchActions.js +188 -0
- package/src/actions/searchEntryFormActions.js +15 -0
- package/src/components/App.jsx +18 -0
- package/src/components/detail/DetailNavBar.jsx +132 -0
- package/src/components/detail/DetailPanel.jsx +215 -0
- package/src/components/detail/DetailPanelContainer.js +29 -0
- package/src/components/detail/ExhibitionSection.jsx +71 -0
- package/src/components/detail/FieldList.jsx +122 -0
- package/src/components/detail/FieldValueList.jsx +31 -0
- package/src/components/detail/ImageGallery.jsx +153 -0
- package/src/components/detail/ImageGalleryContainer.js +17 -0
- package/src/components/detail/InstitutionHoldingList.jsx +188 -0
- package/src/components/detail/InstitutionHoldingListContainer.js +29 -0
- package/src/components/detail/InstitutionIndex.jsx +57 -0
- package/src/components/detail/InstitutionIndexContainer.js +11 -0
- package/src/components/detail/InstitutionSection.jsx +48 -0
- package/src/components/detail/InstitutionSectionContainer.js +11 -0
- package/src/components/layout/Fixed.jsx +29 -0
- package/src/components/layout/IconButton.jsx +41 -0
- package/src/components/layout/Panel.jsx +60 -0
- package/src/components/layout/PanelContainer.js +20 -0
- package/src/components/layout/PanelTitle.jsx +43 -0
- package/src/components/layout/ScrollTopButton.jsx +76 -0
- package/src/components/layout/ToggleFilterPanelButton.jsx +43 -0
- package/src/components/pages/DetailPage.jsx +101 -0
- package/src/components/pages/DetailPageContainer.js +18 -0
- package/src/components/pages/RootPage.jsx +37 -0
- package/src/components/pages/SearchPage.jsx +160 -0
- package/src/components/pages/SearchPageContainer.js +21 -0
- package/src/components/search/entry/SearchEntryForm.jsx +82 -0
- package/src/components/search/entry/SearchEntryFormContainer.js +22 -0
- package/src/components/search/entry/SearchEntryPanel.jsx +28 -0
- package/src/components/search/entry/SearchQueryInput.jsx +95 -0
- package/src/components/search/entry/SearchSubmitButton.jsx +22 -0
- package/src/components/search/entry/SortSelect.jsx +104 -0
- package/src/components/search/entry/SortSelectContainer.js +12 -0
- package/src/components/search/result/ClearSearchParamsLink.jsx +43 -0
- package/src/components/search/result/Filter.jsx +226 -0
- package/src/components/search/result/FilterContainer.js +20 -0
- package/src/components/search/result/FilterGroup.jsx +83 -0
- package/src/components/search/result/FilterList.jsx +51 -0
- package/src/components/search/result/FilterPanel.jsx +143 -0
- package/src/components/search/result/FilterPanelContainer.js +16 -0
- package/src/components/search/result/FilterSearchInput.jsx +68 -0
- package/src/components/search/result/RemoveSearchParamLink.jsx +79 -0
- package/src/components/search/result/SearchError.jsx +30 -0
- package/src/components/search/result/SearchLoadMore.jsx +37 -0
- package/src/components/search/result/SearchParamList.jsx +47 -0
- package/src/components/search/result/SearchPending.jsx +19 -0
- package/src/components/search/result/SearchResultImage.jsx +275 -0
- package/src/components/search/result/SearchResultList.jsx +144 -0
- package/src/components/search/result/SearchResultPanel.jsx +169 -0
- package/src/components/search/result/SearchResultPanelContainer.js +31 -0
- package/src/components/search/result/SearchResultStats.jsx +38 -0
- package/src/components/search/result/SearchResultTile.jsx +70 -0
- package/src/config/anthro.js +153 -0
- package/src/config/bonsai.js +50 -0
- package/src/config/botgarden.js +3 -0
- package/src/config/default.js +604 -0
- package/src/config/fcart.js +38 -0
- package/src/config/herbarium.js +3 -0
- package/src/config/index.js +51 -0
- package/src/config/lhmc.js +3 -0
- package/src/config/materials.js +1173 -0
- package/src/config/publicart.js +3 -0
- package/src/constants/actionCodes.js +26 -0
- package/src/constants/ids.js +3 -0
- package/src/helpers/bodyClassName.js +5 -0
- package/src/helpers/esQueryHelpers.js +224 -0
- package/src/helpers/formatHelpers.jsx +361 -0
- package/src/helpers/searchDimensions.js +21 -0
- package/src/helpers/urlHelpers.js +49 -0
- package/src/index.jsx +59 -0
- package/src/intl/index.js +16 -0
- package/src/reducers/detailReducer.js +201 -0
- package/src/reducers/filterReducer.js +16 -0
- package/src/reducers/index.js +56 -0
- package/src/reducers/mediaReducer.js +44 -0
- package/src/reducers/prefsReducer.js +24 -0
- package/src/reducers/searchEntryFormReducer.js +19 -0
- package/src/reducers/searchReducer.js +118 -0
- package/styles/colors.css +7 -0
- package/styles/cspace/DetailNavBar.css +17 -0
- package/styles/cspace/DetailPage.css +3 -0
- package/styles/cspace/DetailPanel.css +69 -0
- package/styles/cspace/ExhibitionSection.css +9 -0
- package/styles/cspace/FieldList.css +15 -0
- package/styles/cspace/FieldListField.css +7 -0
- package/styles/cspace/FieldListGroup.css +27 -0
- package/styles/cspace/FieldValueList.css +19 -0
- package/styles/cspace/Filter.css +64 -0
- package/styles/cspace/FilterGroup.css +21 -0
- package/styles/cspace/FilterPanel.css +45 -0
- package/styles/cspace/FilterSearchInput.css +13 -0
- package/styles/cspace/Fixed.css +8 -0
- package/styles/cspace/IconButton.css +11 -0
- package/styles/cspace/ImageGallery.css +43 -0
- package/styles/cspace/InstitutionHoldingList.css +109 -0
- package/styles/cspace/InstitutionIndex.css +13 -0
- package/styles/cspace/InstitutionSection.css +4 -0
- package/styles/cspace/Link.css +39 -0
- package/styles/cspace/Panel.css +53 -0
- package/styles/cspace/PanelTitle.css +48 -0
- package/styles/cspace/RemoveSearchParamLink.css +15 -0
- package/styles/cspace/RootPage.css +60 -0
- package/styles/cspace/ScrollTopButton.css +32 -0
- package/styles/cspace/SearchEntryForm.css +4 -0
- package/styles/cspace/SearchEntryPanel.css +11 -0
- package/styles/cspace/SearchPage.css +2 -0
- package/styles/cspace/SearchParamLink.css +21 -0
- package/styles/cspace/SearchParamList.css +6 -0
- package/styles/cspace/SearchQueryInput.css +30 -0
- package/styles/cspace/SearchResultImage.css +29 -0
- package/styles/cspace/SearchResultList.css +10 -0
- package/styles/cspace/SearchResultPanel.css +31 -0
- package/styles/cspace/SearchResultStats.css +4 -0
- package/styles/cspace/SearchResultTile.css +67 -0
- package/styles/cspace/SearchStatus.css +12 -0
- package/styles/cspace/SearchSubmitButton.css +3 -0
- package/styles/cspace/SortSelect.css +19 -0
- package/styles/cspace/ToggleFilterPanelButton.css +44 -0
- package/styles/dimensions.css +9 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { defineMessages, injectIntl } from 'react-intl';
|
|
4
|
+
import SearchSubmitButton from './SearchSubmitButton';
|
|
5
|
+
import styles from '../../../../styles/cspace/SearchQueryInput.css';
|
|
6
|
+
|
|
7
|
+
const propTypes = {
|
|
8
|
+
id: PropTypes.string.isRequired,
|
|
9
|
+
intl: PropTypes.shape({
|
|
10
|
+
formatMessage: PropTypes.func.isRequired,
|
|
11
|
+
}).isRequired,
|
|
12
|
+
onCommit: PropTypes.func,
|
|
13
|
+
showSubmitButton: PropTypes.bool,
|
|
14
|
+
value: PropTypes.string,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const defaultProps = {
|
|
18
|
+
onCommit: () => undefined,
|
|
19
|
+
showSubmitButton: false,
|
|
20
|
+
value: '',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const messages = defineMessages({
|
|
24
|
+
label: {
|
|
25
|
+
id: 'searchQueryInput.label',
|
|
26
|
+
defaultMessage: 'Search collection',
|
|
27
|
+
},
|
|
28
|
+
placeholder: {
|
|
29
|
+
id: 'searchQueryInput.placeholder',
|
|
30
|
+
defaultMessage: 'Search collection',
|
|
31
|
+
},
|
|
32
|
+
shortLabel: {
|
|
33
|
+
id: 'searchQueryInput.shortLabel',
|
|
34
|
+
defaultMessage: 'Search',
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
class SearchQueryInput extends Component {
|
|
39
|
+
constructor() {
|
|
40
|
+
super();
|
|
41
|
+
|
|
42
|
+
this.handleChange = this.handleChange.bind(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
handleChange(event) {
|
|
46
|
+
const {
|
|
47
|
+
id,
|
|
48
|
+
onCommit,
|
|
49
|
+
} = this.props;
|
|
50
|
+
|
|
51
|
+
onCommit(id, event.target.value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
commit() {
|
|
55
|
+
const {
|
|
56
|
+
id,
|
|
57
|
+
onCommit,
|
|
58
|
+
} = this.props;
|
|
59
|
+
|
|
60
|
+
if (this.inputDomNode) {
|
|
61
|
+
onCommit(id, this.inputDomNode.value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
render() {
|
|
66
|
+
const {
|
|
67
|
+
id,
|
|
68
|
+
intl,
|
|
69
|
+
showSubmitButton,
|
|
70
|
+
value,
|
|
71
|
+
} = this.props;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div className={styles.common}>
|
|
75
|
+
<input
|
|
76
|
+
aria-label={intl.formatMessage(messages.label)}
|
|
77
|
+
autoComplete="off"
|
|
78
|
+
autoCorrect="off"
|
|
79
|
+
name={id}
|
|
80
|
+
placeholder={intl.formatMessage(messages.placeholder)}
|
|
81
|
+
type="search"
|
|
82
|
+
value={value}
|
|
83
|
+
onChange={this.handleChange}
|
|
84
|
+
/>
|
|
85
|
+
|
|
86
|
+
{showSubmitButton && <SearchSubmitButton />}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
SearchQueryInput.propTypes = propTypes;
|
|
93
|
+
SearchQueryInput.defaultProps = defaultProps;
|
|
94
|
+
|
|
95
|
+
export default injectIntl(SearchQueryInput);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
3
|
+
import styles from '../../../../styles/cspace/SearchSubmitButton.css';
|
|
4
|
+
|
|
5
|
+
const messages = defineMessages({
|
|
6
|
+
submit: {
|
|
7
|
+
id: 'searchEntryForm.submit',
|
|
8
|
+
defaultMessage: 'Search',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export default function SearchSubmitButton() {
|
|
13
|
+
return (
|
|
14
|
+
<button
|
|
15
|
+
className={styles.common}
|
|
16
|
+
type="submit"
|
|
17
|
+
>
|
|
18
|
+
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
|
19
|
+
<FormattedMessage {...messages.submit} />
|
|
20
|
+
</button>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { withRouter } from 'react-router';
|
|
4
|
+
import { defineMessages, injectIntl } from 'react-intl';
|
|
5
|
+
import config from '../../../config';
|
|
6
|
+
import styles from '../../../../styles/cspace/SortSelect.css';
|
|
7
|
+
|
|
8
|
+
const propTypes = {
|
|
9
|
+
history: PropTypes.shape({
|
|
10
|
+
push: PropTypes.func,
|
|
11
|
+
}).isRequired,
|
|
12
|
+
intl: PropTypes.shape({
|
|
13
|
+
formatMessage: PropTypes.func.isRequired,
|
|
14
|
+
}).isRequired,
|
|
15
|
+
onCommit: PropTypes.func,
|
|
16
|
+
value: PropTypes.string,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const defaultProps = {
|
|
20
|
+
onCommit: () => undefined,
|
|
21
|
+
value: config.get('defaultSortOrder'),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const messages = defineMessages({
|
|
25
|
+
label: {
|
|
26
|
+
id: 'sortSelect.label',
|
|
27
|
+
defaultMessage: 'Sort results by',
|
|
28
|
+
},
|
|
29
|
+
bestmatch: {
|
|
30
|
+
id: 'sortSelect.bestmatch',
|
|
31
|
+
defaultMessage: 'Best match',
|
|
32
|
+
},
|
|
33
|
+
atoz: {
|
|
34
|
+
id: 'sortSelect.atoz',
|
|
35
|
+
defaultMessage: 'A to Z',
|
|
36
|
+
},
|
|
37
|
+
ztoa: {
|
|
38
|
+
id: 'sortSelect.ztoa',
|
|
39
|
+
defaultMessage: 'Z to A',
|
|
40
|
+
},
|
|
41
|
+
newest: {
|
|
42
|
+
id: 'sortSelect.newest',
|
|
43
|
+
defaultMessage: 'Newest',
|
|
44
|
+
},
|
|
45
|
+
oldest: {
|
|
46
|
+
id: 'sortSelect.oldest',
|
|
47
|
+
defaultMessage: 'Oldest',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
class SortSelect extends Component {
|
|
52
|
+
constructor() {
|
|
53
|
+
super();
|
|
54
|
+
|
|
55
|
+
this.handleChange = this.handleChange.bind(this);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
handleChange(event) {
|
|
59
|
+
const {
|
|
60
|
+
history,
|
|
61
|
+
onCommit,
|
|
62
|
+
} = this.props;
|
|
63
|
+
|
|
64
|
+
onCommit(history, event.target.value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
render() {
|
|
68
|
+
const {
|
|
69
|
+
intl,
|
|
70
|
+
value,
|
|
71
|
+
} = this.props;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<label
|
|
75
|
+
htmlFor="sort-select"
|
|
76
|
+
>
|
|
77
|
+
Sort by
|
|
78
|
+
{' '}
|
|
79
|
+
<select
|
|
80
|
+
className={styles.common}
|
|
81
|
+
id="sort-select"
|
|
82
|
+
value={value}
|
|
83
|
+
onChange={this.handleChange}
|
|
84
|
+
>
|
|
85
|
+
{
|
|
86
|
+
['bestmatch', 'atoz', 'ztoa', 'newest', 'oldest'].map((sortOrder) => (
|
|
87
|
+
<option
|
|
88
|
+
key={sortOrder}
|
|
89
|
+
value={sortOrder}
|
|
90
|
+
>
|
|
91
|
+
{intl.formatMessage(messages[sortOrder])}
|
|
92
|
+
</option>
|
|
93
|
+
))
|
|
94
|
+
}
|
|
95
|
+
</select>
|
|
96
|
+
</label>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
SortSelect.propTypes = propTypes;
|
|
102
|
+
SortSelect.defaultProps = defaultProps;
|
|
103
|
+
|
|
104
|
+
export default withRouter(injectIntl(SortSelect));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { connect } from 'react-redux';
|
|
2
|
+
import SortSelect from './SortSelect';
|
|
3
|
+
import { applySortOrder } from '../../../actions/searchActions';
|
|
4
|
+
|
|
5
|
+
const mapDispatchToProps = {
|
|
6
|
+
onCommit: applySortOrder,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default connect(
|
|
10
|
+
undefined,
|
|
11
|
+
mapDispatchToProps,
|
|
12
|
+
)(SortSelect);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
4
|
+
import { Link } from 'react-router-dom';
|
|
5
|
+
import Immutable from 'immutable';
|
|
6
|
+
import { SORT_ID } from '../../../constants/ids';
|
|
7
|
+
import { searchParamsToQueryString } from '../../../helpers/urlHelpers';
|
|
8
|
+
import styles from '../../../../styles/cspace/SearchParamLink.css';
|
|
9
|
+
|
|
10
|
+
const propTypes = {
|
|
11
|
+
params: PropTypes.instanceOf(Immutable.Map).isRequired,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const messages = defineMessages({
|
|
15
|
+
label: {
|
|
16
|
+
id: 'clearSearchParamsLink.label',
|
|
17
|
+
defaultMessage: 'Clear all',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default function ClearSearchParamsLink(props) {
|
|
22
|
+
const {
|
|
23
|
+
params,
|
|
24
|
+
} = props;
|
|
25
|
+
|
|
26
|
+
const sortParam = params.filter((value, key) => (key === SORT_ID));
|
|
27
|
+
const hasNonSortParam = params.size > sortParam.size;
|
|
28
|
+
|
|
29
|
+
if (hasNonSortParam) {
|
|
30
|
+
const queryString = searchParamsToQueryString(sortParam);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Link className={styles.common} to={{ search: `?${queryString}` }}>
|
|
34
|
+
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
|
35
|
+
<FormattedMessage {...messages.label} />
|
|
36
|
+
</Link>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ClearSearchParamsLink.propTypes = propTypes;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
4
|
+
import { withRouter } from 'react-router';
|
|
5
|
+
import Immutable from 'immutable';
|
|
6
|
+
import memoize from 'memoize-one';
|
|
7
|
+
import FilterSearchInput from './FilterSearchInput';
|
|
8
|
+
import Panel from '../../layout/PanelContainer';
|
|
9
|
+
import styles from '../../../../styles/cspace/Filter.css';
|
|
10
|
+
|
|
11
|
+
const propTypes = {
|
|
12
|
+
aggregation: PropTypes.instanceOf(Immutable.Map),
|
|
13
|
+
field: PropTypes.string.isRequired,
|
|
14
|
+
formatValue: PropTypes.func,
|
|
15
|
+
history: PropTypes.shape({
|
|
16
|
+
push: PropTypes.func.isRequired,
|
|
17
|
+
}).isRequired,
|
|
18
|
+
id: PropTypes.string.isRequired,
|
|
19
|
+
messages: PropTypes.shape({
|
|
20
|
+
label: PropTypes.object.isRequired,
|
|
21
|
+
}).isRequired,
|
|
22
|
+
onSearchValueCommit: PropTypes.func,
|
|
23
|
+
onValueCommit: PropTypes.func,
|
|
24
|
+
params: PropTypes.instanceOf(Immutable.Map).isRequired,
|
|
25
|
+
searchValue: PropTypes.string,
|
|
26
|
+
showSearch: PropTypes.bool,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const defaultProps = {
|
|
30
|
+
aggregation: Immutable.Map(),
|
|
31
|
+
formatValue: undefined,
|
|
32
|
+
onSearchValueCommit: () => undefined,
|
|
33
|
+
onValueCommit: () => undefined,
|
|
34
|
+
searchValue: undefined,
|
|
35
|
+
showSearch: true,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const messages = defineMessages({
|
|
39
|
+
count: {
|
|
40
|
+
id: 'filter.count',
|
|
41
|
+
defaultMessage: '({count, number})',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const getFormattedValues = memoize((aggregation, formatValue) => {
|
|
46
|
+
if (!formatValue) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const formattedValues = {};
|
|
51
|
+
|
|
52
|
+
aggregation.get('buckets').forEach((bucket) => {
|
|
53
|
+
const value = bucket.get('key');
|
|
54
|
+
const formattedValue = formatValue(value);
|
|
55
|
+
|
|
56
|
+
formattedValues[value] = formattedValue;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return formattedValues;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const handleCheckboxFocus = (event) => {
|
|
63
|
+
const {
|
|
64
|
+
target: focusedFieldElement,
|
|
65
|
+
} = event;
|
|
66
|
+
|
|
67
|
+
const fieldIndex = focusedFieldElement.getAttribute('data-number');
|
|
68
|
+
const focusedFieldLiElement = focusedFieldElement.parentElement.parentElement;
|
|
69
|
+
const focusedFieldUlElement = focusedFieldLiElement.parentElement;
|
|
70
|
+
const newScrollPosition = focusedFieldLiElement.getBoundingClientRect().height * fieldIndex;
|
|
71
|
+
|
|
72
|
+
focusedFieldUlElement.scrollTop = newScrollPosition;
|
|
73
|
+
focusedFieldUlElement.scrollIntoView({ block: 'end', behavior: 'instant' });
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
class Filter extends Component {
|
|
77
|
+
constructor() {
|
|
78
|
+
super();
|
|
79
|
+
|
|
80
|
+
this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
|
|
81
|
+
this.handleSearchInputCommit = this.handleSearchInputCommit.bind(this);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
handleSearchInputCommit(value) {
|
|
85
|
+
const {
|
|
86
|
+
id,
|
|
87
|
+
onSearchValueCommit,
|
|
88
|
+
} = this.props;
|
|
89
|
+
|
|
90
|
+
onSearchValueCommit(id, value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
handleCheckboxChange(event) {
|
|
94
|
+
const {
|
|
95
|
+
history,
|
|
96
|
+
id,
|
|
97
|
+
onValueCommit,
|
|
98
|
+
} = this.props;
|
|
99
|
+
|
|
100
|
+
const {
|
|
101
|
+
target: checkbox,
|
|
102
|
+
} = event;
|
|
103
|
+
|
|
104
|
+
const {
|
|
105
|
+
dataset,
|
|
106
|
+
name,
|
|
107
|
+
} = checkbox;
|
|
108
|
+
|
|
109
|
+
const { type } = dataset;
|
|
110
|
+
const value = (type === 'number') ? Number.parseInt(name, 10) : name;
|
|
111
|
+
|
|
112
|
+
onValueCommit(history, id, value, checkbox.checked);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
renderBuckets() {
|
|
116
|
+
const {
|
|
117
|
+
aggregation,
|
|
118
|
+
formatValue,
|
|
119
|
+
id,
|
|
120
|
+
params,
|
|
121
|
+
searchValue,
|
|
122
|
+
} = this.props;
|
|
123
|
+
|
|
124
|
+
const formattedValues = getFormattedValues(aggregation, formatValue);
|
|
125
|
+
const buckets = aggregation.get('buckets');
|
|
126
|
+
|
|
127
|
+
let matchingBuckets = buckets;
|
|
128
|
+
|
|
129
|
+
if (searchValue) {
|
|
130
|
+
const needle = searchValue.toLowerCase();
|
|
131
|
+
|
|
132
|
+
matchingBuckets = buckets.filter((bucket) => {
|
|
133
|
+
const value = bucket.get('key');
|
|
134
|
+
const formattedValue = formattedValues ? formattedValues[value] : value;
|
|
135
|
+
const haystack = formattedValue.toLowerCase();
|
|
136
|
+
|
|
137
|
+
return haystack.includes(needle);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let selectedValues = params.get(id) || Immutable.List();
|
|
142
|
+
|
|
143
|
+
if (!Immutable.List.isList(selectedValues)) {
|
|
144
|
+
selectedValues = Immutable.List.of(selectedValues);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return matchingBuckets.map((bucket, index) => {
|
|
148
|
+
const value = bucket.get('key');
|
|
149
|
+
const type = typeof value;
|
|
150
|
+
const count = bucket.get('doc_count');
|
|
151
|
+
const isSelected = (selectedValues.indexOf(value) >= 0);
|
|
152
|
+
const formattedValue = formattedValues ? formattedValues[value] : value;
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<li key={value}>
|
|
156
|
+
{/* The linter is not figuring out that there is an input inside this label. */}
|
|
157
|
+
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
|
|
158
|
+
<label>
|
|
159
|
+
<input
|
|
160
|
+
checked={isSelected}
|
|
161
|
+
data-type={type !== 'string' ? type : undefined}
|
|
162
|
+
data-number={index}
|
|
163
|
+
name={value}
|
|
164
|
+
type="checkbox"
|
|
165
|
+
onChange={this.handleCheckboxChange}
|
|
166
|
+
onFocus={handleCheckboxFocus}
|
|
167
|
+
/>
|
|
168
|
+
|
|
169
|
+
<div>
|
|
170
|
+
<span>
|
|
171
|
+
{formattedValue}
|
|
172
|
+
{' '}
|
|
173
|
+
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
|
174
|
+
<FormattedMessage {...messages.count} values={{ count }} />
|
|
175
|
+
</span>
|
|
176
|
+
</div>
|
|
177
|
+
</label>
|
|
178
|
+
</li>
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
render() {
|
|
184
|
+
const {
|
|
185
|
+
aggregation,
|
|
186
|
+
id,
|
|
187
|
+
messages: filterMessages,
|
|
188
|
+
searchValue,
|
|
189
|
+
showSearch,
|
|
190
|
+
} = this.props;
|
|
191
|
+
|
|
192
|
+
const buckets = aggregation.get('buckets');
|
|
193
|
+
const isEmpty = !buckets || buckets.size === 0;
|
|
194
|
+
|
|
195
|
+
if (isEmpty) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
200
|
+
const title = <FormattedMessage {...filterMessages.label} />;
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<Panel id={`Filter-${id}`} title={title}>
|
|
204
|
+
<div className={styles.common}>
|
|
205
|
+
{
|
|
206
|
+
showSearch
|
|
207
|
+
&& (
|
|
208
|
+
<FilterSearchInput
|
|
209
|
+
value={searchValue}
|
|
210
|
+
onCommit={this.handleSearchInputCommit}
|
|
211
|
+
/>
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
<ul>
|
|
215
|
+
{this.renderBuckets(buckets)}
|
|
216
|
+
</ul>
|
|
217
|
+
</div>
|
|
218
|
+
</Panel>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
Filter.propTypes = propTypes;
|
|
224
|
+
Filter.defaultProps = defaultProps;
|
|
225
|
+
|
|
226
|
+
export default withRouter(Filter);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { connect } from 'react-redux';
|
|
2
|
+
import Filter from './Filter';
|
|
3
|
+
import { setFilterSearchValue } from '../../../actions/filterActions';
|
|
4
|
+
import { applyFilter } from '../../../actions/searchActions';
|
|
5
|
+
import { getFilterSearchValue, getSearchParams } from '../../../reducers';
|
|
6
|
+
|
|
7
|
+
const mapStateToProps = (state, ownProps) => ({
|
|
8
|
+
searchValue: getFilterSearchValue(state, ownProps.id),
|
|
9
|
+
params: getSearchParams(state),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const mapDispatchToProps = ({
|
|
13
|
+
onSearchValueCommit: setFilterSearchValue,
|
|
14
|
+
onValueCommit: applyFilter,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default connect(
|
|
18
|
+
mapStateToProps,
|
|
19
|
+
mapDispatchToProps,
|
|
20
|
+
)(Filter);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { FormattedMessage } from 'react-intl';
|
|
4
|
+
import Immutable from 'immutable';
|
|
5
|
+
import Filter from './FilterContainer';
|
|
6
|
+
import styles from '../../../../styles/cspace/FilterGroup.css';
|
|
7
|
+
|
|
8
|
+
const propTypes = {
|
|
9
|
+
config: PropTypes.shape({
|
|
10
|
+
fields: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
11
|
+
label: PropTypes.string,
|
|
12
|
+
messages: PropTypes.object,
|
|
13
|
+
}).isRequired,
|
|
14
|
+
fieldsConfig: PropTypes.objectOf(PropTypes.object).isRequired,
|
|
15
|
+
id: PropTypes.string.isRequired,
|
|
16
|
+
isPending: PropTypes.bool,
|
|
17
|
+
aggregations: PropTypes.instanceOf(Immutable.Map),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const defaultProps = {
|
|
21
|
+
isPending: false,
|
|
22
|
+
aggregations: Immutable.Map(),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default function FilterGroup(props) {
|
|
26
|
+
const {
|
|
27
|
+
aggregations,
|
|
28
|
+
config,
|
|
29
|
+
fieldsConfig,
|
|
30
|
+
} = props;
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
fields,
|
|
34
|
+
label,
|
|
35
|
+
messages,
|
|
36
|
+
} = config;
|
|
37
|
+
|
|
38
|
+
const isEmpty = aggregations.isEmpty() || !fields.find((fieldId) => {
|
|
39
|
+
const buckets = aggregations.getIn([fieldId, 'buckets']);
|
|
40
|
+
|
|
41
|
+
return (buckets && buckets.size > 0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (isEmpty) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const labelMessage = messages && messages.label;
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
51
|
+
const headerContent = labelMessage ? <FormattedMessage {...labelMessage} /> : label;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className={styles.common}>
|
|
55
|
+
{headerContent && <h1>{headerContent}</h1>}
|
|
56
|
+
{
|
|
57
|
+
fields.map((fieldId) => {
|
|
58
|
+
const {
|
|
59
|
+
field,
|
|
60
|
+
formatValue,
|
|
61
|
+
messages: fieldMessages,
|
|
62
|
+
showSearch,
|
|
63
|
+
} = fieldsConfig[fieldId];
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Filter
|
|
67
|
+
aggregation={aggregations.get(fieldId)}
|
|
68
|
+
id={fieldId}
|
|
69
|
+
field={field}
|
|
70
|
+
formatValue={formatValue}
|
|
71
|
+
key={fieldId}
|
|
72
|
+
messages={fieldMessages}
|
|
73
|
+
showSearch={showSearch}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
FilterGroup.propTypes = propTypes;
|
|
83
|
+
FilterGroup.defaultProps = defaultProps;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Immutable from 'immutable';
|
|
4
|
+
import FilterGroup from './FilterGroup';
|
|
5
|
+
|
|
6
|
+
const propTypes = {
|
|
7
|
+
config: PropTypes.shape({
|
|
8
|
+
fields: PropTypes.object.isRequired,
|
|
9
|
+
groups: PropTypes.object.isRequired,
|
|
10
|
+
layout: PropTypes.object.isRequired,
|
|
11
|
+
}).isRequired,
|
|
12
|
+
isPending: PropTypes.bool,
|
|
13
|
+
aggregations: PropTypes.instanceOf(Immutable.Map),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const defaultProps = {
|
|
17
|
+
aggregations: Immutable.Map(),
|
|
18
|
+
isPending: PropTypes.bool,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default function FilterList(props) {
|
|
22
|
+
const {
|
|
23
|
+
aggregations,
|
|
24
|
+
config,
|
|
25
|
+
isPending,
|
|
26
|
+
} = props;
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
fields,
|
|
30
|
+
groups,
|
|
31
|
+
layout,
|
|
32
|
+
} = config;
|
|
33
|
+
|
|
34
|
+
return Object.keys(layout).map((layoutId) => (
|
|
35
|
+
<div key={layoutId}>
|
|
36
|
+
{layout[layoutId].map((groupId) => (
|
|
37
|
+
<FilterGroup
|
|
38
|
+
aggregations={aggregations}
|
|
39
|
+
config={groups[groupId]}
|
|
40
|
+
fieldsConfig={fields}
|
|
41
|
+
id={groupId}
|
|
42
|
+
isPending={isPending}
|
|
43
|
+
key={groupId}
|
|
44
|
+
/>
|
|
45
|
+
))}
|
|
46
|
+
</div>
|
|
47
|
+
));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
FilterList.propTypes = propTypes;
|
|
51
|
+
FilterList.defaultProps = defaultProps;
|