mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Fix TypeError when running a command on a host in a smart inventory (#11768)
Fix TypeError when running a command on a host in a smart inventory See: https://github.com/ansible/awx/issues/11611
This commit is contained in:
parent
7cf0523561
commit
eb859b9812
@ -59,6 +59,7 @@ function AdHocCommands({
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [fetchData]);
|
||||
|
||||
const {
|
||||
isLoading: isLaunchLoading,
|
||||
error: launchError,
|
||||
@ -172,6 +173,8 @@ function AdHocCommands({
|
||||
AdHocCommands.propTypes = {
|
||||
adHocItems: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
hasListItems: PropTypes.bool.isRequired,
|
||||
onLaunchLoading: PropTypes.func.isRequired,
|
||||
moduleOptions: PropTypes.arrayOf(PropTypes.array).isRequired,
|
||||
};
|
||||
|
||||
export default AdHocCommands;
|
||||
|
||||
@ -73,6 +73,10 @@ describe('<AdHocCommands />', () => {
|
||||
adHocItems={adHocItems}
|
||||
hasListItems
|
||||
onLaunchLoading={() => jest.fn()}
|
||||
moduleOptions={[
|
||||
['command', 'command'],
|
||||
['shell', 'shell'],
|
||||
]}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
@ -25,25 +25,33 @@ function SmartInventoryHostList({ inventory }) {
|
||||
const location = useLocation();
|
||||
const [isAdHocLaunchLoading, setIsAdHocLaunchLoading] = useState(false);
|
||||
const {
|
||||
result: { hosts, count },
|
||||
result: { hosts, count, moduleOptions },
|
||||
error: contentError,
|
||||
isLoading,
|
||||
request: fetchHosts,
|
||||
} = useRequest(
|
||||
useCallback(async () => {
|
||||
const params = parseQueryString(QS_CONFIG, location.search);
|
||||
const {
|
||||
data: { results, count: hostCount },
|
||||
} = await InventoriesAPI.readHosts(inventory.id, params);
|
||||
const [
|
||||
{
|
||||
data: { results, count: hostCount },
|
||||
},
|
||||
adHocOptions,
|
||||
] = await Promise.all([
|
||||
InventoriesAPI.readHosts(inventory.id, params),
|
||||
InventoriesAPI.readAdHocOptions(inventory.id),
|
||||
]);
|
||||
|
||||
return {
|
||||
hosts: results,
|
||||
count: hostCount,
|
||||
moduleOptions: adHocOptions.data.actions.GET.module_name.choices,
|
||||
};
|
||||
}, [location.search, inventory.id]),
|
||||
{
|
||||
hosts: [],
|
||||
count: 0,
|
||||
moduleOptions: [],
|
||||
}
|
||||
);
|
||||
|
||||
@ -91,6 +99,7 @@ function SmartInventoryHostList({ inventory }) {
|
||||
adHocItems={selected}
|
||||
hasListItems={count > 0}
|
||||
onLaunchLoading={setIsAdHocLaunchLoading}
|
||||
moduleOptions={moduleOptions}
|
||||
/>,
|
||||
]
|
||||
: []
|
||||
|
||||
@ -27,6 +27,21 @@ describe('<SmartInventoryHostList />', () => {
|
||||
InventoriesAPI.readHosts.mockResolvedValue({
|
||||
data: mockHosts,
|
||||
});
|
||||
InventoriesAPI.readAdHocOptions.mockResolvedValue({
|
||||
data: {
|
||||
actions: {
|
||||
GET: {
|
||||
module_name: {
|
||||
choices: [
|
||||
['command', 'command'],
|
||||
['shell', 'shell'],
|
||||
],
|
||||
},
|
||||
},
|
||||
POST: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<SmartInventoryHostList inventory={clonedInventory} />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user