Skip to content

Commit 96e4057

Browse files
sbernhardcodex
andcommitted
Fixes #39389 - all-host schedule job bulk search
Co-authored-by: OpenAI Codex <codex@openai.com>
1 parent b58f67d commit 96e4057

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

webpack/assets/javascripts/react_app/components/HostsIndex/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ export const ForemanHostsIndexActionsBarContext = forceSingleton(
8080
() => createContext({})
8181
);
8282

83+
export const getScheduleJobSearch = ({
84+
selectedCount,
85+
areAllRowsSelected,
86+
selectedHostsSearch,
87+
}) => {
88+
if (selectedCount === 0) return null;
89+
if (areAllRowsSelected && selectedHostsSearch === '') return 'name ~ *';
90+
return selectedHostsSearch;
91+
};
92+
8393
const HostsIndex = () => {
8494
const [menuOpen, setMenuOpen] = useState(false);
8595
const [allColumns, setAllColumns] = useState(
@@ -188,6 +198,11 @@ const HostsIndex = () => {
188198
selectedResults,
189199
} = selectAllOptions;
190200
const selectAllHostsMode = areAllRowsSelected() && searchQuery === '';
201+
const scheduleJobSearch = getScheduleJobSearch({
202+
selectedCount,
203+
areAllRowsSelected: areAllRowsSelected(),
204+
selectedHostsSearch: selectedCount > 0 ? fetchBulkParams() : null,
205+
});
191206

192207
const selectionToolbar = (
193208
<ToolbarItem key="selectAll">
@@ -448,7 +463,7 @@ const HostsIndex = () => {
448463
<SplitItem>
449464
<Slot
450465
id="_all-hosts-schedule-a-job"
451-
hostSearch={selectedCount ? fetchBulkParams() : null}
466+
hostSearch={scheduleJobSearch}
452467
hostResponse={response}
453468
selectedCount={selectedCount}
454469
/>

webpack/assets/javascripts/react_app/components/HostsIndex/index.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as ReactRedux from 'react-redux';
55
import configureMockStore from 'redux-mock-store';
66
import thunk from 'redux-thunk';
77
import '@testing-library/jest-dom';
8-
import HostsIndex from './index';
8+
import HostsIndex, { getScheduleJobSearch } from './index';
99

1010
const mockStore = configureMockStore([thunk]);
1111

@@ -155,4 +155,34 @@ describe('HostsIndex', () => {
155155
per_page: 20, // From API response, not from params state (which has 10)
156156
});
157157
});
158+
159+
test('returns an explicit all-hosts search for empty select-all queries', () => {
160+
expect(
161+
getScheduleJobSearch({
162+
selectedCount: 100,
163+
areAllRowsSelected: true,
164+
selectedHostsSearch: '',
165+
})
166+
).toBe('name ~ *');
167+
});
168+
169+
test('does not append the all-hosts fallback to a non-empty select-all search', () => {
170+
expect(
171+
getScheduleJobSearch({
172+
selectedCount: 1,
173+
areAllRowsSelected: true,
174+
selectedHostsSearch: 'name = "centos9-katello-devel.example.com"',
175+
})
176+
).toBe('name = "centos9-katello-devel.example.com"');
177+
});
178+
179+
test('does not use the all-hosts fallback when select-all is not active', () => {
180+
expect(
181+
getScheduleJobSearch({
182+
selectedCount: 1,
183+
areAllRowsSelected: false,
184+
selectedHostsSearch: '',
185+
})
186+
).toBe('');
187+
});
158188
});

0 commit comments

Comments
 (0)