mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Merge pull request #11173 from mabashian/hub-to-controller
Adds support for pre-filling EE add form name, description, and image from query params
This commit is contained in:
@@ -100,10 +100,14 @@ const AuthorizedRoutes = ({ routeConfig }) => {
|
|||||||
|
|
||||||
const ProtectedRoute = ({ children, ...rest }) => {
|
const ProtectedRoute = ({ children, ...rest }) => {
|
||||||
const { authRedirectTo, setAuthRedirectTo } = useSession();
|
const { authRedirectTo, setAuthRedirectTo } = useSession();
|
||||||
const { pathname } = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname);
|
setAuthRedirectTo(
|
||||||
|
authRedirectTo === '/logout'
|
||||||
|
? '/'
|
||||||
|
: `${location.pathname}${location.search}`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isAuthenticated(document.cookie)) {
|
if (isAuthenticated(document.cookie)) {
|
||||||
|
|||||||
@@ -27,6 +27,24 @@ function ExecutionEnvironmentAdd() {
|
|||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
history.push(`/execution_environments`);
|
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 (
|
return (
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card>
|
<Card>
|
||||||
@@ -38,6 +56,7 @@ function ExecutionEnvironmentAdd() {
|
|||||||
submitError={submitError}
|
submitError={submitError}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
me={me || {}}
|
me={me || {}}
|
||||||
|
executionEnvironment={hubParams}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Config>
|
</Config>
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ describe('<ExecutionEnvironmentAdd/>', () => {
|
|||||||
context: { router: { history } },
|
context: { router: { history } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -108,8 +110,6 @@ describe('<ExecutionEnvironmentAdd/>', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('handleCancel should return the user back to the execution environments list', async () => {
|
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');
|
wrapper.find('Button[aria-label="Cancel"]').simulate('click');
|
||||||
expect(history.location.pathname).toEqual('/execution_environments');
|
expect(history.location.pathname).toEqual('/execution_environments');
|
||||||
});
|
});
|
||||||
@@ -131,4 +131,23 @@ describe('<ExecutionEnvironmentAdd/>', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.find('FormSubmitError').length).toBe(1);
|
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(<ExecutionEnvironmentAdd me={mockMe} />, {
|
||||||
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ function ExecutionEnvironmentForm({
|
|||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Formik
|
<Formik
|
||||||
|
enableReinitialize
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
onSubmit={(values) => onSubmit(values)}
|
onSubmit={(values) => onSubmit(values)}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user