/
QueryBarView.js
79 lines (72 loc) · 2.38 KB
/
QueryBarView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React from 'react';
import { connect, useDispatch } from 'react-redux';
import { clearAllFilters, clearFacetSection, clearSliderSection, toggleCheckBox } from '@bento-core/facet-filter';
import { resetAllData, resetUploadData, updateAutocompleteData } from '@bento-core/local-find';
import { QueryBarGenerator } from '@bento-core/query-bar';
import { facetsConfig } from '../../../bento/dashTemplate';
/**
* Generate the Explore Tab Query Bar
*
* @param {object} props
* @param {object} props.statusReducer Facet Filter State
* @param {object} props.localFind Local Find State
* @returns {JSX.Element}
*/
const QueryBarView = ({ statusReducer, localFind }) => {
const dispatch = useDispatch();
const sectionOrder = facetsConfig.map((v) => v.datafield);
const mappedFilterState = Object.keys(statusReducer || {}).map((facet) => {
return {
...facetsConfig.find((config) => config.datafield === facet),
items: statusReducer[facet],
}
});
mappedFilterState.sort((a, b) => sectionOrder.indexOf(a.datafield) - sectionOrder.indexOf(b.datafield));
const { QueryBar } = QueryBarGenerator({
functions: {
clearAll: () => {
dispatch(resetAllData());
dispatch(clearAllFilters());
},
clearUpload: () => {
dispatch(resetUploadData());
},
clearAutocomplete: () => {
dispatch(updateAutocompleteData([]));
},
deleteAutocompleteItem: (title) => {
const { autocomplete } = localFind;
const newdata = [...autocomplete];
const index = newdata.findIndex((v) => v.title === title);
if (index > -1) {
newdata.splice(index, 1);
dispatch(updateAutocompleteData(newdata));
}
},
resetFacetSection: (section) => {
dispatch(clearFacetSection(section));
},
resetFacetSlider: (section) => {
dispatch(clearSliderSection(section));
},
resetFacetCheckbox: (section, checkbox) => {
dispatch(toggleCheckBox({
datafield: section.datafield,
isChecked: false,
name: checkbox
}));
},
},
});
return (
<QueryBar
statusReducer={mappedFilterState}
localFind={localFind}
/>
);
};
const mapStateToProps = (state) => ({
statusReducer: state.statusReducer.filterState,
localFind: state.localFind,
});
export default connect(mapStateToProps, null)(QueryBarView);