diff --git a/awx/ui/src/App.js b/awx/ui/src/App.js index 06c7085c12..ab0211bd38 100644 --- a/awx/ui/src/App.js +++ b/awx/ui/src/App.js @@ -100,10 +100,14 @@ const AuthorizedRoutes = ({ routeConfig }) => { const ProtectedRoute = ({ children, ...rest }) => { const { authRedirectTo, setAuthRedirectTo } = useSession(); - const { pathname } = useLocation(); + const location = useLocation(); useEffect(() => { - setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname); + setAuthRedirectTo( + authRedirectTo === '/logout' + ? '/' + : `${location.pathname}${location.search}` + ); }); if (isAuthenticated(document.cookie)) { diff --git a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js index 3486626473..098fb51109 100644 --- a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js +++ b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js @@ -27,6 +27,24 @@ function ExecutionEnvironmentAdd() { const handleCancel = () => { history.push(`/execution_environments`); }; + + const hubParams = { + description: '', + image: '', + name: '', + }; + + history.location.search + .replace(/^\?/, '') + .split('&') + .map((s) => s.split('=')) + .forEach(([key, val]) => { + if (!(key in hubParams)) { + return; + } + hubParams[key] = decodeURIComponent(val); + }); + return ( @@ -38,6 +56,7 @@ function ExecutionEnvironmentAdd() { submitError={submitError} onCancel={handleCancel} me={me || {}} + executionEnvironment={hubParams} /> )} diff --git a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.test.js b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.test.js index 803750c7ee..22b712e24b 100644 --- a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.test.js +++ b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.test.js @@ -86,6 +86,8 @@ describe('', () => { context: { router: { history } }, }); }); + + await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0); }); afterEach(() => { @@ -108,8 +110,6 @@ describe('', () => { }); test('handleCancel should return the user back to the execution environments list', async () => { - await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0); - wrapper.find('Button[aria-label="Cancel"]').simulate('click'); expect(history.location.pathname).toEqual('/execution_environments'); }); @@ -131,4 +131,23 @@ describe('', () => { wrapper.update(); expect(wrapper.find('FormSubmitError').length).toBe(1); }); + + test('should parse and prefill select form fields from query params', async () => { + history = createMemoryHistory({ + initialEntries: [ + '/execution_environments/add?image=https://myhub.io/repo:2.0', + ], + }); + await act(async () => { + wrapper = mountWithContexts(, { + context: { router: { history } }, + }); + }); + + await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0); + + expect( + wrapper.find('input#execution-environment-image').prop('value') + ).toEqual('https://myhub.io/repo:2.0'); + }); }); diff --git a/awx/ui/src/screens/ExecutionEnvironment/shared/ExecutionEnvironmentForm.js b/awx/ui/src/screens/ExecutionEnvironment/shared/ExecutionEnvironmentForm.js index 15171c0513..bbf7271955 100644 --- a/awx/ui/src/screens/ExecutionEnvironment/shared/ExecutionEnvironmentForm.js +++ b/awx/ui/src/screens/ExecutionEnvironment/shared/ExecutionEnvironmentForm.js @@ -212,6 +212,7 @@ function ExecutionEnvironmentForm({ }; return ( onSubmit(values)} >