Wizard: Add ability to specify AWS target using sources

This commit adds the ability to specify AWS targets using the sources
service on insights.

This is the first commit to the codebase that makes use of the new RTK
Query endpoints, so I will provide a bit of additional context here:

The sources are obtained by calling the `useGetAWSSourcesQuery()` hook.
This hook can be called in any component where information about the
sources is needed.

A few tricks are used to make the user experience as responsive as
possible.

The `prefetch()` hook provided by RTK Query is called when the user
clicks on the AWS button on the image output step. This triggers the
initial request for the sources, which will then (hopefully) be ready by the
time the user clicks to the next step (the AWS target environment step)
where they are needed.

Because we anticipate a common user workflow to involve using the Create
image wizard in one browser tab and the sources service in another tab,
sources are also refetched every time the source dropdown is opened.
This means that if a user adds a source while in the middle of using the
wizard, they will be able to see it in the wizard's sources dropdown
without refreshing their browser.

Finally, because of the `Recreate image` feature, the
`useGetAWSSourcesQuery` hook also needs to be called on the review step.
This commit is contained in:
lucasgarfield 2023-02-27 14:37:02 +01:00 committed by Sanne Raymaekers
parent 7768c44630
commit a474163343
9 changed files with 375 additions and 29 deletions

View file

@ -79,6 +79,10 @@ const onSave = (values) => {
const requests = [];
if (values['target-environment']?.aws) {
const options =
values['aws-target-type'] === 'aws-target-type-source'
? { share_with_sources: [values['aws-sources-select']] }
: { share_with_accounts: [values['aws-account-id']] };
const request = {
distribution: values.release,
image_name: values?.['image-name'],
@ -88,9 +92,7 @@ const onSave = (values) => {
image_type: 'aws',
upload_request: {
type: 'aws',
options: {
share_with_accounts: [values['aws-account-id']],
},
options: options,
},
},
],
@ -297,8 +299,19 @@ const requestToState = (composeRequest) => {
formState['target-environment'][targetEnvironment] = true;
if (targetEnvironment === 'aws') {
formState['aws-account-id'] =
uploadRequest?.options?.share_with_accounts[0];
const shareWithSource = uploadRequest?.options?.share_with_sources?.[0];
const shareWithAccount = uploadRequest?.options?.share_with_accounts?.[0];
formState['aws-sources-select'] = shareWithSource;
formState['aws-account-id'] = shareWithAccount;
if (shareWithAccount && !shareWithSource) {
formState['aws-target-type'] = 'aws-target-type-account-id';
} else {
// if both shareWithAccount & shareWithSource are present, set radio
// to sources - this is essentially an arbitrary decision
// additionally, note that the source is not validated against the actual
// sources
formState['aws-target-type'] = 'aws-target-type-source';
}
} else if (targetEnvironment === 'azure') {
formState['azure-tenant-id'] = uploadRequest?.options?.tenant_id;
formState['azure-subscription-id'] =