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

Refactor the bundle installation to be generic #84886

Merged
merged 48 commits into from
Dec 21, 2023

Conversation

renatho
Copy link
Contributor

@renatho renatho commented Dec 5, 2023

Related to Automattic/themes#7498

First part of this refactor: #84483

Proposed Changes

Testing Instructions

The following tests are just to make sure everything continues working as previously. Nothing should change and anything new was introduced. Also, please test other different scenarios that you can think of.

Flow starting with free plan and selecting a WooCommerce theme

  1. Navigate to http://calypso.localhost:3000/start.
  2. Select the free plan.
  3. On the "Pick a design" step, go to the "store" tab, and select the "Tsubaki" theme (WooCommerce theme).
  4. Continue through the flow, upgrading the plan to be able to install the theme.
  5. Make sure everything works in the same way as previously (a good way I used to compare was to navigate in wordpress.com in parallel), and when you complete all the steps you are redirected to the WooCommerce home with WC installed.

Flow starting with business plan and selecting a WooCommerce theme

  1. Navigate to http://calypso.localhost:3000/start.
  2. Select the business plan.
  3. On the "Pick a design" step, go to the "store" tab, and select the "Tsubaki" theme (WooCommerce theme).
  4. Continue through the flow.
  5. Make sure everything works in the same way as previously (a good way I used to compare was to navigate in wordpress.com in parallel), and when you complete all the steps you are redirected to the WooCommerce home with WC installed.

Flow starting with free plan and free theme changing to WooCommerce theme later

  1. Navigate to http://calypso.localhost:3000/start.
  2. Select the free plan.
  3. On the "Pick a design" step, select the Twenty Twenty-Four theme.
  4. Continue through the flow until redirected to the site.
  5. On the site, navigate to Appearance > Themes.
  6. Select the "Tsubaki" theme.
  7. Upgrade, and continue through the flow.
  8. Make sure everything works in the same way as previously (a good way I used to compare was to navigate in wordpress.com in parallel), and when you complete all the steps you are redirected to the WooCommerce home with WC installed.

Flow starting with business plan and free theme, and changing to WooCommerce theme later

  1. Navigate to http://calypso.localhost:3000/start.
  2. Select the business plan.
  3. On the "Pick a design" step, select the Twenty Twenty-Four theme.
  4. Continue through the flow.
  5. Make sure everything works in the same way as previously (a good way I used to compare was to navigate in wordpress.com in parallel). Notice that in this case, WooCommerce wasn't installed. Not sure if it's the ideal behavior, but it keeps the current behavior. If confirmed that it's not an intentional behavior, I can open an issue for that.

Known issues

  • When I started developing this PR, I noticed an intermittent error (also reproduced on trunk and staging). When I completed the flow with a WooCommerce bundle (woo-on-plans), the "Customize this design" button in http://calypso.localhost:3000/marketplace/thank-you/{DOMAIN} was always a link to the site editor. But sometimes when clicked, it was redirecting to WooCommerce home (/wp-admin/admin.php?page=wc-admin), and others it was just navigating to the site editor without the redirect. I didn't find where this redirect logic lives (I suspect it's not in Calypso), and I couldn't reproduce it anymore, so I'm ignoring it. If you are testing it, and see the same behavior, I can open an issue for that.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • https://wpcalypso.wordpress.com/devdocs/docs/testing/index.md for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-ajp-p2)?

@renatho renatho self-assigned this Dec 5, 2023
Copy link

github-actions bot commented Dec 5, 2023

@matticbot
Copy link
Contributor

matticbot commented Dec 5, 2023

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~195 bytes removed 📉 [gzipped])

name                   parsed_size           gzip_size
entry-stepper               -986 B  (-0.1%)     -194 B  (-0.0%)
entry-subscriptions         -710 B  (-0.0%)     -106 B  (-0.0%)
entry-main                  -710 B  (-0.0%)     -107 B  (-0.0%)
entry-login                 -710 B  (-0.0%)     -107 B  (-0.0%)
entry-domains-landing       -710 B  (-0.1%)     -106 B  (-0.1%)
entry-browsehappy           -710 B  (-0.5%)     -106 B  (-0.3%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~8246 bytes added 📈 [gzipped])

name                       parsed_size           gzip_size
plugin-bundle-flow             +7534 B  (+4.0%)    +3369 B  (+5.3%)
site-setup-flow                -1440 B  (-1.9%)     -830 B  (-5.2%)
with-theme-assembler-flow       -437 B  (-0.6%)       +0 B
update-options-flow             -437 B  (-1.1%)       +7 B  (+0.1%)
update-design-flow              -437 B  (-0.0%)       +4 B  (+0.0%)
free-post-setup-flow            -437 B  (-1.1%)       +4 B  (+0.1%)
free-flow                       -437 B  (-0.9%)       +3 B  (+0.0%)
assembler-first-flow            -437 B  (-0.6%)       -6 B  (-0.0%)
ai-assembler-flow               -437 B  (-0.6%)       -8 B  (-0.0%)
subscribers                     -188 B  (-0.0%)      -55 B  (-0.0%)
sites-dashboard                 -188 B  (-0.0%)      -55 B  (-0.0%)
settings                        -188 B  (-0.0%)      -55 B  (-0.0%)
hosting                         -188 B  (-0.0%)      -55 B  (-0.0%)
home                            -188 B  (-0.0%)      -56 B  (-0.0%)
theme                           +128 B  (+0.0%)      +45 B  (+0.0%)
themes                           +20 B  (+0.0%)      +13 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~81 bytes removed 📉 [gzipped])

name                                                 parsed_size           gzip_size
async-load-design                                         -188 B  (-0.0%)      -55 B  (-0.0%)
async-load-signup-steps-woocommerce-install-confirm        +46 B  (+0.1%)      -26 B  (-0.2%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@renatho renatho force-pushed the change/make-bundle-installation-generic branch from 6755a5c to ed39003 Compare December 5, 2023 22:05
@matticbot
Copy link
Contributor

matticbot commented Dec 5, 2023

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • blaze-dashboard
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug change/make-bundle-installation-generic on your sandbox.

@renatho renatho force-pushed the change/make-bundle-installation-generic branch 3 times, most recently from daad2b8 to 0a4f76f Compare December 6, 2023 21:10
const { submit } = navigation;
const { setPendingAction, setProgressTitle, setProgress } = useDispatch( ONBOARD_STORE );
const { initiateSoftwareInstall, requestAtomicSoftwareStatus } = useDispatch( SITE_STORE );
const { getAtomicSoftwareInstallError, getAtomicSoftwareStatus, getAtomicSoftwareError } =
useSelect( ( select ) => select( SITE_STORE ) as SiteSelect, [] );
const site = useSite();
const softwareSet = 'woo-on-plans';
const softwareSet = useSitePluginSlug();
Copy link
Contributor Author

@renatho renatho Dec 6, 2023

Choose a reason for hiding this comment

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

In some cases, you will see softwareSet vs pluginSlug.
They are the same thing. They just have different names because in different places they were called differently, and making everything generic, they are getting mixed in some parts.
I didn't want to rename all functions and variables to not make it even bigger, but it's something that could be done in the future.

@renatho renatho force-pushed the change/make-bundle-installation-generic branch 4 times, most recently from c6fd676 to 1b8a773 Compare December 8, 2023 19:02

export default pluginBundleSteps;
export type BundledPlugin = keyof typeof bundleStepsSettings & string;
Copy link
Contributor Author

@renatho renatho Dec 8, 2023

Choose a reason for hiding this comment

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

I don't have much experience with TypeScript, so I'd appreciate help here if any reviewer has a suggestion.
BundledPlugin type is currently accepting any string.

If I remove the type BundleStepsSettings from the bundleStepsSettings it works properly, accepting only "woo-on-plans". The same happens with the previous version of this object (trunk).

Any idea on how to solve it? The best resource I could find about this is https://stackoverflow.com/questions/51808160/keyof-inferring-string-number-when-key-is-only-a-string

const stepNavigation = flow.useStepNavigation(
currentStepRoute,
_navigate,
flowSteps.map( ( step ) => step.slug )
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 added the steps argument here.

It seems when it was created, the type already had the steps argument, but it was never used.

@renatho renatho changed the title Refactor bundle installation to be generic Refactor the bundle installation to be generic Dec 8, 2023
@renatho renatho force-pushed the change/make-bundle-installation-generic branch 2 times, most recently from c050e84 to d449f0b Compare December 8, 2023 22:25
recordTracksEvent( 'calypso_woocommerce_dashboard_confirm_submit', {
let eventName = 'calypso_bundle_dashboard_confirm_submit';

if ( 'woo-on-plans' === pluginSlug ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic was applied in some different places as part of this commit: 4d32095

Do you think it makes sense? So we keep the same event and log when it's the woo-on-plans, but we use a generic name for the others. Or maybe should we register one event and log for woo-on-plans, and always register the generic one (having 2 registers for woo-on-plans)?

Personally, I thought the ideal would be to just rename it for every case (the calypso_woocommerce_dashboard_confirm_submit wouldn't exist anymore), but I'm afraid that it could break existing reports, and so on.

Also, should I document this somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a tool for documenting new tracks events, more info: PCYsg-mUj-p2

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be tempted to have both events, one for woo-on-plans specifically, so as not to break any existing reports (though it doesn't look oft used tbh) and the generic one that's more future-proof

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in: 59878f2. I wasn't very sure about the logstash, so I did the same there, just in case.

I'll take a look about the documentation! Thank you!

Copy link
Contributor Author

@renatho renatho Dec 14, 2023

Choose a reason for hiding this comment

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

Events are also registered.
The previous ones (WooCommerce events) weren't registered, and I didn't register them because we probably don't want them to be used anymore.

https://github.com/Automattic/tracks-events-registration/pull/2054
https://github.com/Automattic/tracks-events-registration/pull/2055

* Hook to get the bundle settings for a given theme.
* If the theme doesn't have a sotfware set defined, it returns `null`.
*/
const useBundleSettings = ( themeId: string ): BundleSettings | null => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now we have hooks to get the settings by software or theme (through useBundleSettingsByTheme) now.

@renatho renatho force-pushed the change/make-bundle-installation-generic branch from 4d32095 to a87c1e0 Compare December 11, 2023 18:28
import { eligibilityHolds as eligibilityHoldsConstants } from 'calypso/state/automated-transfer/constants';
import SupportCard from '../store-address/support-card';
import type { Step } from '../../types';
import type { OnboardSelect, SiteSelect } from '@automattic/data-stores';
import type { TransferEligibilityError } from '@automattic/data-stores/src/automated-transfer-eligibility/types';
import './style.scss';

const ActionSection = styled.div`
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 moved these styles directly to this final instead of importing it from woocommerce-install to not have it tied to woocommerce components, and following the approach used in other components. Ideally, in the future, it could be in a central place and replace all the occurrences.

@renatho renatho mentioned this pull request Dec 14, 2023
7 tasks
renatho and others added 2 commits December 14, 2023 15:26
Update to match changes from conflicting PR. See #85013 and #84886 (comment).

Co-authored-by: okmttdhr <okmttdhr@users.noreply.github.com>
@renatho renatho force-pushed the change/make-bundle-installation-generic branch from 373f83e to 15cee75 Compare December 14, 2023 19:09
okmttdhr added a commit that referenced this pull request Dec 15, 2023
intent,
storeType,
adminUrl,
dispatch,
exitFlow,
} );
if ( false !== endReturn ) {
if ( settings?.endFlow && false !== endReturn ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While testing it with the Sensei bundle (#85309), I noticed an issue here. Fixed as part of this commit: b5fa4e0

It should return earlier only if the endFlow exists and it doesn't return false.

@renatho renatho force-pushed the change/make-bundle-installation-generic branch from 7b251e7 to c08ac45 Compare December 18, 2023 20:36
@renatho renatho merged commit 973a2b5 into trunk Dec 21, 2023
11 checks passed
@renatho renatho deleted the change/make-bundle-installation-generic branch December 21, 2023 17:49
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 21, 2023
renatho added a commit that referenced this pull request Dec 21, 2023
* Refactor check for plugins to be generic

* Update bundle settings hook to allow getting settings by theme software

* Move array of plugins to check to the bundle settings

* Update feature flag to a generic name

* Rename woo confirm to bundle confirm

* Add new hook to get site bundle settings

* Add TODO comment to review later

* Rename woo transfer to bundle transfer

* Make bundle transfer step generic

* Rename woo install plugins to bundle install plugins

* Make install plugins generic

* Translate message that was not translated

* Get software name dynamically from bundle settings

* Remove a not necessary hook

* Refactor hooks to be named exports, following the standards of the existing ones

* Use hook to get plugin slug

* Remove Woo Verify Email not used feature

* Reorganize bundle steps array

* Add comments to make the steps more clear

* Move custom back to settings

* Move flow settings to bundleStepsSettings

* Move steps to settings

So only one object from this file needs to be customized for bundles.

* Make end of flow generic

* Make custom functions optional

* Add comments to the custom functions

* Rename the variable to follow the same standard of the other file

* Force type to be a string

* Add steps as argument to the useStepNavigation

* Make the navigation to the next step generic for the submit

* Refactor submit

* Update log and event name

* Update import to the new function

* Remove unused code

This logic is part of plugin-bundle-flow.

* Move the styles to the file

Following the approach applied in other files

* Remove comment

Keeping it as a customization inside the step, as exception.

* Update logic to upgrade site when installing free theme with bundle

* Make `ThemeUpgradeModal` Calypso-State-free

Update to match changes from conflicting PR. See #85013 and #84886 (comment).

Co-authored-by: okmttdhr <okmttdhr@users.noreply.github.com>

* Add event for all the cases, and keep the current one for backward compatibility

* Fix case when endFlow is not set

* Add Sensei bundle settings

* Update string to match new updates from rebase

* Redirect to Sensei Setup Wizard after the WPCOM flow

* Remove step from URL

It automattically redirects to the first step of the wizard.

* Update string for bundled plugin messages

* Fix logic to display activate or upgrade button

---------

Co-authored-by: okmttdhr <okmttdhr@users.noreply.github.com>
@a8ci18n
Copy link

a8ci18n commented Dec 21, 2023

This Pull Request is now available for translation here: https://translate.wordpress.com/deliverables/10448936

Some locales (Hebrew, Japanese) have been temporarily machine-translated due to translator availability. All other translations are usually ready within a few days. Untranslated and machine-translated strings will be sent for translation next Monday and are expected to be completed by the following Friday.

Hi @renatho, could you please edit the description of this PR and add a screenshot for our translators? Ideally it'd include this string: Installing %(softwareName)s

Thank you in advance!

@a8ci18n
Copy link

a8ci18n commented Dec 24, 2023

Translation for this Pull Request has now been finished.

( ( ! isThemeAllowedOnSite || isPremium ) &&
! isThemePurchased &&
! isExternallyManagedTheme ) ||
( isBundledSoftwareSet && ! canInstallPlugins )
Copy link
Contributor

@ilyasfoo ilyasfoo Jan 2, 2024

Choose a reason for hiding this comment

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

Hey, @renatho!

This particular change may have unintentionally caused a bug in Woo Express, where themes like tsubaki and tazza now requires an upgrade. This is because a free trial site can't activate plugins, and I believe woocommerce themes are marked as "bundled software set".

May I know what was the intended themes to be matched with this logic?

To reproduce:

  1. Create a Woo Express free trial site by going to https://woo.com/start and follow through the NUX process
  2. Go to Appearance > Themes
  3. Search for tazza
  4. Select Tazza theme
  5. Observe you can't activate it now
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I've made a PR to fix this, #85890.

Appreciate if you can take a look as well, @renatho!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilyasfoo

Thank you for catching it and quickly raising a PR with the fix!

May I know what was the intended themes to be matched with this logic?

It was supposed to match the paid themes (previous logic) + bundled themes. But I was assuming that any bundled theme would need to be upgraded to a plan where the user can install plugins because it will install a plugin along with the theme. But I missed this use case that you mentioned.

I've made a PR to fix this, #85890.

I'll take a look now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May I know what was the intended themes to be matched with this logic?

The new theme we are considering outside of WooCommerce is the Course theme, which installs the Sensei LMS.

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.

6 participants