diff --git a/awx/ui_next/src/components/Lookup/CredentialLookup.jsx b/awx/ui_next/src/components/Lookup/CredentialLookup.jsx index 2b398abcbe..df9964440b 100644 --- a/awx/ui_next/src/components/Lookup/CredentialLookup.jsx +++ b/awx/ui_next/src/components/Lookup/CredentialLookup.jsx @@ -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); diff --git a/awx/ui_next/src/screens/Credential/CredentialList/CredentialList.jsx b/awx/ui_next/src/screens/Credential/CredentialList/CredentialList.jsx index 26272ee4ad..e4a10ed86c 100644 --- a/awx/ui_next/src/screens/Credential/CredentialList/CredentialList.jsx +++ b/awx/ui_next/src/screens/Credential/CredentialList/CredentialList.jsx @@ -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`), diff --git a/awx/ui_next/src/screens/InstanceGroup/ContainerGroupEdit/ContainerGroupEdit.test.jsx b/awx/ui_next/src/screens/InstanceGroup/ContainerGroupEdit/ContainerGroupEdit.test.jsx index d63996dde8..937aa15adb 100644 --- a/awx/ui_next/src/screens/InstanceGroup/ContainerGroupEdit/ContainerGroupEdit.test.jsx +++ b/awx/ui_next/src/screens/InstanceGroup/ContainerGroupEdit/ContainerGroupEdit.test.jsx @@ -123,7 +123,7 @@ describe('', () => { }); test('called InstanceGroupsAPI.readOptions', async () => { - expect(InstanceGroupsAPI.readOptions).toHaveBeenCalledTimes(1); + expect(InstanceGroupsAPI.readOptions).toHaveBeenCalled(); }); test('handleCancel returns the user to container group detail', async () => {