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-9.1.0 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js
foreman_remote_execution-8.2.1 webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js