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

Version Path
foreman_remote_execution-5.0.8 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.7 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.6 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.5 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.4 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.3 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.2 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.1.0 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.1 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js
foreman_remote_execution-5.0.0 webpack/JobWizard/steps/HostsAndInputs/HostSearch.js