diff --git a/client/controller/index.node.js b/client/controller/index.node.js index f2fe030dd016bd..b9e4dc56b75e15 100644 --- a/client/controller/index.node.js +++ b/client/controller/index.node.js @@ -93,3 +93,5 @@ export const render = ( context ) => {}; export const ProviderWrappedLayout = () => null; export const notFound = () => null; export const setSelectedSiteIdByOrigin = () => {}; +// eslint-disable-next-line no-unused-vars +export const redirectIfDuplicatedView = ( wpAdminPath ) => () => {}; diff --git a/client/controller/index.web.js b/client/controller/index.web.js index b422d1db5b7762..b327e80155b55a 100644 --- a/client/controller/index.web.js +++ b/client/controller/index.web.js @@ -16,6 +16,7 @@ import MomentProvider from 'calypso/components/localized-moment/provider'; import { RouteProvider } from 'calypso/components/route'; import Layout from 'calypso/layout'; import LayoutLoggedOut from 'calypso/layout/logged-out'; +import { loadExperimentAssignment } from 'calypso/lib/explat'; import { navigate } from 'calypso/lib/navigate'; import { createAccountUrl, login } from 'calypso/lib/paths'; import { CalypsoReactQueryDevtools } from 'calypso/lib/react-query-devtools-helper'; @@ -32,7 +33,7 @@ import { import { canCurrentUser } from 'calypso/state/selectors/can-current-user'; import { getSiteAdminUrl, getSiteHomeUrl, getSiteOption } from 'calypso/state/sites/selectors'; import { setSelectedSiteId } from 'calypso/state/ui/actions/set-sites.js'; -import { getSelectedSite } from 'calypso/state/ui/selectors'; +import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors'; import { makeLayoutMiddleware } from './shared.js'; import { hydrate, render } from './web-util.js'; @@ -390,3 +391,19 @@ export const setSelectedSiteIdByOrigin = ( context, next ) => { export const ssrSetupLocale = ( _context, next ) => { next(); }; + +export const redirectIfDuplicatedView = ( wpAdminPath ) => async ( context, next ) => { + const duplicateViewsExperimentAssignment = await loadExperimentAssignment( + 'calypso_duplicate_views_placeholder' + ); + if ( duplicateViewsExperimentAssignment.variationName === 'treatment' ) { + const state = context.store.getState(); + const siteId = getSelectedSiteId( state ); + const wpAdminUrl = getSiteAdminUrl( state, siteId, wpAdminPath ); + if ( wpAdminUrl ) { + window.location = wpAdminUrl; + return; + } + } + next(); +}; diff --git a/client/my-sites/posts/index.js b/client/my-sites/posts/index.js index b19de141134e02..b10c964bddb81b 100644 --- a/client/my-sites/posts/index.js +++ b/client/my-sites/posts/index.js @@ -1,5 +1,5 @@ import page from '@automattic/calypso-router'; -import { makeLayout, render as clientRender } from 'calypso/controller'; +import { makeLayout, render as clientRender, redirectIfDuplicatedView } from 'calypso/controller'; import { getSiteFragment } from 'calypso/lib/route'; import { navigation, siteSelection } from 'calypso/my-sites/controller'; import postsController from './controller'; @@ -8,6 +8,7 @@ export default function () { page( '/posts/:author(my)?/:status(published|drafts|scheduled|trashed)?/:domain?', siteSelection, + redirectIfDuplicatedView( 'edit.php' ), navigation, postsController.posts, makeLayout, diff --git a/client/my-sites/site-settings/settings-writing/index.js b/client/my-sites/site-settings/settings-writing/index.js index 89dc910fc870d6..3c0c55602df135 100644 --- a/client/my-sites/site-settings/settings-writing/index.js +++ b/client/my-sites/site-settings/settings-writing/index.js @@ -1,9 +1,20 @@ import page from '@automattic/calypso-router'; -import { makeLayout, render as clientRender } from 'calypso/controller'; +import { + makeLayout, + render as clientRender, + redirectIfDuplicatedView as _redirectIfDuplicatedView, +} from 'calypso/controller'; import { navigation, siteSelection, sites } from 'calypso/my-sites/controller'; import { setScroll, siteSettings } from 'calypso/my-sites/site-settings/settings-controller'; import { taxonomies, writing } from './controller'; +const redirectIfDuplicatedView = ( context, next ) => { + _redirectIfDuplicatedView( `edit-tags.php?taxonomy=${ context.params.taxonomy }` )( + context, + next + ); +}; + export default function () { page( '/settings/writing/:site_id', @@ -20,6 +31,7 @@ export default function () { page( '/settings/taxonomies/:taxonomy/:site_id', siteSelection, + redirectIfDuplicatedView, navigation, setScroll, taxonomies, diff --git a/client/my-sites/types/index.js b/client/my-sites/types/index.js index 078485bf5c12ae..19776fea061fce 100644 --- a/client/my-sites/types/index.js +++ b/client/my-sites/types/index.js @@ -1,9 +1,23 @@ -import { makeLayout } from 'calypso/controller'; +import { + makeLayout, + redirectIfDuplicatedView as _redirectIfDuplicatedView, +} from 'calypso/controller'; import { siteSelection, navigation, sites } from 'calypso/my-sites/controller'; import { list } from './controller'; +const redirectIfDuplicatedView = ( context, next ) => { + _redirectIfDuplicatedView( `edit.php?post_type=${ context.params.type }` )( context, next ); +}; + export default function ( router ) { - router( '/types/:type/:status?/:site', siteSelection, navigation, list, makeLayout ); - router( '/types/:type', siteSelection, sites, makeLayout ); + router( + '/types/:type/:status?/:site', + siteSelection, + redirectIfDuplicatedView, + navigation, + list, + makeLayout + ); + router( '/types/:type', siteSelection, redirectIfDuplicatedView, sites, makeLayout ); router( '/types', '/posts' ); }