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

Tidy up after recent Focused Launch checkout changes #50182

Merged
merged 10 commits into from
Feb 18, 2021

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Feb 17, 2021

Changes proposed in this Pull Request

Following work from #48452:

  • Add more details to some of the Focused Launch logic in the form of inline comments
  • Add missing isInIframe prop for the Step by Step launch context
  • Rename mistyped window.currentSiteId to window._currentSiteId (and fixed related TypeScript type)

Testing instructions

Most changes are just comments.

  • Open apps/editing-toolkit/editing-toolkit-plugin/editor-site-launch/src/attach-launch-sidebar.tsx and verify that the TypeScript error is gone

Related to #48452

@matticbot
Copy link
Contributor

@@ -54,6 +55,7 @@ registerPlugin( 'a8c-editor-site-launch', {
redirectTo: redirectToWpcomPath,
openCheckout,
getCurrentLaunchFlowUrl,
isInIframe: inIframe(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes in 48452 introduced this error (the isInIframe prop is required by LaunchContext but was not provided here), but somehow neither building the site locally, nor the CI checks flagged it.

We should look into having a full automated TypeScript check — pinging @scinos for some guidance (and in case this is related to #49984)

Copy link

@razvanpapadopol razvanpapadopol Feb 17, 2021

Choose a reason for hiding this comment

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

We've set isInIframe to false as default in the commit where we introduced it and the app mounted in attach-launch-sidebar.tsx is not using it so it's not really a bug.

I'm not against adding it to have the context consistent across both apps but maybe we should remove the default to reduce the maintenance effort?

Good to read on the context subject: https://kentcdodds.com/blog/how-to-use-react-context-effectively

Tl;dr:

  • we can do this to avoid TS errors:
    const LaunchContext = React.createContext< LaunchContext | undefined >( undefined );
  • in unit tests, unlike stated in React docs, we should wrap the components with the necessary context and not rely on this default value

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 see why this wasn't a real bug, but it caused a TypeScript error that was never flagged (the only way I came across it was by opening that file in my IDE).

I agree that one way of fixing this is to make the isInIframe prop optional — I will go ahead and apply this change in this PR

Copy link

@razvanpapadopol razvanpapadopol Feb 17, 2021

Choose a reason for hiding this comment

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

I agree that one way of fixing this is to make the isInIframe prop optional — I will go ahead and apply this change in this PR

It's probably not a good idea to do that since we have it's required in Focused Launch 😬
Let's continue to keep the context using the same interface for both apps and set a value to this property even if it's not used at the moment in this variation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok then, I guess we can keep the code in this PR as is.

maybe we should remove the default value of the LaunchContext

This could be an option.

The more pressing issue, for me, is to understand how we can get TypeScript errors like this flagged in our automated build / CI processes

@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 17, 2021
@ciampo ciampo self-assigned this Feb 17, 2021
@ciampo ciampo added [Type] Janitorial Focused Launch Issues and PRs related to Focused Launch labels Feb 17, 2021
@matticbot
Copy link
Contributor

Caution: This PR affects files in the Editing Toolkit Plugin on WordPress.com
Please ensure your changes work on WordPress.com before merging.

D57191-code has been created so you can easily test it on your sandbox. See this FieldGuide page about developing the Editing Toolkit Plugin for more info: PCYsg-ly5-p2

@ciampo ciampo force-pushed the feat/focused-launch-comments branch from 3b45cd1 to 3f6df32 Compare February 17, 2021 14:07
@ciampo ciampo added the Editing Toolkit For issues and PRs that affect the Editing Toolkit plugin label Feb 17, 2021
@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@ciampo ciampo changed the title Feat/focused launch comments Tidy up after recent Focused Launch checkout changes Feb 17, 2021
@ciampo
Copy link
Contributor Author

ciampo commented Feb 18, 2021

@razvanpapadopol is this PR good to go, or do you see any other changes required?

* @param siteSlug The slug (id) of the current site.
* @param isEcommerce True if the eCommerce plan is going to be in the checkout.
* @param onSuccessCallback Called when the checkout opens as a modal and is completed successfully
*/
export const openCheckout = (
siteSlug: string = window?.currentSiteId?.toString() || '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Just verified. window.currentSiteId doesn't exist. window._currentSiteId does. Then we can also fix the typings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleaned up that variable in 4d9ec5f

Copy link
Contributor

Choose a reason for hiding this comment

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

@yansern can you have another look?

Looks good! :)

@ciampo ciampo requested a review from yansern February 18, 2021 09:41
@ciampo
Copy link
Contributor Author

ciampo commented Feb 18, 2021

@yansern can you have another look?

@ciampo ciampo merged commit 3cd8c3b into trunk Feb 18, 2021
@ciampo ciampo deleted the feat/focused-launch-comments branch February 18, 2021 10:15
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 18, 2021
@ciampo ciampo mentioned this pull request Feb 18, 2021
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Editing Toolkit For issues and PRs that affect the Editing Toolkit plugin Focused Launch Issues and PRs related to Focused Launch [Type] Janitorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants