mirror of
https://github.com/ansible/awx.git
synced 2026-01-25 00:11:23 -03:30
Remove smart inventories from host form inv lookup
This commit is contained in:
parent
cd83030668
commit
8246d4a298
@ -39,6 +39,7 @@ const InventoryLookupField = ({ isDisabled }) => {
|
||||
error={inventoryMeta.error}
|
||||
validate={required(t`Select a value for this field`)}
|
||||
isDisabled={isDisabled}
|
||||
hideSmartInventories
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import { Inventory } from '../../types';
|
||||
import Lookup from './Lookup';
|
||||
import OptionsList from '../OptionsList';
|
||||
import useRequest from '../../util/useRequest';
|
||||
import { getQSConfig, parseQueryString } from '../../util/qs';
|
||||
import { getQSConfig, parseQueryString, mergeParams } from '../../util/qs';
|
||||
import LookupErrorMessage from './shared/LookupErrorMessage';
|
||||
import FieldWithPrompt from '../FieldWithPrompt';
|
||||
|
||||
@ -32,6 +32,7 @@ function InventoryLookup({
|
||||
validate,
|
||||
fieldName,
|
||||
isDisabled,
|
||||
hideSmartInventories,
|
||||
}) {
|
||||
const {
|
||||
result: {
|
||||
@ -47,8 +48,15 @@ function InventoryLookup({
|
||||
} = useRequest(
|
||||
useCallback(async () => {
|
||||
const params = parseQueryString(QS_CONFIG, history.location.search);
|
||||
const inventoryKindParams = hideSmartInventories
|
||||
? { not__kind: 'smart' }
|
||||
: {};
|
||||
const [{ data }, actionsResponse] = await Promise.all([
|
||||
InventoriesAPI.read(params),
|
||||
InventoriesAPI.read(
|
||||
mergeParams(params, {
|
||||
...inventoryKindParams,
|
||||
})
|
||||
),
|
||||
InventoriesAPI.readOptions(),
|
||||
]);
|
||||
|
||||
@ -60,7 +68,12 @@ function InventoryLookup({
|
||||
).map(val => val.slice(0, -8)),
|
||||
searchableKeys: Object.keys(
|
||||
actionsResponse.data.actions?.GET || {}
|
||||
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
|
||||
).filter(key => {
|
||||
if (key === 'kind' && hideSmartInventories) {
|
||||
return false;
|
||||
}
|
||||
return actionsResponse.data.actions?.GET[key].filterable;
|
||||
}),
|
||||
canEdit:
|
||||
Boolean(actionsResponse.data.actions.POST) || isOverrideDisabled,
|
||||
};
|
||||
@ -230,6 +243,7 @@ InventoryLookup.propTypes = {
|
||||
validate: func,
|
||||
fieldName: string,
|
||||
isDisabled: bool,
|
||||
hideSmartInventories: bool,
|
||||
};
|
||||
|
||||
InventoryLookup.defaultProps = {
|
||||
@ -239,6 +253,7 @@ InventoryLookup.defaultProps = {
|
||||
validate: () => {},
|
||||
fieldName: 'inventory',
|
||||
isDisabled: false,
|
||||
hideSmartInventories: false,
|
||||
};
|
||||
|
||||
export default withRouter(InventoryLookup);
|
||||
|
||||
@ -48,6 +48,42 @@ describe('InventoryLookup', () => {
|
||||
});
|
||||
wrapper.update();
|
||||
expect(InventoriesAPI.read).toHaveBeenCalledTimes(1);
|
||||
expect(InventoriesAPI.read).toHaveBeenCalledWith({
|
||||
order_by: 'name',
|
||||
page: 1,
|
||||
page_size: 5,
|
||||
role_level: 'use_role',
|
||||
});
|
||||
expect(wrapper.find('InventoryLookup')).toHaveLength(1);
|
||||
expect(wrapper.find('Lookup').prop('isDisabled')).toBe(false);
|
||||
});
|
||||
|
||||
test('should fetch only regular inventories when hideSmartInventories is true', async () => {
|
||||
InventoriesAPI.readOptions.mockReturnValue({
|
||||
data: {
|
||||
actions: {
|
||||
GET: {},
|
||||
POST: {},
|
||||
},
|
||||
related_search_fields: [],
|
||||
},
|
||||
});
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Formik>
|
||||
<InventoryLookup onChange={() => {}} hideSmartInventories />
|
||||
</Formik>
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
expect(InventoriesAPI.read).toHaveBeenCalledTimes(1);
|
||||
expect(InventoriesAPI.read).toHaveBeenCalledWith({
|
||||
not__kind: 'smart',
|
||||
order_by: 'name',
|
||||
page: 1,
|
||||
page_size: 5,
|
||||
role_level: 'use_role',
|
||||
});
|
||||
expect(wrapper.find('InventoryLookup')).toHaveLength(1);
|
||||
expect(wrapper.find('Lookup').prop('isDisabled')).toBe(false);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user