Sha256: a25e719262b2791fc8f3b62213c20b53a8cdbe999c94a50478ed4237338c829d

Contents?: true

Size: 1.46 KB

Versions: 41

Compression:

Stored size: 1.46 KB

Contents

import React, { useState } from 'react';
import { useQuery } from '@apollo/client';
import { SelectVariant } from '@patternfly/react-core';
import {
  useForemanOrganization,
  useForemanLocation,
} from 'foremanReact/Root/Context/ForemanContext';
import { decodeId } from 'foremanReact/common/globalIdHelpers';
import { HOSTS, HOST_GROUPS, dataName } from '../../JobWizardConstants';
import { SearchSelect } from '../form/SearchSelect';
import hostsQuery from './hosts.gql';
import hostgroupsQuery from './hostgroups.gql';

export const useNameSearchGQL = apiKey => {
  const org = useForemanOrganization();
  const location = useForemanLocation();
  const [search, setSearch] = useState('');
  const queries = {
    [HOSTS]: hostsQuery,
    [HOST_GROUPS]: hostgroupsQuery,
  };
  const { loading, data } = useQuery(queries[apiKey], {
    variables: {
      search: [
        `name~"${search}"`,
        org ? `organization_id=${org.id}` : null,
        location ? `location_id=${location.id}` : null,
      ]
        .filter(i => i)
        .join(' and '),
    },
  });
  return [
    setSearch,
    {
      subtotal: data?.[dataName[apiKey]]?.totalCount,
      results:
        data?.[dataName[apiKey]]?.nodes.map(node => ({
          id: decodeId(node.id),
          name: node.name,
        })) || [],
    },
    loading,
  ];
};

export const SelectGQL = props => (
  <SearchSelect
    {...props}
    variant={SelectVariant.typeaheadMulti}
    useNameSearch={useNameSearchGQL}
  />
);

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
foreman_remote_execution-12.0.7 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-10.1.3 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-12.0.5 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-12.0.4 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-12.0.1 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-12.0.2 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-11.1.3 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-10.1.2 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-12.0.0 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-10.1.1 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-11.1.1 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-11.1.0 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-10.1.0 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-8.3.3 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-8.3.2 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-11.0.0 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-10.0.7 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-8.3.1 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-10.0.6 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js
foreman_remote_execution-10.0.5 webpack/JobWizard/steps/HostsAndInputs/SelectGQL.js