From 0a0c635de842793dfc2d92aee38e22149274abdc Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 6 Jul 2021 16:34:47 -0400 Subject: [PATCH] fixes missing key values in ad hoc credental step advanced search --- .../AdHocCommands/AdHocCommands.test.jsx | 8 ++++ .../AdHocCommandsWizard.test.jsx | 6 +++ .../AdHocCommands/AdHocCredentialStep.jsx | 38 +++++++++++++++---- .../AdHocCredentialStep.test.jsx | 3 ++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/awx/ui_next/src/components/AdHocCommands/AdHocCommands.test.jsx b/awx/ui_next/src/components/AdHocCommands/AdHocCommands.test.jsx index 417e2a08d7..862f04662c 100644 --- a/awx/ui_next/src/components/AdHocCommands/AdHocCommands.test.jsx +++ b/awx/ui_next/src/components/AdHocCommands/AdHocCommands.test.jsx @@ -153,6 +153,10 @@ describe('', () => { count: 5, }, }); + CredentialsAPI.readOptions.mockResolvedValue({ + data: { actions: { GET: {} } }, + }); + ExecutionEnvironmentsAPI.read.mockResolvedValue({ data: { results: [ @@ -310,6 +314,10 @@ describe('', () => { count: 5, }, }); + CredentialsAPI.readOptions.mockResolvedValue({ + data: { actions: { GET: {} } }, + }); + ExecutionEnvironmentsAPI.read.mockResolvedValue({ data: { results: [ diff --git a/awx/ui_next/src/components/AdHocCommands/AdHocCommandsWizard.test.jsx b/awx/ui_next/src/components/AdHocCommands/AdHocCommandsWizard.test.jsx index 1393a94ebf..a0166f4492 100644 --- a/awx/ui_next/src/components/AdHocCommands/AdHocCommandsWizard.test.jsx +++ b/awx/ui_next/src/components/AdHocCommands/AdHocCommandsWizard.test.jsx @@ -127,6 +127,9 @@ describe('', () => { count: 2, }, }); + CredentialsAPI.readOptions.mockResolvedValue({ + data: { actions: { GET: {} } }, + }); await waitForElement(wrapper, 'WizardNavItem', el => el.length > 0); await act(async () => { @@ -246,6 +249,9 @@ describe('', () => { }, }) ); + CredentialsAPI.readOptions.mockResolvedValue({ + data: { actions: { GET: {} } }, + }); await waitForElement(wrapper, 'WizardNavItem', el => el.length > 0); await act(async () => { diff --git a/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx b/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx index 29ae4e6827..0246bf444d 100644 --- a/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx +++ b/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx @@ -27,23 +27,45 @@ function AdHocCredentialStep({ credentialTypeId, onEnableLaunch }) { error, isLoading, request: fetchCredentials, - result: { credentials, credentialCount }, + result: { + credentials, + credentialCount, + relatedSearchableKeys, + searchableKeys, + }, } = useRequest( useCallback(async () => { const params = parseQueryString(QS_CONFIG, history.location.search); - const { - data: { results, count }, - } = await CredentialsAPI.read( - mergeParams(params, { credential_type: credentialTypeId }) - ); + const [ + { + data: { results, count }, + }, + actionsResponse, + ] = await Promise.all([ + CredentialsAPI.read( + mergeParams(params, { credential_type: credentialTypeId }) + ), + CredentialsAPI.readOptions(), + ]); return { credentials: results, credentialCount: count, + 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), }; }, [credentialTypeId, history.location.search]), - { credentials: [], credentialCount: 0 } + { + credentials: [], + credentialCount: 0, + relatedSearchableKeys: [], + searchableKeys: [], + } ); useEffect(() => { @@ -84,6 +106,8 @@ function AdHocCredentialStep({ credentialTypeId, onEnableLaunch }) { header={t`Machine Credential`} readOnly qsConfig={QS_CONFIG} + relatedSearchableKeys={relatedSearchableKeys} + searchableKeys={searchableKeys} searchColumns={[ { name: t`Name`, diff --git a/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.test.jsx b/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.test.jsx index 873b792278..a00bbf29cc 100644 --- a/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.test.jsx +++ b/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.test.jsx @@ -23,6 +23,9 @@ describe('', () => { count: 2, }, }); + CredentialsAPI.readOptions.mockResolvedValue({ + data: { actions: { GET: {} } }, + }); await act(async () => { wrapper = mountWithContexts(