saving-in-store-for-dynamic-deleting
[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     searchBarActions,
12     deleteSavedQuery,
13     saveRecentQuery,
14     loadRecentQueries,
15     saveQuery
16 } from '~/store/search-bar/search-bar-actions';
17 import { SearchBarView } from '~/views-components/search-bar/search-bar-view';
18
19 const mapStateToProps = ({ searchBar }: RootState) => {
20     return {
21         searchValue: searchBar.searchValue,
22         currentView: searchBar.currentView,
23         isPopoverOpen: searchBar.open,
24         searchResults: searchBar.searchResults,
25         savedQueries: searchBar.savedQueries
26     };
27 };
28
29 const mapDispatchToProps = (dispatch: Dispatch) => ({
30     onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch)),
31     onSetView: (currentView: string) => dispatch(goToView(currentView)),
32     openView: () => dispatch<any>(searchBarActions.OPEN_SEARCH_VIEW()),
33     closeView: () => dispatch<any>(searchBarActions.CLOSE_SEARCH_VIEW()),
34     saveRecentQuery: (query: string) => dispatch<any>(saveRecentQuery(query)),
35     loadRecentQueries: () => dispatch<any>(loadRecentQueries()),
36     saveQuery: (query: string) => dispatch<any>(saveQuery(query)),
37     deleteSavedQuery: (id: number) => dispatch<any>(deleteSavedQuery(id))
38 });
39
40 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);