Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
161b7b3
Add install-and-activate-plugins-async action to onboarding
Jun 5, 2023
b0a8c4a
Add label and learn_more_link types
Jun 5, 2023
4ae39aa
Use label and learn_more_link
Jun 5, 2023
02d1f94
Fix type
Jun 5, 2023
f0836f7
Add changelog
Jun 5, 2023
144568b
Add changelog
Jun 5, 2023
a4db495
Add install_priority -- this will be used in the core profiler
Jun 6, 2023
22cea1f
Sort selected plugins by install_priority for installation
Jun 6, 2023
f2bbf2a
Remove unused imports
Jun 6, 2023
b6d9912
dev: refactor installAndActivatePlugins to xstate
rjchow Jun 2, 2023
bf6d53f
ts fixes
rjchow Jun 2, 2023
071ecbb
Sort plugins by install_priority
Jun 6, 2023
3d8483b
Make sure WooCommerce Shipping is always visible
Jun 6, 2023
7bc389d
Update free extension list content
Jun 6, 2023
c29b492
Visual changes on the plugin page
Jun 6, 2023
a2506ca
Fix css lint error
Jun 7, 2023
9725e3f
Fix gray-900 variable name
Jun 7, 2023
5676c45
Hide learn more link on mobile view
Jun 7, 2023
6bc1133
Add back learn more link that was removed from rebase
Jun 11, 2023
fcb6b67
Send pluginsAvailable to pluginInstallermachine
Jun 12, 2023
e09db7e
Use is_activated to determine plugin availability and install status
Jun 12, 2023
a09dbfd
Update packages/js/data/src/onboarding/types.ts
Jun 13, 2023
de530a5
Update plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/De…
Jun 13, 2023
31f8600
Add back recordTracksPluginsLearnMoreLinkClicked
Jun 13, 2023
5fb6863
Use install-and-activate-plugins-async when timer is up
Jun 13, 2023
175deec
Record plugin and link with learn more linked clicked event
Jun 13, 2023
f45f695
Fix failign tests
Jun 13, 2023
f852515
Add comment for install_priority
Jun 13, 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
4 changes: 4 additions & 0 deletions packages/js/data/changelog/update-onboarding-types
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Added install-and-activate-async to Onboarding and updated related types
25 changes: 24 additions & 1 deletion packages/js/data/src/onboarding/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
TaskListType,
TaskType,
OnboardingProductTypes,
InstallAndActivatePluginsAsyncResponse,
} from './types';
import { Plugin } from '../plugins/types';
import { Plugin, PluginNames } from '../plugins/types';

export function getFreeExtensionsError( error: unknown ) {
return {
Expand Down Expand Up @@ -465,6 +466,28 @@ export function* actionTask( id: string ) {
}
}

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 it'll be good to document the async behaviour, i.e.: how it works and how it's handled in the frontend. Not sure if this is the best place, but I digress. What do you think?

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 think we can document it in both frontend and backend. I'll add them 👍

export function* installAndActivatePluginsAsync(
plugins: Partial< PluginNames >[]
) {
yield setIsRequesting( 'installAndActivatePluginsAsync', true );

try {
const results: InstallAndActivatePluginsAsyncResponse = yield apiFetch(
{
path: `${ WC_ADMIN_NAMESPACE }/onboarding/plugins/install-and-activate-async`,
method: 'POST',
data: { plugins },
}
);

return results;
} catch ( error ) {
throw error;
} finally {
yield setIsRequesting( 'installAndActivatePluginsAsync', false );
}
}

export type Action = ReturnType<
| typeof getFreeExtensionsError
| typeof getFreeExtensionsSuccess
Expand Down
17 changes: 15 additions & 2 deletions packages/js/data/src/onboarding/test/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ describe( 'plugins reducer', () => {
it( 'should handle SET_PROFILE_ITEMS', () => {
const state = reducer(
{
// @ts-expect-error - we're only testing profileItems
profileItems,
freeExtensions: [],
taskLists: {},
paymentMethods: [],
productTypes: {},
emailPrefill: '',
errors: {},
requesting: {},
},
{
type: TYPES.SET_PROFILE_ITEMS,
profileItems: { is_agree_marketing: true },
replace: false,
}
);

Expand All @@ -64,8 +71,14 @@ describe( 'plugins reducer', () => {
it( 'should handle SET_PROFILE_ITEMS with replace', () => {
const state = reducer(
{
// @ts-expect-error - we're only testing profileItems
profileItems,
freeExtensions: [],
taskLists: {},
paymentMethods: [],
productTypes: {},
emailPrefill: '',
errors: {},
requesting: {},
},
{
type: TYPES.SET_PROFILE_ITEMS,
Expand Down
16 changes: 15 additions & 1 deletion packages/js/data/src/onboarding/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type RevenueTypeSlug =
| 'more-than-250000';

export type ProfileItems = {
business_extensions?: [] | null;
business_extensions?: string[] | null;
completed?: boolean | null;
industry?: Industry[] | null;
number_employees?: string | null;
Expand Down Expand Up @@ -180,7 +180,21 @@ export type Extension = {
image_url: string;
manage_url: string;
name: string;
label?: string;
is_built_by_wc: boolean;
is_visible: boolean;
is_installed?: boolean;
is_activated?: boolean;
learn_more_link?: string;
install_priority?: number;
};

export type InstallAndActivatePluginsAsyncResponse = {
job_id: string;
status: 'pending' | 'in-progress' | 'completed' | 'failed';
plugins: Array< {
status: 'pending' | 'installing' | 'installed' | 'activated' | 'failed';
errors: string[];
install_duration?: number;
} >;
};
14 changes: 14 additions & 0 deletions plugins/woocommerce-admin/client/core-profiler/actions/tracks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CoreProfilerStateMachineContext,
UserProfileEvent,
BusinessInfoEvent,
PluginsLearnMoreLinkClicked,
} from '..';
import { POSSIBLY_DEFAULT_STORE_NAMES } from '../pages/BusinessInfo';

Expand Down Expand Up @@ -89,11 +90,24 @@ const recordTracksBusinessInfoCompleted = (
} );
};

const recordTracksPluginsLearnMoreLinkClicked = (
_context: unknown,
_event: PluginsLearnMoreLinkClicked,
{ action }: { action: unknown }
) => {
const { step } = action as { step: string };
recordEvent( `storeprofiler_${ step }_learn_more_link_clicked`, {
plugin: _event.payload.plugin,
link: _event.payload.learnMoreLink,
} );
};

export default {
recordTracksStepViewed,
recordTracksStepSkipped,
recordTracksIntroCompleted,
recordTracksUserProfileCompleted,
recordTracksSkipBusinessLocationCompleted,
recordTracksBusinessInfoCompleted,
recordTracksPluginsLearnMoreLinkClicked,
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
max-width: 100%;
}

.components-checkbox-control__input-container {
margin-top: 6px;
}

input {
margin: 3px 26px 0 0;
width: 20px;
Expand All @@ -26,15 +30,15 @@
}
img {
margin-right: 12px;
width: 25px;
height: 25px;
width: 28px;
@include breakpoint( '<782px' ) {
align-self: center;
}
}
h3 {
font-size: 14px;
line-height: 20px;
font-weight: 500;
margin: 0 0 8px 0;
padding: 0;
@include breakpoint( '<782px' ) {
Expand All @@ -43,14 +47,20 @@
}

p {
display: inline;
font-size: 13px;
line-height: 16px;
color: $gray-700;
margin: 0;
padding: 0;
a {
color: inherit;
@include breakpoint( '<782px' ) {
display: none;
}
}

a {
color: $gray-700;
margin-left: 5px;
@include breakpoint( '<782px' ) {
display: none;
}
Expand All @@ -63,6 +73,7 @@
height: 16px;
&:focus {
box-shadow: none;
border-color: #1e1e1e;
}
}
.components-checkbox-control__input[type='checkbox']:checked {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const PluginCard = ( {
onChange,
checked = false,
description,
learnMoreLink,
}: {
// Checkbox will be hidden if true
installed?: boolean;
Expand All @@ -28,6 +29,7 @@ export const PluginCard = ( {
description: string | ReactNode;
checked?: boolean;
onChange?: () => void;
learnMoreLink?: ReactNode;
} ) => {
return (
<div className="woocommerce-profiler-plugins-plugin-card">
Expand All @@ -53,6 +55,7 @@ export const PluginCard = ( {
) }
</div>
<p dangerouslySetInnerHTML={ sanitizeHTML( description ) } />
{ learnMoreLink }
</div>
</div>
);
Expand Down
17 changes: 17 additions & 0 deletions plugins/woocommerce-admin/client/core-profiler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ export type PluginsInstallationRequestedEvent = {
};
};

export type PluginsLearnMoreLinkClicked = {
type: 'PLUGINS_LEARN_MORE_LINK_CLICKED';
payload: {
plugin: string;
learnMoreLink: string;
};
};

// TODO: add types as we develop the pages
export type OnboardingProfile = {
business_choice: BusinessChoice;
Expand Down Expand Up @@ -1107,6 +1115,14 @@ export const coreProfilerStateMachineDefinition = createMachine( {
],
target: 'pluginsSkipped',
},
PLUGINS_LEARN_MORE_LINK_CLICKED: {
actions: [
{
type: 'recordTracksPluginsLearnMoreLinkClicked',
step: 'plugins',
},
],
},
PLUGINS_INSTALLATION_REQUESTED: {
target: 'installPlugins',
actions: [ 'assignPluginsSelected' ],
Expand Down Expand Up @@ -1266,6 +1282,7 @@ export const coreProfilerStateMachineDefinition = createMachine( {
data: ( context ) => {
return {
selectedPlugins: context.pluginsSelected,
pluginsAvailable: context.pluginsAvailable,
};
},
},
Expand Down
36 changes: 31 additions & 5 deletions plugins/woocommerce-admin/client/core-profiler/pages/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { useState } from 'react';
/**
* Internal dependencies
*/
import { CoreProfilerStateMachineContext } from '../index';
import {
CoreProfilerStateMachineContext,
PluginsLearnMoreLinkClicked,
} from '../index';
import { PluginsInstallationRequestedEvent, PluginsPageSkippedEvent } from '..';
import { Heading } from '../components/heading/heading';
import { Navigation } from '../components/navigation/navigation';
Expand All @@ -36,13 +39,16 @@ export const Plugins = ( {
}: {
context: CoreProfilerStateMachineContext;
sendEvent: (
payload: PluginsInstallationRequestedEvent | PluginsPageSkippedEvent
payload:
| PluginsInstallationRequestedEvent
| PluginsPageSkippedEvent
| PluginsLearnMoreLinkClicked
) => void;
navigationProgress: number;
} ) => {
const [ selectedPlugins, setSelectedPlugins ] = useState<
ExtensionList[ 'plugins' ]
>( context.pluginsAvailable.filter( ( plugin ) => ! plugin.is_installed ) );
>( context.pluginsAvailable.filter( ( plugin ) => ! plugin.is_activated ) );

const setSelectedPlugin = ( plugin: Extension ) => {
setSelectedPlugins(
Expand Down Expand Up @@ -136,10 +142,29 @@ export const Plugins = ( {
) }
<div className="woocommerce-profiler-plugins__list">
{ context.pluginsAvailable.map( ( plugin ) => {
const learnMoreLink = plugin.learn_more_link ? (
<Link
onClick={ () => {
sendEvent( {
type: 'PLUGINS_LEARN_MORE_LINK_CLICKED',
payload: {
plugin: plugin.key,
learnMoreLink:
plugin.learn_more_link ?? '',
},
} );
} }
href={ plugin.learn_more_link }
target="_blank"
type="external"
>
{ __( 'Learn More', 'woocommerce' ) }
</Link>
) : null;
return (
<PluginCard
key={ `checkbox-control-${ plugin.key }` }
installed={ plugin.is_installed }
installed={ plugin.is_activated }
onChange={ () => {
setSelectedPlugin( plugin );
} }
Expand All @@ -156,8 +181,9 @@ export const Plugins = ( {
/>
) : null
}
title={ plugin.name }
title={ plugin.label }
description={ plugin.description }
learnMoreLink={ learnMoreLink }
/>
);
} ) }
Expand Down
Loading