refs #master Merge branch 'origin/master' into 14280-query-language
[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     openSearchView,
14     closeSearchView,
15     closeAdvanceView,
16     navigateToItem,
17     editSavedQuery,
18     changeData,
19     submitData, moveUp, moveDown, setAdvancedDataFromSearchValue
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         selectedItem: searchBar.selectedItem,
31         savedQueries: searchBar.savedQueries,
32         tags: form.searchBarAdvanceFormName,
33         saveQuery: form.searchBarAdvanceFormName &&
34             form.searchBarAdvanceFormName.values &&
35             form.searchBarAdvanceFormName.values.saveQuery
36     };
37 };
38
39 const mapDispatchToProps = (dispatch: Dispatch): SearchBarActionProps => ({
40     onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch)),
41     onChange: (event: React.ChangeEvent<HTMLInputElement>) => dispatch<any>(changeData(event.target.value)),
42     onSetView: (currentView: string) => dispatch(goToView(currentView)),
43     onSubmit: (event: React.FormEvent<HTMLFormElement>) => dispatch<any>(submitData(event)),
44     closeView: () => dispatch<any>(closeSearchView()),
45     closeAdvanceView: () => dispatch<any>(closeAdvanceView()),
46     loadRecentQueries: () => dispatch<any>(loadRecentQueries()),
47     deleteSavedQuery: (id: number) => dispatch<any>(deleteSavedQuery(id)),
48     openSearchView: () => dispatch<any>(openSearchView()),
49     navigateTo: (uuid: string) => dispatch<any>(navigateToItem(uuid)),
50     editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(editSavedQuery(data)),
51     moveUp: () => dispatch<any>(moveUp()),
52     moveDown: () => dispatch<any>(moveDown()),
53     setAdvancedDataFromSearchValue: (search: string) => dispatch<any>(setAdvancedDataFromSearchValue(search))
54 });
55
56 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);