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';
25 const mapStateToProps = ({ searchBar, form }: RootState): SearchBarDataProps => {
27 searchValue: searchBar.searchValue,
28 currentView: searchBar.currentView,
29 isPopoverOpen: searchBar.open,
30 searchResults: searchBar.searchResults,
31 selectedItem: searchBar.selectedItem,
32 savedQueries: searchBar.savedQueries,
33 tags: form[SEARCH_BAR_ADVANCED_FORM_NAME],
34 saveQuery: form[SEARCH_BAR_ADVANCED_FORM_NAME] &&
35 form[SEARCH_BAR_ADVANCED_FORM_NAME].values &&
36 form[SEARCH_BAR_ADVANCED_FORM_NAME].values!.saveQuery
40 const mapDispatchToProps = (dispatch: Dispatch): SearchBarActionProps => ({
41 onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch)),
42 onChange: (event: React.ChangeEvent<HTMLInputElement>) => dispatch<any>(changeData(event.target.value)),
43 onSetView: (currentView: string) => dispatch(goToView(currentView)),
44 onSubmit: (event: React.FormEvent<HTMLFormElement>) => dispatch<any>(submitData(event)),
45 closeView: () => dispatch<any>(closeSearchView()),
46 closeAdvanceView: () => dispatch<any>(closeAdvanceView()),
47 loadRecentQueries: () => dispatch<any>(loadRecentQueries()),
48 deleteSavedQuery: (id: number) => dispatch<any>(deleteSavedQuery(id)),
49 openSearchView: () => dispatch<any>(openSearchView()),
50 navigateTo: (uuid: string) => dispatch<any>(navigateToItem(uuid)),
51 editSavedQuery: (data: SearchBarAdvancedFormData) => dispatch<any>(editSavedQuery(data)),
52 moveUp: () => dispatch<any>(moveUp()),
53 moveDown: () => dispatch<any>(moveDown()),
54 setAdvancedDataFromSearchValue: (search: string, vocabulary: Vocabulary) => dispatch<any>(setAdvancedDataFromSearchValue(search, vocabulary))
57 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);