Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueprints: Add import Wizard (HMS-3690) #1928

Merged
merged 1 commit into from
May 22, 2024

Conversation

avitova
Copy link
Contributor

@avitova avitova commented Apr 12, 2024

Sooo...I think we are ready for a discussion on what we want to export AND import, since this is ready. :)

@@ -96,15 +102,25 @@ export const ImportBlueprintModal: React.FunctionComponent<
<HelperText>
<HelperTextItem variant={isRejected ? 'error' : 'default'}>
{isRejected
? 'Must be a JSON file no larger than 1 KB'
? 'Must be a JSON file no larger than 6 KB'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case we want to export even the gpg key and overall everything, 1 KB does not seem to be enough.

Copy link
Member

@amirfefer amirfefer Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the first boot script it can be larger, I guess we can increase it a bit more.

@lucasgarfield
Copy link
Collaborator

Should this be working, @avitova? When I tried importing a blueprint, I just got kicked back to the table.

@avitova
Copy link
Contributor Author

avitova commented Apr 16, 2024

@lucasgarfield Yeah, you are right, let me correct this:)

@avitova avitova force-pushed the import-wizard branch 2 times, most recently from 4091f07 to 37a85ab Compare April 16, 2024 11:01
@avitova avitova force-pushed the import-wizard branch 2 times, most recently from 85a5ba7 to 916aaf2 Compare April 17, 2024 10:32
@avitova
Copy link
Contributor Author

avitova commented Apr 17, 2024

Rebase done. I have also incorporated toast notification for when something goes wrong with the import. :) Thoughts? @lucasgarfield @amirfefer

Copy link
Member

@amirfefer amirfefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @avitova, this looks and works great! 👍
I have a suggestion regarding the json parsing

@@ -96,15 +102,25 @@ export const ImportBlueprintModal: React.FunctionComponent<
<HelperText>
<HelperTextItem variant={isRejected ? 'error' : 'default'}>
{isRejected
? 'Must be a JSON file no larger than 1 KB'
? 'Must be a JSON file no larger than 6 KB'
Copy link
Member

@amirfefer amirfefer Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the first boot script it can be larger, I guess we can increase it a bit more.

Comment on lines 23 to 24
const importedBlueprint: BlueprintResponse = JSON.parse(blueprint);
const importBlueprintState = mapRequestToState(importedBlueprint);
Copy link
Member

@amirfefer amirfefer Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to parse the json before the router transition and loading the wizard, but after the user uploads the data in the import modal, this allows us to verify whether it complies with the blueprintResponse first. Then we can propagate the blueprint request object in the router's state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, thank you for this idea. :)

@avitova avitova force-pushed the import-wizard branch 4 times, most recently from e91f59f to 94624c7 Compare April 22, 2024 09:23
@avitova
Copy link
Contributor Author

avitova commented Apr 22, 2024

I addressed your comments @amirfefer :) Ready for re-review.

Copy link
Member

@amirfefer amirfefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @avitova, tested a full export-import scenario, and it works well! 👍
I left a few minor inline comments, mainly for wrong casting.

This feature is guarded by a feature flag, so I'm ok to add unit tests as follow-up. react testing library has upload API for mimicking upload input, like here

Comment on lines 35 to 36
const [importedBlueprint, setImportedBlueprint] = React.useState(
{} as wizardState
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to use as here

Suggested change
const [importedBlueprint, setImportedBlueprint] = React.useState(
{} as wizardState
const [importedBlueprint, setImportedBlueprint] = React.useState<wizardState>()

@@ -49,17 +61,27 @@ export const ImportBlueprintModal: React.FunctionComponent<
setJsonContent(value);
};
const handleDataChange = (_: DropEvent, value: string) => {
setJsonContent(value);
try {
const importedBlueprint = JSON.parse(value) as BlueprintResponse;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Suggested change
const importedBlueprint = JSON.parse(value) as BlueprintResponse;
const importedBlueprint: BlueprintResponse = JSON.parse(value);

: 'Upload a JSON file'}
</HelperTextItem>
</HelperText>
</FormHelperText>
</FormGroup>
<ActionGroup>
<Button type="button">Review and finish</Button>
<Button
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add ouid prop for testing?

);
}
}, [blueprint, dispatch]);
return <CreateImageWizard startStepIndex={1} />;
Copy link
Member

@amirfefer amirfefer May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reason why this fails to build, startStepIndex prop no longer exists, and isn't needed here, the default is 1 anyway.

Copy link
Collaborator

@regexowl regexowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! Added some comments

src/Components/Blueprints/BlueprintCard.tsx Outdated Show resolved Hide resolved
src/Components/Blueprints/ImportBlueprintModal.tsx Outdated Show resolved Hide resolved
ouiaId="import-blueprint-finish"
>
Review and finish
</Button>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried to import a compose request, it didn't work which makes sense. The request is missing values that blueprint needs to have.

But the failure currently crashes the service and leaves the user stuck on the import path which means that even refreshing the page will not help.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this!

@avitova avitova force-pushed the import-wizard branch 5 times, most recently from b6341cf to 998ead3 Compare May 16, 2024 12:09
@avitova
Copy link
Contributor Author

avitova commented May 16, 2024

So I added a test and rebased. The tests mostly cover which files should be accepted and which should not. It is quite plain, but I think that we can go with this for a while.

@regexowl
Copy link
Collaborator

@avitova Looks great! Can you please resolve the conflict and rebase?

@avitova
Copy link
Contributor Author

avitova commented May 22, 2024

@regexowl rebased:)

@regexowl
Copy link
Collaborator

/retest

Copy link
Collaborator

@regexowl regexowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you! Looks and works great 🚀

@regexowl
Copy link
Collaborator

/retest

3 similar comments
@regexowl
Copy link
Collaborator

/retest

@regexowl
Copy link
Collaborator

/retest

@regexowl
Copy link
Collaborator

/retest

@regexowl regexowl merged commit 3018d64 into osbuild:main May 22, 2024
5 checks passed
@avitova
Copy link
Contributor Author

avitova commented May 22, 2024

🥳 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants