From 7bd74a0477f52b1a01c8b4f44a50c40494721dd5 Mon Sep 17 00:00:00 2001 From: snarya07 Date: Tue, 15 Sep 2026 06:53:55 -0400 Subject: [PATCH] Fixes #39630 - REX Job Wizard host autofill when display_fqdn_for_hosts settings is disabled --- .../JobWizard/__tests__/integration.test.js | 2 +- webpack/JobWizard/autofill.js | 22 +++++++++++++++---- .../__tests__/HostsAndInputs.test.js | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/webpack/JobWizard/__tests__/integration.test.js b/webpack/JobWizard/__tests__/integration.test.js index a02911263..91082ad01 100644 --- a/webpack/JobWizard/__tests__/integration.test.js +++ b/webpack/JobWizard/__tests__/integration.test.js @@ -105,7 +105,7 @@ describe('Job wizard fill', () => { }); expectDispatchedGet({ key: 'HOST_IDS', - params: { search: 'id = 105 or id = 37' }, + params: { search: 'id ^ (105,37)' }, url: '/api/hosts', }); expectDispatchedGet({ diff --git a/webpack/JobWizard/autofill.js b/webpack/JobWizard/autofill.js index ee838ea4a..06e1bf378 100644 --- a/webpack/JobWizard/autofill.js +++ b/webpack/JobWizard/autofill.js @@ -11,6 +11,21 @@ import { import { selectHostBookmarks } from './JobWizardSelectors'; import './JobWizard.scss'; +export const buildHostSearchFromIds = hostIds => { + const ids = Array.isArray(hostIds) ? hostIds : [hostIds]; + const isNumericId = id => /^\d+$/.test(String(id)); + const numericIds = ids.filter(isNumericId); + const hostnames = ids.filter(id => !isNumericId(id)); + const parts = []; + if (numericIds.length) { + parts.push(`id ^ (${numericIds.join(',')})`); + } + if (hostnames.length) { + parts.push(`name ^ (${hostnames.join(', ')})`); + } + return parts.join(' or '); +}; + export const useAutoFill = ({ fills, setFills, @@ -52,9 +67,7 @@ export const useAutoFill = ({ setFills({}); if (hostIds) { setSelectedBookmark(null); - const hostSearch = Array.isArray(hostIds) - ? `id = ${hostIds.join(' or id = ')}` - : `id = ${hostIds}`; + const hostSearch = buildHostSearchFromIds(hostIds); dispatch( get({ key: HOST_IDS, @@ -69,8 +82,9 @@ export const useAutoFill = ({ // eslint-disable-next-line camelcase ({ id, name, display_name }) => ({ id, + name, // eslint-disable-next-line camelcase - name: display_name || name, + display_name: display_name || name, }) ), })); diff --git a/webpack/JobWizard/steps/HostsAndInputs/__tests__/HostsAndInputs.test.js b/webpack/JobWizard/steps/HostsAndInputs/__tests__/HostsAndInputs.test.js index 81638fa0d..5e97f6cd3 100644 --- a/webpack/JobWizard/steps/HostsAndInputs/__tests__/HostsAndInputs.test.js +++ b/webpack/JobWizard/steps/HostsAndInputs/__tests__/HostsAndInputs.test.js @@ -163,7 +163,7 @@ describe('Hosts', () => { }); api.get.mock.calls.forEach(call => { if (call[0].key === 'HOST_IDS') { - expect(call[0].params).toEqual({ search: 'id = host1 or id = host3' }); + expect(call[0].params).toEqual({ search: 'name ^ (host1, host3)' }); } });