Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
83 changes: 42 additions & 41 deletions plugins/woocommerce-admin/client/core-profiler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ import { BusinessLocation } from './pages/BusinessLocation';
import { getCountryStateOptions } from './services/country';
import { Loader } from './pages/Loader';
import { Plugins } from './pages/Plugins';
import { getPluginTrackKey, getTimeFrame } from '~/utils';
import { getPluginSlug, getPluginTrackKey, getTimeFrame } from '~/utils';
import './style.scss';
import {
InstallationCompletedResult,
InstallAndActivatePlugins,
InstalledPlugin,
PluginInstallError,
pluginInstallerMachine,
} from './services/installAndActivatePlugins';
import { ProfileSpinner } from './components/profile-spinner/profile-spinner';
import recordTracksActions from './actions/tracks';
Expand Down Expand Up @@ -362,6 +362,23 @@ const updateBusinessLocation = ( countryAndState: string ) => {
} );
};

const assignStoreLocation = assign( {
businessInfo: (
context: CoreProfilerStateMachineContext,
event: BusinessLocationEvent
) => {
return {
...context.businessInfo,
location: event.payload.storeLocation,
};
},
} );

const assignUserProfile = assign( {
userProfile: ( context, event: UserProfileEvent ) =>
event.payload.userProfile, // sets context.userProfile to the payload of the event
} );

const updateBusinessInfo = async (
_context: CoreProfilerStateMachineContext,
event: BusinessInfoEvent
Expand Down Expand Up @@ -442,8 +459,8 @@ const browserPopstateHandler = () => ( sendBack: Sender< AnyEventObject > ) => {
};

const handlePlugins = assign( {
pluginsAvailable: ( _context, event: DoneInvokeEvent< Extension[] > ) =>
event.data,
pluginsAvailable: ( _context, event ) =>
( event as DoneInvokeEvent< Extension[] > ).data,
} );

type ActType = (
Expand All @@ -462,6 +479,12 @@ const updateQueryStep: ActType = ( _context, _evt, { action } ) => {
}
};

const assignPluginsSelected = assign( {
pluginsSelected: ( _context, event: PluginsInstallationRequestedEvent ) => {
return event.payload.plugins.map( getPluginSlug );
},
} );

export const preFetchActions = {
preFetchGetPlugins,
preFetchGetCountries,
Expand All @@ -480,6 +503,9 @@ const coreProfilerMachineActions = {
handleStoreNameOption,
handleStoreCountryOption,
assignOptInDataSharing,
assignStoreLocation,
assignPluginsSelected,
assignUserProfile,
handleCountries,
handleOnboardingProfileOption,
assignOnboardingProfile,
Expand Down Expand Up @@ -712,25 +738,11 @@ export const coreProfilerStateMachineDefinition = createMachine( {
on: {
USER_PROFILE_COMPLETED: {
target: 'postUserProfile',
actions: [
assign( {
userProfile: (
_context,
event: UserProfileEvent
) => event.payload.userProfile, // sets context.userProfile to the payload of the event
} ),
],
actions: [ 'assignUserProfile' ],
},
USER_PROFILE_SKIPPED: {
target: 'postUserProfile',
actions: [
assign( {
userProfile: (
_context,
event: UserProfileEvent
) => event.payload.userProfile, // assign context.userProfile to the payload of the event
} ),
],
actions: [ 'assignUserProfile' ],
},
},
exit: actions.choose( [
Expand Down Expand Up @@ -952,18 +964,7 @@ export const coreProfilerStateMachineDefinition = createMachine( {
BUSINESS_LOCATION_COMPLETED: {
target: 'postSkipFlowBusinessLocation',
actions: [
assign( {
businessInfo: (
_context,
event: BusinessLocationEvent
) => {
return {
..._context.businessInfo,
location:
event.payload.storeLocation,
};
},
} ),
'assignStoreLocation',
'recordTracksSkipBusinessLocationCompleted',
],
},
Expand Down Expand Up @@ -1108,14 +1109,7 @@ export const coreProfilerStateMachineDefinition = createMachine( {
},
PLUGINS_INSTALLATION_REQUESTED: {
target: 'installPlugins',
actions: [
assign( {
pluginsSelected: (
_context,
event: PluginsInstallationRequestedEvent
) => event.payload.plugins,
} ),
],
actions: [ 'assignPluginsSelected' ],
},
},
meta: {
Expand Down Expand Up @@ -1268,7 +1262,12 @@ export const coreProfilerStateMachineDefinition = createMachine( {
} ),
],
invoke: {
src: InstallAndActivatePlugins,
src: pluginInstallerMachine,
data: ( context ) => {
return {
selectedPlugins: context.pluginsSelected,
};
},
},
meta: {
component: Loader,
Expand All @@ -1290,6 +1289,8 @@ export const CoreProfilerController = ( {
const augmentedStateMachine = useMemo( () => {
// When adding extensibility, this is the place to manipulate the state machine definition.
return coreProfilerStateMachineDefinition.withConfig( {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- there seems to be a flaky error here - it fails sometimes and then not on recompile, will need to investigate further.
actions: {
...coreProfilerMachineActions,
...actionOverrides,
Expand Down
Loading