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

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