change code after quick cr - remove render word inside components
[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     loadRecentQueries,
13     saveQuery,
14     openSearchView,
15     closeSearchView,
16     navigateToItem,
17     editSavedQuery,
18     changeData,
19     submitData
20 } from '~/store/search-bar/search-bar-actions';
21 import { SearchBarView, SearchBarActionProps, SearchBarDataProps } from '~/views-components/search-bar/search-bar-view';
22 import { SearchBarAdvanceFormData } from '~/models/search-bar';
23
24 const mapStateToProps = ({ searchBar, form }: RootState): SearchBarDataProps => {
25     return {
26         searchValue: searchBar.searchValue,
27         currentView: searchBar.currentView,
28         isPopoverOpen: searchBar.open,
29         searchResults: searchBar.searchResults,
30         savedQueries: searchBar.savedQueries,
31         tags: form.searchBarAdvanceFormName
32     };
33 };
34
35 const mapDispatchToProps = (dispatch: Dispatch): SearchBarActionProps => ({
36     onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch)),
37     onChange: (event: React.ChangeEvent<HTMLInputElement>) => dispatch<any>(changeData(event.target.value)),
38     onSetView: (currentView: string) => dispatch(goToView(currentView)),
39     onSubmit: (event: React.FormEvent<HTMLFormElement>) => dispatch<any>(submitData(event)),
40     closeView: () => dispatch<any>(closeSearchView()),
41     loadRecentQueries: () => dispatch<any>(loadRecentQueries()),
42     saveQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(saveQuery(data)),
43     deleteSavedQuery: (id: number) => dispatch<any>(deleteSavedQuery(id)),
44     openSearchView: () => dispatch<any>(openSearchView()),
45     navigateTo: (uuid: string) => dispatch<any>(navigateToItem(uuid)),
46     editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(editSavedQuery(data))
47 });
48
49 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);