Sha256: 79f5242cee49cb32a90ca381269eaaf8cd2be86fe4f4a3d2102e8339a6ea96a7
Contents?: true
Size: 1.66 KB
Versions: 10
Compression:
Stored size: 1.66 KB
Contents
import React, { useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import SearchBar from 'foremanReact/components/SearchBar'; import { getControllerSearchProps } from 'foremanReact/constants'; import { getResults } from 'foremanReact/components/AutoComplete/AutoCompleteActions'; import { TRIGGERS } from 'foremanReact/components/AutoComplete/AutoCompleteConstants'; import { hostsController, hostQuerySearchID } from '../../JobWizardConstants'; import { noop } from '../../../helpers'; export const HostSearch = ({ value, setValue }) => { const searchQuery = useSelector( state => state.autocomplete?.hostsSearch?.searchQuery ); useEffect(() => { setValue(searchQuery || ''); }, [setValue, searchQuery]); const dispatch = useDispatch(); const setSearch = newSearchQuery => { dispatch( getResults({ url: '/hosts/auto_complete_search', searchQuery: newSearchQuery, controller: 'hostsController', trigger: TRIGGERS.INPUT_CHANGE, id: hostQuerySearchID, }) ); }; const props = getControllerSearchProps(hostsController, hostQuerySearchID); return ( <div className="foreman-search-field"> <SearchBar data={{ ...props, autocomplete: { id: hostQuerySearchID, url: '/hosts/auto_complete_search', useKeyShortcuts: true, }, }} onSearch={noop} initialQuery={value} onBookmarkClick={search => setSearch(search)} /> </div> ); }; HostSearch.propTypes = { value: PropTypes.string.isRequired, setValue: PropTypes.func.isRequired, };
Version data entries
10 entries across 10 versions & 1 rubygems