1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { connect } from 'react-redux';
6 import { RootState } from 'store/store';
7 import { Dispatch } from 'redux';
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';
27 const mapStateToProps = ({ searchBar, form , auth }: RootState): SearchBarDataProps => {
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,
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))},
61 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);