Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion webpack/JobWizard/__tests__/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
22 changes: 18 additions & 4 deletions webpack/JobWizard/autofill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
})
),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)' });
}
});

Expand Down
Loading