Sha256: f49db8e7dca1b749d83b9e4c194513675ec9ca8bc258b65305fafa1ff0e800a8
Contents?: true
Size: 1.16 KB
Versions: 10
Compression:
Stored size: 1.16 KB
Contents
import { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { get } from 'foremanReact/redux/API'; import { HOST_IDS } from './JobWizardConstants'; import { selectRouterSearch } from './JobWizardSelectors'; import './JobWizard.scss'; export const useAutoFill = ({ setSelectedTargets, setHostsSearchQuery }) => { const fills = useSelector(selectRouterSearch); const dispatch = useDispatch(); useEffect(() => { if (Object.keys(fills).length) { if (fills['host_ids[]']) { dispatch( get({ key: HOST_IDS, url: '/api/hosts', params: { search: `id = ${fills['host_ids[]'].join(' or id = ')}` }, handleSuccess: ({ data }) => { setSelectedTargets(currentTargets => ({ ...currentTargets, hosts: (data.results || []).map(({ name }) => ({ id: name, name, })), })); }, }) ); } if (fills.search) { setHostsSearchQuery(fills.search); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); };
Version data entries
10 entries across 10 versions & 1 rubygems