merge master
[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 {
9     goToView,
10     searchData,
11     deleteSavedQuery,
12     saveRecentQuery,
13     loadRecentQueries,
14     saveQuery,
15     openSearchView,
16     closeSearchView,
17     navigateToItem
18 } from '~/store/search-bar/search-bar-actions';
19 import { SearchBarView } from '~/views-components/search-bar/search-bar-view';
20 import { SearchBarAdvanceFormData } from '~/models/search-bar';
21
22 const mapStateToProps = ({ searchBar }: RootState) => {
23     return {
24         searchValue: searchBar.searchValue,
25         currentView: searchBar.currentView,
26         isPopoverOpen: searchBar.open,
27         searchResults: searchBar.searchResults,
28         savedQueries: searchBar.savedQueries
29     };
30 };
31
32 const mapDispatchToProps = (dispatch: Dispatch) => ({
33     onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch)),
34     onSetView: (currentView: string) => dispatch(goToView(currentView)),
35     closeView: () => dispatch<any>(closeSearchView()),
36     saveRecentQuery: (query: string) => dispatch<any>(saveRecentQuery(query)),
37     loadRecentQueries: () => dispatch<any>(loadRecentQueries()),
38     saveQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(saveQuery(data)),
39     deleteSavedQuery: (id: number) => dispatch<any>(deleteSavedQuery(id)),
40     openSearchView: () => dispatch<any>(openSearchView()),
41     navigateTo: (uuid: string) => dispatch<any>(navigateToItem(uuid))
42 });
43
44 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);