mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Adds searchable keys and related keys
This commit is contained in:
parent
7e74f823f4
commit
1dbadca78e
@ -1,4 +1,5 @@
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import {
|
||||
arrayOf,
|
||||
bool,
|
||||
@ -8,7 +9,6 @@ import {
|
||||
string,
|
||||
oneOfType,
|
||||
} from 'prop-types';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import { t } from '@lingui/macro';
|
||||
import { FormGroup } from '@patternfly/react-core';
|
||||
@ -39,13 +39,13 @@ function CredentialLookup({
|
||||
credentialTypeKind,
|
||||
credentialTypeNamespace,
|
||||
value,
|
||||
history,
|
||||
i18n,
|
||||
tooltip,
|
||||
isDisabled,
|
||||
autoPopulate,
|
||||
multiple,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
const autoPopulateLookup = useAutoPopulateLookup(onChange);
|
||||
const {
|
||||
result: { count, credentials, relatedSearchableKeys, searchableKeys },
|
||||
@ -72,22 +72,28 @@ function CredentialLookup({
|
||||
...typeNamespaceParams,
|
||||
})
|
||||
),
|
||||
CredentialsAPI.readOptions,
|
||||
CredentialsAPI.readOptions(),
|
||||
]);
|
||||
|
||||
if (autoPopulate) {
|
||||
autoPopulateLookup(data.results);
|
||||
}
|
||||
|
||||
const searchKeys = Object.keys(
|
||||
actionsResponse.data.actions?.GET || {}
|
||||
).filter(key => actionsResponse.data.actions?.GET[key].filterable);
|
||||
const item = searchKeys.indexOf('type');
|
||||
if (item) {
|
||||
searchKeys[item] = 'credential_type__kind';
|
||||
}
|
||||
|
||||
return {
|
||||
count: data.count,
|
||||
credentials: data.results,
|
||||
relatedSearchableKeys: (
|
||||
actionsResponse?.data?.related_search_fields || []
|
||||
).map(val => val.slice(0, -8)),
|
||||
searchableKeys: Object.keys(
|
||||
actionsResponse.data?.actions?.GET || {}
|
||||
).filter(key => actionsResponse.data?.actions?.GET[key]?.filterable),
|
||||
searchableKeys: searchKeys,
|
||||
};
|
||||
}, [
|
||||
autoPopulate,
|
||||
@ -222,4 +228,4 @@ CredentialLookup.defaultProps = {
|
||||
};
|
||||
|
||||
export { CredentialLookup as _CredentialLookup };
|
||||
export default withI18n()(withRouter(CredentialLookup));
|
||||
export default withI18n()(CredentialLookup);
|
||||
|
||||
@ -26,7 +26,13 @@ function CredentialList({ i18n }) {
|
||||
const location = useLocation();
|
||||
|
||||
const {
|
||||
result: { credentials, credentialCount, actions },
|
||||
result: {
|
||||
credentials,
|
||||
credentialCount,
|
||||
actions,
|
||||
relatedSearchableKeys,
|
||||
searchableKeys,
|
||||
},
|
||||
error: contentError,
|
||||
isLoading,
|
||||
request: fetchCredentials,
|
||||
@ -37,16 +43,29 @@ function CredentialList({ i18n }) {
|
||||
CredentialsAPI.read(params),
|
||||
CredentialsAPI.readOptions(),
|
||||
]);
|
||||
const searchKeys = Object.keys(
|
||||
credActions.data.actions?.GET || {}
|
||||
).filter(key => credActions.data.actions?.GET[key].filterable);
|
||||
const item = searchKeys.indexOf('type');
|
||||
if (item) {
|
||||
searchKeys[item] = 'credential_type__kind';
|
||||
}
|
||||
return {
|
||||
credentials: creds.data.results,
|
||||
credentialCount: creds.data.count,
|
||||
actions: credActions.data.actions,
|
||||
relatedSearchableKeys: (
|
||||
credActions?.data?.related_search_fields || []
|
||||
).map(val => val.slice(0, -8)),
|
||||
searchableKeys: searchKeys,
|
||||
};
|
||||
}, [location]),
|
||||
{
|
||||
credentials: [],
|
||||
credentialCount: 0,
|
||||
actions: {},
|
||||
relatedSearchableKeys: [],
|
||||
searchableKeys: [],
|
||||
}
|
||||
);
|
||||
|
||||
@ -102,6 +121,8 @@ function CredentialList({ i18n }) {
|
||||
itemCount={credentialCount}
|
||||
qsConfig={QS_CONFIG}
|
||||
onRowClick={handleSelect}
|
||||
toolbarSearchableKeys={searchableKeys}
|
||||
toolbarRelatedSearchableKeys={relatedSearchableKeys}
|
||||
toolbarSearchColumns={[
|
||||
{
|
||||
name: i18n._(t`Name`),
|
||||
|
||||
@ -123,7 +123,7 @@ describe('<ContainerGroupEdit/>', () => {
|
||||
});
|
||||
|
||||
test('called InstanceGroupsAPI.readOptions', async () => {
|
||||
expect(InstanceGroupsAPI.readOptions).toHaveBeenCalledTimes(1);
|
||||
expect(InstanceGroupsAPI.readOptions).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('handleCancel returns the user to container group detail', async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user