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

#4550 validate blueprint options on activation #4602

Merged
merged 17 commits into from
Nov 9, 2022

Conversation

mnholtz
Copy link
Collaborator

@mnholtz mnholtz commented Nov 4, 2022

What does this PR do?

Reviewer Tips

  • Main functional change was adding a validationSchema return value on the useWizard hook, and then passing that schema to the Formik form in ActivateWizard

Discussion

  • I'm not certain if the function "getValidationSchemaFromOptionSchema" has been written elsewhere in the code. I couldn't easily find any references to such logic. In any case, a lot of the type validation is enforced by the SchemaField UI anyways, so the actual Yup validation from the optionSchema seems to be more of a "nice to have"

Demo

https://loom.com/share/96d87c67cdbd4014bfb4167bff6dc4f8

Future Work

  • I wrote a comment for this, but validating Integrations in the validationSchema would be nice to have. Working on tests took longer than anticipated so I'm leaving this for future work.

Checklist

  • Add tests
  • Run Storybook and manually confirm that all stories are working
  • Designate a primary reviewer - either @BLoe or @BALEHOK as time permits

@mnholtz mnholtz changed the title Feature/4550 validate blueprint options on activation #4550 validate blueprint options on activation Nov 4, 2022
: ({ children }) => (
<MemoryRouter>
<Provider store={store}>{children}</Provider>
</MemoryRouter>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't see a problem with adding this to the wrappers. I'm often having to add this when writing tests and I don't think most of our components would be rendered out of a react router context anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

The extension works without Router, ideally we shouldn't add MemoryRouter to all the tests.
I suggest either

  • Add a config parameter to the createRenderWithWrappers. We create a concrete version of the renderWithWrappers for each app (PageEditor, Options, and App). Let an app decide if it needs MemoryRouter (or any other wrapper) and add it only for that app.
    or
  • Add MemoryRouter to the other case a few lines above when we generate <Formik> context. At least this will be more consistent.

@codecov
Copy link

codecov bot commented Nov 5, 2022

Codecov Report

Merging #4602 (e210366) into main (e68c2e3) will increase coverage by 0.79%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #4602      +/-   ##
==========================================
+ Coverage   51.39%   52.19%   +0.79%     
==========================================
  Files         915      915              
  Lines       27121    27206      +85     
  Branches     5515     5518       +3     
==========================================
+ Hits        13938    14199     +261     
+ Misses      12249    12087     -162     
+ Partials      934      920      -14     
Impacted Files Coverage Δ
src/options/pages/marketplace/ActivateWizard.tsx 96.96% <100.00%> (+96.96%) ⬆️
src/options/pages/marketplace/useWizard.ts 94.44% <100.00%> (+1.76%) ⬆️
...omponents/fields/schemaFields/getToggleOptions.tsx 87.07% <0.00%> (+1.36%) ⬆️
src/utils.ts 64.86% <0.00%> (+1.93%) ⬆️
src/registry/internal.ts 24.17% <0.00%> (+4.39%) ⬆️
src/options/pages/marketplace/ExtensionsBody.tsx 100.00% <0.00%> (+12.50%) ⬆️
...options/pages/blueprints/utils/installableUtils.ts 72.26% <0.00%> (+15.12%) ⬆️
src/hooks/useAuthorizationGrantFlow.ts 19.04% <0.00%> (+19.04%) ⬆️
...tions/pages/blueprints/useInstallableViewItems.tsx 76.74% <0.00%> (+20.93%) ⬆️
src/components/ServiceAuthSelector.tsx 26.47% <0.00%> (+26.47%) ⬆️
... and 13 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@twschiller twschiller added this to the 1.7.13 milestone Nov 5, 2022
src/options/pages/marketplace/ActivateWizard.test.tsx Outdated Show resolved Hide resolved
: ({ children }) => (
<MemoryRouter>
<Provider store={store}>{children}</Provider>
</MemoryRouter>
Copy link
Contributor

Choose a reason for hiding this comment

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

The extension works without Router, ideally we shouldn't add MemoryRouter to all the tests.
I suggest either

  • Add a config parameter to the createRenderWithWrappers. We create a concrete version of the renderWithWrappers for each app (PageEditor, Options, and App). Let an app decide if it needs MemoryRouter (or any other wrapper) and add it only for that app.
    or
  • Add MemoryRouter to the other case a few lines above when we generate <Formik> context. At least this will be more consistent.

/>
);
await waitForEffect();
expect(rendered.asFragment()).toMatchSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this snapshot is not needed since the happy path is covered by the first test, isn't it?

src/options/pages/marketplace/useWizard.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@BLoe BLoe left a comment

Choose a reason for hiding this comment

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

I agree with Aleksandr that we should probably follow the pattern in ServiceEditorModal and use buildYup from the library to do the schema conversion. Otherwise, good start here! Having tests already will be helpful when you refactor.

@@ -93,7 +133,42 @@ function useWizard(blueprint: RecipeDefinition): [WizardStep[], WizardValues] {
grantPermissions: false,
};

return [steps, initialValues];
const validationSchema = Yup.object().shape({
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be easier/simpler to write this all as json-schema and then convert it to yup in one pass, instead of going back and forth between json-schema and yup to append the options part and stuff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you have an example of where we do this elsewhere? I'm not convinced that would be any less complex 🤔

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

When the PR is merged, the first loom link found on this PR will be posted to #sprint-demo on Slack. Do not edit this comment manually.

@mnholtz mnholtz merged commit 9e1ee02 into main Nov 9, 2022
@mnholtz mnholtz deleted the feature/4550_validate_blueprint_options_on_activation branch November 9, 2022 20:32
@twschiller twschiller modified the milestones: 1.7.13, 1.7.12 Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blueprint Activation screen not validating user-provided blueprint options
4 participants