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