-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stepper framework: Add importers steps (#63525)
* Fix styling issues inside stepper framework * Adjust importer routes * Set current user in the redux store * Add block margin to the importer-step * Update step navigator to support path with query params * Add util functions * Update getWpComOnboardingUrl method to support switch between frameworks * Add importer hooks * Create common importer wrapper component * Create Blogger importer step * Create Medium importer step * Create Squarespace importer step * Create Wix importer step * Create Wordpress importer step * Update navigation typing to support arg: StepPath + QueryParams * Register importer steps * Configure importer navigation * Configure route to consume importer from the stepper framework * Fix typing error * Optimize calling analyzeUrl: prevent calling for an undefined value * Replace providing siteId reference * Disable query fetching on each window focus Fixes issue with multiple rerenders when user tries to choose a file for upload. Before this commit, a user wasn't able to uplad a file. * Optimize initial fetching Fetch only selected site instaed of fetching all * Improve generateStepPath helper method * Update tests setup to support and frameworks * Add stepper import flows e2e tests
- Loading branch information
Showing
35 changed files
with
733 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,8 @@ button { | |
} | ||
} | ||
|
||
.import-step { | ||
.import-step, | ||
.importer-step { | ||
@include onboarding-block-margin; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
client/landing/stepper/declarative-flow/internals/steps-repository/import/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const BASE_ROUTE = 'import'; | ||
export const BASE_STEPPER_ROUTE = 'setup'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...nt/landing/stepper/declarative-flow/internals/steps-repository/importer-blogger/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Step } from 'calypso/landing/stepper/declarative-flow/internals/types'; | ||
import BloggerImporter from 'calypso/signup/steps/import-from/blogger'; | ||
import { withImporterWrapper } from '../importer'; | ||
import './style.scss'; | ||
|
||
const ImporterBlogger: Step = function ( props ) { | ||
const Importer = withImporterWrapper( BloggerImporter ); | ||
|
||
return <Importer importer={ 'blogger' } { ...props } />; | ||
}; | ||
|
||
export default ImporterBlogger; |
2 changes: 2 additions & 0 deletions
2
...t/landing/stepper/declarative-flow/internals/steps-repository/importer-blogger/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import 'signup/steps/import/style/base'; | ||
@import '../importer/style'; |
12 changes: 12 additions & 0 deletions
12
client/landing/stepper/declarative-flow/internals/steps-repository/importer-medium/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Step } from 'calypso/landing/stepper/declarative-flow/internals/types'; | ||
import MediumImporter from 'calypso/signup/steps/import-from/medium'; | ||
import { withImporterWrapper } from '../importer'; | ||
import './style.scss'; | ||
|
||
const ImporterMedium: Step = function ( props ) { | ||
const Importer = withImporterWrapper( MediumImporter ); | ||
|
||
return <Importer importer={ 'medium' } { ...props } />; | ||
}; | ||
|
||
export default ImporterMedium; |
2 changes: 2 additions & 0 deletions
2
...nt/landing/stepper/declarative-flow/internals/steps-repository/importer-medium/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import 'signup/steps/import/style/base'; | ||
@import '../importer/style'; |
12 changes: 12 additions & 0 deletions
12
...anding/stepper/declarative-flow/internals/steps-repository/importer-squarespace/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Step } from 'calypso/landing/stepper/declarative-flow/internals/types'; | ||
import SquarespaceImporter from 'calypso/signup/steps/import-from/squarespace'; | ||
import { withImporterWrapper } from '../importer'; | ||
import './style.scss'; | ||
|
||
const ImporterSquarespace: Step = function ( props ) { | ||
const Importer = withImporterWrapper( SquarespaceImporter ); | ||
|
||
return <Importer importer={ 'squarespace' } { ...props } />; | ||
}; | ||
|
||
export default ImporterSquarespace; |
2 changes: 2 additions & 0 deletions
2
...nding/stepper/declarative-flow/internals/steps-repository/importer-squarespace/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import 'signup/steps/import/style/base'; | ||
@import '../importer/style'; |
12 changes: 12 additions & 0 deletions
12
client/landing/stepper/declarative-flow/internals/steps-repository/importer-wix/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Step } from 'calypso/landing/stepper/declarative-flow/internals/types'; | ||
import WixImporter from 'calypso/signup/steps/import-from/wix'; | ||
import { withImporterWrapper } from '../importer'; | ||
import './style.scss'; | ||
|
||
const ImporterWix: Step = function ( props ) { | ||
const Importer = withImporterWrapper( WixImporter ); | ||
|
||
return <Importer importer={ 'wix' } { ...props } />; | ||
}; | ||
|
||
export default ImporterWix; |
2 changes: 2 additions & 0 deletions
2
client/landing/stepper/declarative-flow/internals/steps-repository/importer-wix/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import 'signup/steps/import/style/base'; | ||
@import '../importer/style'; |
12 changes: 12 additions & 0 deletions
12
.../landing/stepper/declarative-flow/internals/steps-repository/importer-wordpress/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Step } from 'calypso/landing/stepper/declarative-flow/internals/types'; | ||
import WordpressImporter from 'calypso/signup/steps/import-from/wordpress'; | ||
import { withImporterWrapper } from '../importer'; | ||
import './style.scss'; | ||
|
||
const ImporterWordpress: Step = function ( props ) { | ||
const Importer = withImporterWrapper( WordpressImporter ); | ||
|
||
return <Importer importer={ 'wordpress' } { ...props } />; | ||
}; | ||
|
||
export default ImporterWordpress; |
7 changes: 7 additions & 0 deletions
7
...landing/stepper/declarative-flow/internals/steps-repository/importer-wordpress/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@import 'signup/steps/import/style/base'; | ||
@import '../importer/style'; | ||
|
||
.importer-wordpress .step-container__content { | ||
padding: 20px; | ||
box-sizing: border-box; | ||
} |
24 changes: 24 additions & 0 deletions
24
...-flow/internals/steps-repository/importer/hooks/use-atomic-transfer-query-param-update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useEffect } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useQuery } from 'calypso/landing/stepper/hooks/use-query'; | ||
import { useSiteSlugParam } from 'calypso/landing/stepper/hooks/use-site-slug-param'; | ||
import { getSite } from 'calypso/state/sites/selectors'; | ||
import { updateQueryParams } from '../../import/util'; | ||
|
||
/** | ||
* Update site slug when destination site is in transition from simple to atomic | ||
*/ | ||
export function useAtomicTransferQueryParamUpdate( siteId: number | undefined ) { | ||
const currentSearchParams = useQuery(); | ||
const siteItem = useSelector( ( state ) => getSite( state, siteId as number ) ); | ||
const siteSlug = useSiteSlugParam(); | ||
|
||
useEffect( checkSiteSlugUpdate, [ siteItem?.slug ] ); | ||
|
||
function checkSiteSlugUpdate() { | ||
if ( siteItem?.slug && siteSlug !== siteItem.slug ) { | ||
currentSearchParams.set( 'siteSlug', siteItem.slug ); | ||
updateQueryParams( currentSearchParams.toString() ); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...epper/declarative-flow/internals/steps-repository/importer/hooks/use-initial-query-run.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useQuery } from 'calypso/landing/stepper/hooks/use-query'; | ||
import { updateQueryParams } from '../../import/util'; | ||
|
||
export function useInitialQueryRun( siteId: number | undefined ) { | ||
const currentSearchParams = useQuery(); | ||
const [ runImportInitially, setRunImportInitially ] = useState( false ); | ||
|
||
useEffect( checkInitialRunState, [ siteId ] ); | ||
|
||
function checkInitialRunState() { | ||
// run query param indicates that the import process can be run immediately, | ||
// but before proceeding, remove it from the URL path | ||
// because of the browser's back or refresh edge cases | ||
if ( currentSearchParams.get( 'run' ) === 'true' ) { | ||
setRunImportInitially( true ); | ||
currentSearchParams.delete( 'run' ); | ||
updateQueryParams( currentSearchParams.toString() ); | ||
} | ||
} | ||
|
||
return runImportInitially; | ||
} |
90 changes: 90 additions & 0 deletions
90
.../stepper/declarative-flow/internals/steps-repository/importer/hooks/use-step-navigator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { addQueryArgs } from 'calypso/lib/route'; | ||
import { useCheckoutUrl } from 'calypso/signup/steps/import-from/hooks/use-checkout-url'; | ||
import { WPImportOption } from 'calypso/signup/steps/import-from/wordpress/types'; | ||
import { getWpOrgImporterUrl } from 'calypso/signup/steps/import/util'; | ||
import { StepPath } from '../../../steps-repository'; | ||
import { BASE_STEPPER_ROUTE } from '../../import/config'; | ||
import { removeLeadingSlash } from '../../import/util'; | ||
import type { NavigationControls } from '../../../types'; | ||
import type { StepNavigator } from 'calypso/signup/steps/import-from/types'; | ||
|
||
export function useStepNavigator( | ||
navigation: NavigationControls, | ||
siteId: number, | ||
siteSlug: string, | ||
fromSite: string | ||
): StepNavigator { | ||
const checkoutUrl = useCheckoutUrl( siteId as number, siteSlug as string ); | ||
|
||
function navigator( path: string ) { | ||
const stepPath = removeLeadingSlash( path.replace( BASE_STEPPER_ROUTE, '' ) ); | ||
navigation.goToStep?.( stepPath as StepPath ); | ||
} | ||
|
||
function goToIntentPage() { | ||
navigation.goToStep?.( 'intent' ); | ||
} | ||
|
||
function goToImportCapturePage() { | ||
navigation.goToStep?.( 'import' ); | ||
} | ||
|
||
function goToSiteViewPage() { | ||
navigation.submit?.( { | ||
type: 'redirect', | ||
url: `/view/${ siteSlug || '' }`, | ||
} ); | ||
} | ||
|
||
function goToCheckoutPage() { | ||
navigation.submit?.( { | ||
type: 'redirect', | ||
url: getCheckoutUrl(), | ||
} ); | ||
} | ||
|
||
function goToWpAdminImportPage() { | ||
navigation.submit?.( { | ||
type: 'redirect', | ||
url: `/import/${ siteSlug }`, | ||
} ); | ||
} | ||
|
||
function goToWpAdminWordPressPluginPage() { | ||
navigation.submit?.( { | ||
type: 'redirect', | ||
url: getWpOrgImporterUrl( siteSlug as string, 'wordpress' ), | ||
} ); | ||
} | ||
|
||
function getWordpressImportEverythingUrl(): string { | ||
const queryParams = { | ||
siteSlug: siteSlug, | ||
from: fromSite, | ||
option: WPImportOption.EVERYTHING, | ||
run: true, | ||
}; | ||
|
||
return addQueryArgs( queryParams, `/${ BASE_STEPPER_ROUTE }/importerWordpress` ); | ||
} | ||
|
||
function getCheckoutUrl() { | ||
const path = checkoutUrl; | ||
const queryParams = { | ||
redirect_to: getWordpressImportEverythingUrl(), | ||
cancel_to: getWordpressImportEverythingUrl(), | ||
}; | ||
|
||
return addQueryArgs( queryParams, path ); | ||
} | ||
|
||
return { | ||
goToIntentPage, | ||
goToImportCapturePage, | ||
goToSiteViewPage, | ||
goToCheckoutPage, | ||
goToWpAdminImportPage, | ||
goToWpAdminWordPressPluginPage, | ||
navigate: ( path ) => navigator( path ), | ||
}; | ||
} |
Oops, something went wrong.