Merge branch 'master' of git.curoverse.com:arvados-workbench2 into 13827-structured...
[arvados-workbench2.git] / src / views-components / search-bar / search-bar.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { connect } from 'react-redux';
6 import { RootState } from '~/store/store';
7 import { Dispatch } from 'redux';
8 import { goToView, searchData, searchBarActions } from '~/store/search-bar/search-bar-actions';
9 import { SearchBarView } from '~/views-components/search-bar/search-bar-view';
10 import { saveRecentQuery, loadRecentQueries } from '~/store/search-bar/search-bar-actions';
11
12 const mapStateToProps = ({ searchBar }: RootState) => {
13     return {
14         searchValue: searchBar.searchValue,
15         currentView: searchBar.currentView,
16         open: searchBar.open,
17         searchResults: searchBar.searchResults
18     };
19 };
20
21 const mapDispatchToProps = (dispatch: Dispatch) => ({
22     onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch)),
23     onSetView: (currentView: string) => dispatch(goToView(currentView)),
24     openView: () => dispatch<any>(searchBarActions.OPEN_SEARCH_VIEW()),
25     closeView: () => dispatch<any>(searchBarActions.CLOSE_SEARCH_VIEW()),
26     saveQuery: (query: string) => dispatch<any>(saveRecentQuery(query)),
27     loadQueries: () => dispatch<any>(loadRecentQueries())
28 });
29
30 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);