diff --git a/awx/ui/package.json b/awx/ui/package.json
index 0c117173df..57289b4d94 100644
--- a/awx/ui/package.json
+++ b/awx/ui/package.json
@@ -74,7 +74,7 @@
"prestart-instrumented": "lingui compile",
"pretest": "lingui compile",
"pretest-watch": "lingui compile",
- "start": "GENERATE_SOURCEMAP=false ESLINT_NO_DEV_ERRORS=true PORT=3001 HTTPS=true DANGEROUSLY_DISABLE_HOST_CHECK=true react-scripts start",
+ "start": "GENERATE_SOURCEMAP=false ESLINT_NO_DEV_ERRORS=true PORT=3003 HTTPS=true DANGEROUSLY_DISABLE_HOST_CHECK=true react-scripts start",
"start-instrumented": "ESLINT_NO_DEV_ERRORS=true DEBUG=instrument-cra PORT=3001 HTTPS=true DANGEROUSLY_DISABLE_HOST_CHECK=true react-scripts -r @cypress/instrument-cra start",
"build": "INLINE_RUNTIME_CHUNK=false react-scripts build",
"test": "TZ='UTC' react-scripts test --watchAll=false",
diff --git a/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.js b/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.js
index a79f04405c..35d9ad19ab 100644
--- a/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.js
+++ b/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.js
@@ -153,6 +153,10 @@ function CredentialsStep({
}))}
value={selectedType && selectedType.id}
onChange={(e, id) => {
+ // Reset query params when the category of credentials is changed
+ history.replace({
+ search: '',
+ });
setSelectedType(types.find((o) => o.id === parseInt(id, 10)));
}}
/>
diff --git a/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.test.js b/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.test.js
index 0b403607ff..c29ec246cb 100644
--- a/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.test.js
+++ b/awx/ui/src/components/LaunchPrompt/steps/CredentialsStep.test.js
@@ -4,6 +4,7 @@ import { Formik } from 'formik';
import { CredentialsAPI, CredentialTypesAPI } from 'api';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import CredentialsStep from './CredentialsStep';
+import { createMemoryHistory } from 'history';
jest.mock('../../../api/models/CredentialTypes');
jest.mock('../../../api/models/Credentials');
@@ -164,6 +165,41 @@ describe('CredentialsStep', () => {
});
});
+ test('should reset query params (credential.page) when selected credential type is changed', async () => {
+ let wrapper;
+ const history = createMemoryHistory({
+ initialEntries: ['?credential.page=2'],
+ });
+ await act(async () => {
+ wrapper = mountWithContexts(
+
+
+ ,
+ {
+ context: { router: { history } },
+ }
+ );
+ });
+ wrapper.update();
+
+ expect(CredentialsAPI.read).toHaveBeenCalledWith({
+ credential_type: 1,
+ order_by: 'name',
+ page: 2,
+ page_size: 5,
+ });
+
+ await act(async () => {
+ wrapper.find('AnsibleSelect').invoke('onChange')({}, 3);
+ });
+ expect(CredentialsAPI.read).toHaveBeenCalledWith({
+ credential_type: 3,
+ order_by: 'name',
+ page: 1,
+ page_size: 5,
+ });
+ });
+
test("error should be shown when a credential that prompts for passwords is selected on a step that doesn't allow it", async () => {
let wrapper;
await act(async () => {
diff --git a/awx/ui/src/components/Lookup/MultiCredentialsLookup.js b/awx/ui/src/components/Lookup/MultiCredentialsLookup.js
index 31598e1f5b..ef0f3ef745 100644
--- a/awx/ui/src/components/Lookup/MultiCredentialsLookup.js
+++ b/awx/ui/src/components/Lookup/MultiCredentialsLookup.js
@@ -173,6 +173,10 @@ function MultiCredentialsLookup({
}))}
value={selectedType && selectedType.id}
onChange={(e, id) => {
+ // Reset query params when the category of credentials is changed
+ history.replace({
+ search: '',
+ });
setSelectedType(
credentialTypes.find((o) => o.id === parseInt(id, 10))
);
diff --git a/awx/ui/src/components/Lookup/MultiCredentialsLookup.test.js b/awx/ui/src/components/Lookup/MultiCredentialsLookup.test.js
index 34c066d0fa..a5cb20f3a3 100644
--- a/awx/ui/src/components/Lookup/MultiCredentialsLookup.test.js
+++ b/awx/ui/src/components/Lookup/MultiCredentialsLookup.test.js
@@ -7,6 +7,7 @@ import {
waitForElement,
} from '../../../testUtils/enzymeHelpers';
import MultiCredentialsLookup from './MultiCredentialsLookup';
+import { createMemoryHistory } from 'history';
jest.mock('../../api');
@@ -228,6 +229,53 @@ describe('', () => {
]);
});
+ test('should reset query params (credentials.page) when selected credential type is changed', async () => {
+ const history = createMemoryHistory({
+ initialEntries: ['?credentials.page=2'],
+ });
+ await act(async () => {
+ wrapper = mountWithContexts(
+
+ {}}
+ onError={() => {}}
+ />
+ ,
+ {
+ context: { router: { history } },
+ }
+ );
+ });
+ const searchButton = await waitForElement(
+ wrapper,
+ 'Button[aria-label="Search"]'
+ );
+ await act(async () => {
+ searchButton.invoke('onClick')();
+ });
+ expect(CredentialsAPI.read).toHaveBeenCalledWith({
+ credential_type: 400,
+ order_by: 'name',
+ page: 2,
+ page_size: 5,
+ });
+
+ const select = await waitForElement(wrapper, 'AnsibleSelect');
+ await act(async () => {
+ select.invoke('onChange')({}, 500);
+ });
+ wrapper.update();
+
+ expect(CredentialsAPI.read).toHaveBeenCalledWith({
+ credential_type: 500,
+ order_by: 'name',
+ page: 1,
+ page_size: 5,
+ });
+ });
+
test('should only add 1 credential per credential type except vault(see below)', async () => {
const onChange = jest.fn();
await act(async () => {