Skip to content

Commit e27225a

Browse files
nofaralfasijeremylenz
authored andcommitted
Fixes #38760 - Add loading skeleton to Change host group modal
The BulkReassignHostgroupModal now displays a skeleton loader while fetching hostgroup data, improving user experience by providing visual feedback during the loading state. The Save button is also disabled while data is loading to prevent premature submission.
1 parent 29bdc27 commit e27225a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/reassignHostGroup/BulkReassignHostgroupModal.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import { foremanUrl } from '../../../../common/helpers';
2727
import { APIActions } from '../../../../redux/API';
2828
import HostGroupSelect from './HostGroupSelect';
29+
import SkeletonLoader from '../../../common/SkeletonLoader';
2930
import {
3031
HOSTS_API_PATH,
3132
API_REQUEST_KEY,
@@ -197,7 +198,10 @@ const BulkReassignHostgroupModal = ({
197198
ouiaId="bulk-reassign-hg-modal-add-button"
198199
variant="primary"
199200
onClick={handleSave}
200-
isDisabled={hostUpdateStatus === STATUS.PENDING}
201+
isDisabled={
202+
hostUpdateStatus === STATUS.PENDING ||
203+
hostgroupStatus !== STATUS.RESOLVED
204+
}
201205
isLoading={hostUpdateStatus === STATUS.PENDING}
202206
>
203207
{__('Save')}
@@ -249,7 +253,7 @@ const BulkReassignHostgroupModal = ({
249253
/>
250254
</Text>
251255
</TextContent>
252-
{hostgroups && hostgroupStatus === STATUS.RESOLVED && (
256+
<SkeletonLoader status={hostgroupStatus} skeletonProps={{ count: 3 }}>
253257
<HostGroupSelect
254258
onClear={handleClear}
255259
headerText={__('Select host group')}
@@ -270,7 +274,7 @@ const BulkReassignHostgroupModal = ({
270274
);
271275
})}
272276
</HostGroupSelect>
273-
)}
277+
</SkeletonLoader>
274278
<hr />
275279
</Modal>
276280
);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import HostsIndex from './index';
99

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

12-
// Mock useSelector and useDispatch
13-
jest.spyOn(ReactRedux, 'useSelector').mockImplementation(() => []);
12+
// Mock useDispatch
1413
jest.spyOn(ReactRedux, 'useDispatch').mockImplementation(() => jest.fn());
1514

1615
// Mock the API hook to return a controlled response
@@ -128,6 +127,10 @@ jest.mock('../PF4/TableIndexPage/TableIndexPage', () => ({
128127
describe('HostsIndex', () => {
129128
const store = mockStore({
130129
foremanModals: {},
130+
API: {
131+
HOSTGROUP_KEY: { status: 'RESOLVED', response: { results: [] } },
132+
BULK_REASSIGN_HOSTGROUP_KEY: { status: undefined },
133+
},
131134
});
132135

133136
beforeEach(() => {

0 commit comments

Comments
 (0)