Sha256: 7915cddee76fb63337a6d6cc37d8a0c89027ad75ef176a0d94737ee328197ecf

Contents?: true

Size: 867 Bytes

Versions: 42

Compression:

Stored size: 867 Bytes

Contents

export const buildHostQuery = (selected, search) => {
  const { hosts, hostCollections, hostGroups } = selected;
  const hostsSearch = `id ^ (${hosts.map(({ id }) => id).join(',')})`;
  const hostCollectionsSearch = `host_collection_id ^ (${hostCollections
    .map(({ id }) => id)
    .join(',')})`;
  const hostGroupsSearch = `hostgroup_id ^ (${hostGroups
    .map(({ id }) => id)
    .join(',')})`;
  const queryParts = [
    hosts.length ? hostsSearch : false,
    hostCollections.length ? hostCollectionsSearch : false,
    hostGroups.length ? hostGroupsSearch : false,
    search.length ? search : false,
  ].filter(Boolean);

  if (queryParts.length === 0) {
    return 'name=a AND name=b';
  }
  if (queryParts.length === 1) {
    return queryParts[0] || 'name=a AND name=b';
  }
  return queryParts.map(p => `(${p})`).join(' or ') || 'name=a AND name=b';
};

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
foreman_remote_execution-14.1.2 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-14.1.1 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-14.1.0 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-14.0.2 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-14.0.1 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.2.6 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-14.0.0 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.2.5 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.2.4 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.2.3 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.2.2 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-12.0.7 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.2.1 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.2.0 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-10.1.3 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-13.0.0 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-12.0.5 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-12.0.4 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-12.0.1 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-12.0.2 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js