From 8e34898b4eec95a0acc1ba7521394ce21cb07543 Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Wed, 22 Sep 2021 10:41:08 -0400 Subject: [PATCH 1/6] Redirect with query params and update EE form with hub image data --- awx/ui/src/App.js | 8 +++++++- .../ExecutionEnvironmentAdd.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/awx/ui/src/App.js b/awx/ui/src/App.js index 06c7085c12..a1e1dc1dc9 100644 --- a/awx/ui/src/App.js +++ b/awx/ui/src/App.js @@ -100,7 +100,7 @@ const AuthorizedRoutes = ({ routeConfig }) => { const ProtectedRoute = ({ children, ...rest }) => { const { authRedirectTo, setAuthRedirectTo } = useSession(); - const { pathname } = useLocation(); + const location = useLocation(); useEffect(() => { setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname); @@ -116,6 +116,12 @@ const ProtectedRoute = ({ children, ...rest }) => { ); } + setAuthRedirectTo( + authRedirectTo === '/logout' + ? '/' + : `${location.pathname}${location.search}` + ); + return ; }; diff --git a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js index 3486626473..429188fd4f 100644 --- a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js +++ b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js @@ -27,6 +27,21 @@ function ExecutionEnvironmentAdd() { const handleCancel = () => { history.push(`/execution_environments`); }; + + const hubParams = { + image: '', + credential: null // reverse lookup? + }; + history.location.search.replace(/^\?/, '') + .split('&') + .map((s) => s.split('=')) + .forEach(([key, val]) => { + if (!(key in hubParams)) { + return; + } + hubParams[key] = decodeURIComponent(val); + }); + return ( @@ -38,6 +53,7 @@ function ExecutionEnvironmentAdd() { submitError={submitError} onCancel={handleCancel} me={me || {}} + executionEnvironment={hubParams} /> )} From e5578a8ef3bb64021f9d48b5cf995cebdd354353 Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 29 Sep 2021 13:55:30 -0400 Subject: [PATCH 2/6] Fix bad merge conflict resolution --- awx/ui/src/App.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/awx/ui/src/App.js b/awx/ui/src/App.js index a1e1dc1dc9..ab0211bd38 100644 --- a/awx/ui/src/App.js +++ b/awx/ui/src/App.js @@ -103,7 +103,11 @@ const ProtectedRoute = ({ children, ...rest }) => { const location = useLocation(); useEffect(() => { - setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname); + setAuthRedirectTo( + authRedirectTo === '/logout' + ? '/' + : `${location.pathname}${location.search}` + ); }); if (isAuthenticated(document.cookie)) { @@ -116,12 +120,6 @@ const ProtectedRoute = ({ children, ...rest }) => { ); } - setAuthRedirectTo( - authRedirectTo === '/logout' - ? '/' - : `${location.pathname}${location.search}` - ); - return ; }; From ad24fe70179ff810f9daeb45b9841aeaa7d0ed4e Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 29 Sep 2021 13:57:27 -0400 Subject: [PATCH 3/6] Remove cred from potential hub params --- .../ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js index 429188fd4f..2b19f5657f 100644 --- a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js +++ b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js @@ -30,9 +30,10 @@ function ExecutionEnvironmentAdd() { const hubParams = { image: '', - credential: null // reverse lookup? }; - history.location.search.replace(/^\?/, '') + + history.location.search + .replace(/^\?/, '') .split('&') .map((s) => s.split('=')) .forEach(([key, val]) => { From 71c72f74a1e391236a83fda0f41d1052d69d63bf Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 29 Sep 2021 16:45:07 -0400 Subject: [PATCH 4/6] Add support for name and description query params on ee add --- .../ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js index 2b19f5657f..098fb51109 100644 --- a/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js +++ b/awx/ui/src/screens/ExecutionEnvironment/ExecutionEnvironmentAdd/ExecutionEnvironmentAdd.js @@ -29,7 +29,9 @@ function ExecutionEnvironmentAdd() { }; const hubParams = { + description: '', image: '', + name: '', }; history.location.search From d0a13cb12ac2d281a56d2da0d1b8552d2d46e325 Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 29 Sep 2021 16:59:16 -0400 Subject: [PATCH 5/6] Adds test coverage for parsing and prefilling form fields from query params on EE add form --- .../ExecutionEnvironmentAdd.test.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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'); + }); }); From d93a7c29977141e28b217b2093b0f38404a957bb Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Tue, 5 Oct 2021 13:10:33 -0400 Subject: [PATCH 6/6] Reset form values when query params change --- .../ExecutionEnvironment/shared/ExecutionEnvironmentForm.js | 1 + 1 file changed, 1 insertion(+) 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)} >