Merge branch 'main' into 21841-missing-vocab
[arvados.git] / services / workbench2 / 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, SEARCH_BAR_ADVANCED_FORM_NAME
20 } from 'store/search-bar/search-bar-actions';
21 import { SearchBarView, SearchBarActionProps, SearchBarDataProps } from 'views-components/search-bar/search-bar-view';
22 import { SearchBarAdvancedFormData } from 'models/search-bar';
23 import { Vocabulary } from 'models/vocabulary';
24 import { searchSingleCluster } from 'store/search-results-panel/search-results-middleware-service';
25 import { Session } from 'models/session';
26
27 const mapStateToProps = ({ searchBar, form , auth }: RootState): SearchBarDataProps => {
28     return {
29         searchValue: searchBar.searchValue,
30         currentView: searchBar.currentView,
31         isPopoverOpen: searchBar.open,
32         searchResults: searchBar.searchResults,
33         selectedItem: searchBar.selectedItem,
34         savedQueries: searchBar.savedQueries,
35         tags: form[SEARCH_BAR_ADVANCED_FORM_NAME],
36         saveQuery: form[SEARCH_BAR_ADVANCED_FORM_NAME] &&
37             form[SEARCH_BAR_ADVANCED_FORM_NAME].values &&
38             form[SEARCH_BAR_ADVANCED_FORM_NAME].values!.saveQuery,
39         sessions: auth.sessions,
40     };
41 };
42
43 const mapDispatchToProps = (dispatch: Dispatch): SearchBarActionProps => ({
44     onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch, true)),
45     onChange: (event: React.ChangeEvent<HTMLInputElement>) => dispatch<any>(changeData(event.target.value)),
46     onSetView: (currentView: string) => dispatch(goToView(currentView)),
47     onSubmit: (event: React.FormEvent<HTMLFormElement>) => dispatch<any>(submitData(event)),
48     closeView: () => dispatch<any>(closeSearchView()),
49     closeAdvanceView: () => dispatch<any>(closeAdvanceView()),
50     loadRecentQueries: () => dispatch<any>(loadRecentQueries()),
51     deleteSavedQuery: (id: number) => dispatch<any>(deleteSavedQuery(id)),
52     openSearchView: () => dispatch<any>(openSearchView()),
53     navigateTo: (uuid: string) => dispatch<any>(navigateToItem(uuid)),
54     editSavedQuery: (data: SearchBarAdvancedFormData) => dispatch<any>(editSavedQuery(data)),
55     moveUp: () => dispatch<any>(moveUp()),
56     moveDown: () => dispatch<any>(moveDown()),
57     setAdvancedDataFromSearchValue: (search: string, vocabulary: Vocabulary) => dispatch<any>(setAdvancedDataFromSearchValue(search, vocabulary)),
58     searchSingleCluster: (session: Session, searchValue: string) => {dispatch<any>(searchSingleCluster(session, searchValue))},
59 });
60
61 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);