Skip to content

Commit

Permalink
Duplicate views: Redirect from Calypso to WP Admin (Posts, Testimonia…
Browse files Browse the repository at this point in the history
…ls, Portfolio) (#97231)
  • Loading branch information
mmtr authored and timur987 committed Dec 13, 2024
1 parent ef15cd3 commit c5aa3e6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 2 additions & 0 deletions client/controller/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => () => {};
19 changes: 18 additions & 1 deletion client/controller/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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();
};
3 changes: 2 additions & 1 deletion client/my-sites/posts/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion client/my-sites/site-settings/settings-writing/index.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -20,6 +31,7 @@ export default function () {
page(
'/settings/taxonomies/:taxonomy/:site_id',
siteSelection,
redirectIfDuplicatedView,
navigation,
setScroll,
taxonomies,
Expand Down
20 changes: 17 additions & 3 deletions client/my-sites/types/index.js
Original file line number Diff line number Diff line change
@@ -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' );
}

0 comments on commit c5aa3e6

Please sign in to comment.