Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-apply "change add a menu link to point to the top level of customier" #55981

Merged
merged 1 commit into from
Sep 6, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import { getCurrentUser, isCurrentUserEmailVerified } from 'calypso/state/curren
import { CHECKLIST_KNOWN_TASKS } from 'calypso/state/data-layer/wpcom/checklist/index.js';
import { requestGuidedTour } from 'calypso/state/guided-tours/actions';
import getChecklistTaskUrls from 'calypso/state/selectors/get-checklist-task-urls';
import getMenusUrl from 'calypso/state/selectors/get-menus-url';
import getSiteChecklist from 'calypso/state/selectors/get-site-checklist';
import isUnlaunchedSite from 'calypso/state/selectors/is-unlaunched-site';
import { getSiteOption, getSiteSlug } from 'calypso/state/sites/selectors';
import { getSiteOption, getSiteSlug, getCustomizerUrl } from 'calypso/state/sites/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import CurrentTaskItem from './current-task-item';
import { getTask } from './get-task';
Expand Down Expand Up @@ -340,7 +339,7 @@ export default connect( ( state ) => {
firstIncompleteTask: taskList.getFirstIncompleteTask(),
isEmailUnverified: ! isCurrentUserEmailVerified( state ),
isPodcastingSite: !! getSiteOption( state, siteId, 'anchor_podcast' ),
menusUrl: getMenusUrl( state, siteId ),
menusUrl: getCustomizerUrl( state, siteId, null, null, 'add-menu' ),
siteId,
siteSlug: getSiteSlug( state, siteId ),
tasks: taskList.getAll(),
Expand Down
16 changes: 10 additions & 6 deletions client/state/sites/selectors/get-customizer-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import isJetpackSite from './is-jetpack-site';
/**
* Returns the customizer URL for a site, or null if it cannot be determined.
*
* @param {object} state Global state tree
* @param {?number} siteId Site ID
* @param {string} panel Optional panel to autofocus
* @param {string} returnUrl Optional return url for when the user closes the customizer
* @returns {string} Customizer URL
* @param {object} state Global state tree
* @param {?number} siteId Site ID
* @param {?string} panel Optional panel to autofocus
* @param {?string} returnUrl Optional return url for when the user closes the customizer
* @param {?string} guide Optional parameter to show a help guide in the customizer. possible values:
* 'add-menu' and 'social-media' show custom guides, any other value shows the default guide
* @returns {string} Customizer URL
*/
export default function getCustomizerUrl( state, siteId, panel, returnUrl ) {
export default function getCustomizerUrl( state, siteId, panel, returnUrl, guide ) {
if ( ! isJetpackSite( state, siteId ) ) {
const siteSlug = getSiteSlug( state, siteId );
const url = [ '' ].concat( [ 'customize', panel, siteSlug ].filter( Boolean ) ).join( '/' );
return addQueryArgs(
{
return: returnUrl,
guide,
},
url
);
Expand All @@ -39,6 +42,7 @@ export default function getCustomizerUrl( state, siteId, panel, returnUrl ) {
{
return: returnUrl,
...getCustomizerFocus( panel ),
guide,
},
adminUrl
);
Expand Down
49 changes: 49 additions & 0 deletions client/state/sites/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3157,6 +3157,55 @@ describe( 'selectors', () => {
);
} );

test( 'should prepend guide parameter for WordPress.com site', () => {
const customizerUrl = getCustomizerUrl(
{
sites: {
items: {
77203199: {
ID: 77203199,
URL: 'https://example.com',
jetpack: false,
},
},
},
},
77203199,
'identity',
null,
'test-guide'
);

chaiExpect( customizerUrl ).to.equal( '/customize/identity/example.com?guide=test-guide' );
} );

test( 'should prepend guide parameter for Jetpack site', () => {
const customizerUrl = getCustomizerUrl(
{
sites: {
items: {
77203199: {
ID: 77203199,
URL: 'https://example.com',
jetpack: true,
options: {
admin_url: 'https://example.com/wp-admin/',
},
},
},
},
},
77203199,
'identity',
null,
'test-guide'
);

chaiExpect( customizerUrl ).to.equal(
'https://example.com/wp-admin/customize.php?autofocus%5Bsection%5D=title_tagline&guide=test-guide'
);
} );

describe( 'browser', () => {
beforeAll( () => {
global.window = {
Expand Down