Skip to content

Commit

Permalink
Import flows: Update logic for generating importer URL (unified impor…
Browse files Browse the repository at this point in the history
…ters) (#85150)

* Import flows: Update logic for generating importer URL (unified importers)

* Remove unnecessary param
  • Loading branch information
bogiii authored Dec 13, 2023
1 parent 2f6c9b9 commit 589b890
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useSelect } from '@wordpress/data';
import React, { useEffect } from 'react';
import { ReadyPreviewStep } from 'calypso/blocks/import/ready';
import { Step } from 'calypso/landing/stepper/declarative-flow/internals/types';
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { useSiteSlugParam } from 'calypso/landing/stepper/hooks/use-site-slug-param';
import { ONBOARD_STORE } from 'calypso/landing/stepper/stores';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
Expand All @@ -16,8 +15,6 @@ import type { OnboardSelect } from '@automattic/data-stores';
const ImportReadyPreview: Step = function ImportStep( props ) {
const { navigation } = props;
const siteSlug = useSiteSlugParam();
const site = useSite();
const isAtomicSite = !! site?.options?.is_automated_transfer;
const urlData = useSelector( getUrlData );
const isMigrateFromWp = useSelect(
( select ) => ( select( ONBOARD_STORE ) as OnboardSelect ).getIsMigrateFromWp(),
Expand Down Expand Up @@ -51,12 +48,7 @@ const ImportReadyPreview: Step = function ImportStep( props ) {
return;
}

const url = getFinalImporterUrl(
siteSlug as string,
urlData.url,
urlData.platform,
isAtomicSite
);
const url = getFinalImporterUrl( siteSlug as string, urlData.url, urlData.platform );

navigation.submit?.( { url } );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { ReadyStep } from 'calypso/blocks/import/ready';
import { Step } from 'calypso/landing/stepper/declarative-flow/internals/types';
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { useSiteSlugParam } from 'calypso/landing/stepper/hooks/use-site-slug-param';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { useSelector } from 'calypso/state';
Expand All @@ -13,8 +12,6 @@ import { getFinalImporterUrl } from '../import/helper';
const ImportReady: Step = function ImportStep( props ) {
const { navigation } = props;
const siteSlug = useSiteSlugParam();
const site = useSite();
const isAtomicSite = !! site?.options?.is_automated_transfer;
const urlData = useSelector( getUrlData );

/**
Expand All @@ -29,12 +26,7 @@ const ImportReady: Step = function ImportStep( props ) {
↓ Methods
*/
const goToImporterPage = () => {
const url = getFinalImporterUrl(
siteSlug as string,
urlData.url,
urlData.platform,
isAtomicSite
);
const url = getFinalImporterUrl( siteSlug as string, urlData.url, urlData.platform );

navigation.submit?.( { url, platform: urlData.platform } );
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,24 @@ import { BASE_ROUTE } from './config';
export function getFinalImporterUrl(
targetSlug: string,
fromSite: string,
platform: ImporterPlatform,
isAtomicSite: boolean | null
platform: ImporterPlatform
) {
let importerUrl;
const encodedFromSite = encodeURIComponent( fromSite );
// Escape WordPress, has two sub-flows "Import everything" and "Content only"
// firstly show import type chooser screen and then decide about importer url
if ( isAtomicSite && platform !== 'wordpress' ) {
importerUrl = getWpOrgImporterUrl( targetSlug, platform );
} else if (
[ 'blogger', 'medium', 'squarespace', 'wix', 'wordpress' ].some( ( targetPlatform ) => {
return (
platform === targetPlatform && isEnabled( `onboarding/import-from-${ targetPlatform }` )
);
} )
) {
importerUrl = getWpComOnboardingUrl( targetSlug, platform, encodedFromSite );
const productImporters = [ 'blogger', 'medium', 'substack', 'squarespace', 'wix', 'wordpress' ];

if ( productImporters.includes( platform ) ) {
importerUrl = isEnabled( `onboarding/import-from-${ platform }` )
? getWpComOnboardingUrl( targetSlug, platform, encodedFromSite )
: getImporterUrl( targetSlug, platform, encodedFromSite );

if ( platform === 'wordpress' && ! fromSite && isAtomicSite ) {
importerUrl = getWpOrgImporterUrl( targetSlug, platform );
} else if ( platform === 'wordpress' && ! fromSite ) {
if ( platform === 'wordpress' && ! fromSite ) {
importerUrl = addQueryArgs( importerUrl, {
option: WPImportOption.CONTENT_ONLY,
} );
}
} else {
importerUrl = getImporterUrl( targetSlug, platform, encodedFromSite );
importerUrl = getWpOrgImporterUrl( targetSlug, platform );
}

return importerUrl;
Expand Down

0 comments on commit 589b890

Please sign in to comment.