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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
afafd12
Refactor check for plugins to be generic
renatho Dec 5, 2023
cb51bbe
Update bundle settings hook to allow getting settings by theme software
renatho Dec 6, 2023
5efd51a
Move array of plugins to check to the bundle settings
renatho Dec 6, 2023
4575b6a
Update feature flag to a generic name
renatho Dec 6, 2023
14a7768
Rename woo confirm to bundle confirm
renatho Dec 6, 2023
3fc713d
Add new hook to get site bundle settings
renatho Dec 6, 2023
fa5ba4f
Add TODO comment to review later
renatho Dec 6, 2023
c666534
Rename woo transfer to bundle transfer
renatho Dec 6, 2023
19af71c
Make bundle transfer step generic
renatho Dec 6, 2023
f17fd99
Rename woo install plugins to bundle install plugins
renatho Dec 6, 2023
bd2c819
Make install plugins generic
renatho Dec 6, 2023
c753658
Translate message that was not translated
renatho Dec 6, 2023
cb77c6f
Get software name dynamically from bundle settings
renatho Dec 6, 2023
23f01f8
Remove a not necessary hook
renatho Dec 6, 2023
6edb309
Refactor hooks to be named exports, following the standards of the ex…
renatho Dec 6, 2023
01791a9
Use hook to get plugin slug
renatho Dec 6, 2023
49f24dd
Remove Woo Verify Email not used feature
renatho Dec 7, 2023
f3c61f7
Reorganize bundle steps array
renatho Dec 7, 2023
f448108
Add comments to make the steps more clear
renatho Dec 7, 2023
d5d0eea
Move custom back to settings
renatho Dec 7, 2023
bbc6c0b
Move flow settings to bundleStepsSettings
renatho Dec 7, 2023
9bf0212
Move steps to settings
renatho Dec 8, 2023
2add0ab
Make end of flow generic
renatho Dec 8, 2023
efdefa1
Make custom functions optional
renatho Dec 8, 2023
f227e86
Add comments to the custom functions
renatho Dec 8, 2023
a689fc4
Rename the variable to follow the same standard of the other file
renatho Dec 8, 2023
11555fd
Force type to be a string
renatho Dec 8, 2023
9b6355d
Add steps as argument to the useStepNavigation
renatho Dec 8, 2023
3e9eff8
Make the navigation to the next step generic for the submit
renatho Dec 8, 2023
7834689
Refactor submit
renatho Dec 8, 2023
691a7d7
Update log and event name
renatho Dec 11, 2023
3b65a42
Update import to the new function
renatho Dec 11, 2023
739f2f9
Remove unused code
renatho Dec 11, 2023
4184b93
Move the styles to the file
renatho Dec 11, 2023
894db61
Remove comment
renatho Dec 11, 2023
1b69050
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 12, 2023
cd6f5da
Update logic to upgrade site when installing free theme with bundle
renatho Dec 14, 2023
f7791a0
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 14, 2023
15cee75
Make `ThemeUpgradeModal` Calypso-State-free
renatho Dec 14, 2023
59878f2
Add event for all the cases, and keep the current one for backward co…
renatho Dec 14, 2023
99dfe64
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 14, 2023
fb98dbe
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 15, 2023
b5fa4e0
Fix case when endFlow is not set
renatho Dec 15, 2023
67f5a17
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 15, 2023
c08ac45
Fix logic to display activate or upgrade button
renatho Dec 18, 2023
00a7551
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 20, 2023
77bca35
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 21, 2023
6698d00
Merge branch 'trunk' of github.com:Automattic/wp-calypso into change/…
renatho Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ export const FlowRenderer: React.FC< { flow: Flow } > = ( { flow } ) => {
setPreviousProgress( stepProgress?.progress ?? 0 );
};

const stepNavigation = flow.useStepNavigation( currentStepRoute, _navigate );
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.

);

// Retrieve any extra step data from the stepper-internal store. This will be passed as a prop to the current step.
const stepData = useSelect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProductsList } from '@automattic/data-stores';
import { StepContainer } from '@automattic/onboarding';
import { StepContainer, NextButton } from '@automattic/onboarding';
import styled from '@emotion/styled';
import { useSelect, useDispatch } from '@wordpress/data';
import { useI18n } from '@wordpress/react-i18n';
Expand All @@ -11,21 +11,41 @@ import FormattedHeader from 'calypso/components/formatted-header';
import { LoadingEllipsis } from 'calypso/components/loading-ellipsis';
import WarningCard from 'calypso/components/warning-card';
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { useSitePluginSlug } from 'calypso/landing/stepper/hooks/use-site-plugin-slug';
import {
AUTOMATED_ELIGIBILITY_STORE,
SITE_STORE,
ONBOARD_STORE,
} from 'calypso/landing/stepper/stores';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { addQueryArgs } from 'calypso/lib/url';
import { ActionSection, StyledNextButton } from 'calypso/signup/steps/woocommerce-install';
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.

display: flex;
justify-content: space-between;
align-items: baseline;
flex-wrap: wrap;
margin-top: 40px;
gap: 4%;

@media ( max-width: 320px ) {
align-items: center;
}
`;

const StyledNextButton = styled( NextButton )`
@media ( max-width: 320px ) {
width: 100%;
margin-bottom: 20px;
}
`;

const Divider = styled.hr`
border-top: 1px solid #eee;
background: none;
Expand All @@ -41,11 +61,12 @@ const TRANSFERRING_NOT_BLOCKERS = [
eligibilityHoldsConstants.TRANSFER_ALREADY_EXISTS, // Already Atomic sites are handled in the install flow.
];

const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {
const BundleConfirm: Step = function BundleConfirm( { navigation } ) {
const { goBack, submit } = navigation;
const { __ } = useI18n();
const site = useSite();
const siteId = site && site?.ID;
const pluginSlug = useSitePluginSlug();
const isAtomicSite = useSelect(
( select ) => siteId && ( select( SITE_STORE ) as SiteSelect ).isSiteAtomic( siteId ),
[ siteId ]
Expand Down Expand Up @@ -179,8 +200,8 @@ const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {
required: requiresUpgrade,
checkoutUrl: addQueryArgs(
{
redirect_to: addQueryArgs( queryArgs, '/setup/plugin-bundle/wooTransfer' ),
cancel_to: addQueryArgs( queryArgs, '/setup/plugin-bundle/wooConfirm' ),
redirect_to: addQueryArgs( queryArgs, '/setup/plugin-bundle/bundleTransfer' ),
cancel_to: addQueryArgs( queryArgs, '/setup/plugin-bundle/bundleConfirm' ),
},
`/checkout/${ wpcomDomain }/${ upgradingPlan?.product_slug ?? '' }`
),
Expand All @@ -206,7 +227,7 @@ const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {
}

return (
<div className="woo-confirm__upgrade-required">
<div className="bundle-confirm__upgrade-required">
<PlanWarning title={ __( 'Plan upgrade required' ) }>
{ siteUpgrading.description }
</PlanWarning>
Expand Down Expand Up @@ -242,8 +263,8 @@ const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {
function getContent() {
return (
<>
<div className="woo-confirm__info-section" />
<div className="woo-confirm__instructions-container">
<div className="bundle-confirm__info-section" />
<div className="bundle-confirm__instructions-container">
{ getWPComSubdomainWarningContent() }
{ getCheckoutContent() }
{ getWarningsOrHoldsSection() }
Expand All @@ -252,11 +273,24 @@ const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {
<StyledNextButton
disabled={ isTransferringBlocked || ! isDataReady }
onClick={ () => {
recordTracksEvent( 'calypso_woocommerce_dashboard_confirm_submit', {
const eventProperties = {
site: wpcomDomain,
Copy link
Contributor

Choose a reason for hiding this comment

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

it'd be good to add a property here for the bundle slug, that way we can create bundle specific funnels and stats later if necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Added in 59878f2.

upgrade_required: siteUpgrading.required,
};

recordTracksEvent( 'calypso_bundle_dashboard_confirm_submit', {
...eventProperties,
software_set: pluginSlug,
} );

// For backward compatibility with existing event. When it's not used anymore, it can be removed.
if ( 'woo-on-plans' === pluginSlug ) {
recordTracksEvent(
'calypso_woocommerce_dashboard_confirm_submit',
eventProperties
);
}

const providedDependencies = {
checkoutUrl: siteUpgrading.checkoutUrl,
};
Expand All @@ -276,7 +310,7 @@ const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {

if ( site === null || ! site.ID || ! isDataReady || isReadyToStart ) {
return (
<div className="woo-confirm__loading-container">
<div className="bundle-confirm__loading-container">
<LoadingEllipsis />
</div>
);
Expand All @@ -289,13 +323,13 @@ const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {

return (
<StepContainer
stepName="woo-confirm"
stepName="bundle-confirm"
goBack={ goBack }
hideSkip
isHorizontalLayout={ true }
formattedHeader={
<FormattedHeader
id="woo-confirm-title-header"
id="bundle-confirm-title-header"
headerText={ headerText }
subHeaderText={ subHeaderText }
align="left"
Expand All @@ -308,4 +342,4 @@ const WooConfirm: Step = function WooCommerceConfirm( { navigation } ) {
);
};

export default WooConfirm;
export default BundleConfirm;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

body.is-section-stepper {
// Two column layout.
.step-container.woo-confirm {
.step-container.bundle-confirm {
@media ( min-width: 660px ) {
display: flex;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ body.is-section-stepper {
margin: 0 24px;
}

.woo-confirm__instructions-container {
.bundle-confirm__instructions-container {
font-size: 0.875rem;
letter-spacing: -0.16px;
color: var(--studio-gray-60);
Expand All @@ -63,7 +63,7 @@ body.is-section-stepper {
margin-top: 16px;
}

.woo-confirm__upgrade-required {
.bundle-confirm__upgrade-required {
margin-top: 1rem;
}

Expand Down Expand Up @@ -113,14 +113,14 @@ body.is-section-stepper {
}
}

.site-setup.woo-confirm {
.woo-confirm__loading-container,
.woo-confirm__info-section {
.site-setup.bundle-confirm {
.bundle-confirm__loading-container,
.bundle-confirm__info-section {
display: flex;
justify-content: center;
}

.woo-confirm__loading-container {
.bundle-confirm__loading-container {
margin-top: 25vh;

@include break-small {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint-disable no-console */
import config from '@automattic/calypso-config';
import { useDispatch, useSelect } from '@wordpress/data';
import { useTranslate } from 'i18n-calypso';
import { useEffect } from 'react';
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { useSitePluginSlug } from 'calypso/landing/stepper/hooks/use-site-plugin-slug';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { logToLogstash } from 'calypso/lib/logstash';
import { useBundleSettings } from 'calypso/my-sites/theme/hooks/use-bundle-settings';
import { ONBOARD_STORE, SITE_STORE } from '../../../../stores';
import type { Step } from '../../types';
import type { AtomicSoftwareStatus, OnboardSelect, SiteSelect } from '@automattic/data-stores';
Expand All @@ -17,38 +20,63 @@ export interface FailureInfo {
error: string;
}

const WooInstallPlugins: Step = function WooInstallPlugins( { navigation } ) {
const BundleInstallPlugins: Step = function BundleInstallPlugins( { navigation } ) {
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.

const bundleSettings = useBundleSettings( softwareSet );
const translate = useTranslate();
const { getIntent } = useSelect( ( select ) => select( ONBOARD_STORE ) as OnboardSelect, [] );

const handleTransferFailure = ( failureInfo: FailureInfo ) => {
recordTracksEvent( 'calypso_woocommerce_dashboard_snag_error', {
const eventProperties = {
action: failureInfo.type,
site: site?.URL,
code: failureInfo.code,
error: failureInfo.error,
intent: getIntent(),
} );
};

logToLogstash( {
feature: 'calypso_client',
const logstashProperties = {
feature: 'calypso_client' as 'calypso_client' | 'calypso_ssr',
message: failureInfo.error,
severity: config( 'env_id' ) === 'production' ? 'error' : 'debug',
blog_id: site?.ID,
properties: {
env: config( 'env_id' ),
type: 'calypso_woocommerce_dashboard_snag_error',
type: 'calypso_bundle_dashboard_snag_error',
action: failureInfo.type,
site: site?.URL,
code: failureInfo.code,
},
};

recordTracksEvent( 'calypso_bundle_dashboard_snag_error', {
...eventProperties,
software_set: softwareSet,
} );

logToLogstash( {
...logstashProperties,
properties: { ...logstashProperties.properties, software_set: softwareSet },
} );

// For backward compatibility with existing event. When it's not used anymore, it can be removed.
if ( 'woo-on-plans' === softwareSet ) {
recordTracksEvent( 'calypso_woocommerce_dashboard_snag_error', eventProperties );

logToLogstash( {
...logstashProperties,
properties: {
...logstashProperties.properties,
type: 'calypso_woocommerce_dashboard_snag_error',
},
} );
}
};

useEffect( () => {
Expand All @@ -57,7 +85,14 @@ const WooInstallPlugins: Step = function WooInstallPlugins( { navigation } ) {
}

setPendingAction( async () => {
setProgressTitle( 'Installing WooCommerce' );
// translators: %(softwareName)s is the software name that is being installed.
const title = translate( 'Installing %(softwareName)s', {
args: {
softwareName: bundleSettings?.softwareName || '',
},
} );

setProgressTitle( title );
setProgress( 0 );
initiateSoftwareInstall( site.ID, softwareSet );

Expand Down Expand Up @@ -111,4 +146,4 @@ const WooInstallPlugins: Step = function WooInstallPlugins( { navigation } ) {
return null;
};

export default WooInstallPlugins;
export default BundleInstallPlugins;
Loading
Loading