Skip to content

Commit f8d762d

Browse files
authored
Post editor: Open support links in Help Center (#43883)
This commit ensures that the support links of the Excerpt and Tags panels in the WP.com post editor are opened directly in the Help Center rather than on a new tab.
1 parent 08c26bc commit f8d762d

File tree

10 files changed

+99
-72
lines changed

10 files changed

+99
-72
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Components: Add reusable link to open support articles in Help Center
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as JetpackEditorPanelLogo } from './jetpack-editor-panel-logo';
22
export { Nudge } from './upgrade-nudge';
3+
export { WpcomSupportLink } from './wpcom-support-link';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { ExternalLink } from '@wordpress/components';
2+
import { useDispatch } from '@wordpress/data';
3+
import React, { forwardRef } from 'react';
4+
5+
/**
6+
* Renders a link that opens a WP.com support article in the Help Center.
7+
*
8+
* @param {object} props - The component props.
9+
* @param {string} props.supportLink - Support link URL.
10+
* @param {number} props.supportPostId - Support post ID.
11+
* @param {React.Component} props.children - Support link content.
12+
* @param {Function} [props.onClick] - Callback function to be called when the link is clicked.
13+
* @param {object} [props.style] - CSS properties to be applied to the link.
14+
* @return {React.JSX.Element} The component to render.
15+
*/
16+
export const WpcomSupportLink = forwardRef(
17+
( { supportLink, supportPostId, children, onClick, style }, ref ) => {
18+
const helpCenterDispatch = useDispatch( 'automattic/help-center' );
19+
const setShowSupportDoc = helpCenterDispatch?.setShowSupportDoc;
20+
21+
if ( setShowSupportDoc ) {
22+
return (
23+
<a
24+
href={ supportLink }
25+
// eslint-disable-next-line react/jsx-no-bind
26+
onClick={ event => {
27+
event.preventDefault();
28+
onClick?.();
29+
setShowSupportDoc( supportLink, supportPostId );
30+
} }
31+
style={ style }
32+
ref={ ref }
33+
>
34+
{ children }
35+
</a>
36+
);
37+
}
38+
return (
39+
<ExternalLink href={ supportLink } onClick={ onClick } style={ style } ref={ ref }>
40+
{ children }
41+
</ExternalLink>
42+
);
43+
}
44+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Post editor: Open WP.com support articles in Help Center

projects/packages/jetpack-mu-wpcom/src/features/tags-education/tags-education.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { localizeUrl } from '@automattic/i18n-utils';
22
import { useAnalytics } from '@automattic/jetpack-shared-extension-utils';
3-
import { ExternalLink } from '@wordpress/components';
3+
import { WpcomSupportLink } from '@automattic/jetpack-shared-extension-utils/components';
44
import { createHigherOrderComponent } from '@wordpress/compose';
55
import { addFilter } from '@wordpress/hooks';
66

@@ -15,14 +15,15 @@ const addTagsEducationLink = createHigherOrderComponent( PostTaxonomyType => {
1515
return (
1616
<>
1717
<PostTaxonomyType { ...props } />
18-
<ExternalLink
19-
href={ localizeUrl( 'https://wordpress.com/support/posts/tags/' ) }
18+
<WpcomSupportLink
19+
supportLink={ localizeUrl( 'https://wordpress.com/support/posts/tags/' ) }
20+
supportPostId={ 8586 }
2021
onClick={ () => {
2122
tracks.recordEvent( 'jetpack_mu_wpcom_tags_education_link_click' );
2223
} }
2324
>
2425
{ window.wpcomTagsEducation.actionText }
25-
</ExternalLink>
26+
</WpcomSupportLink>
2627
</>
2728
);
2829
};

projects/packages/jetpack-mu-wpcom/src/features/wpcom-block-description-links/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import blockInfoMapping, {
66
blockInfoWithVariations,
77
childrenBlockInfoWithDifferentUrl,
88
} from './src/block-links-map';
9-
import DescriptionSupportLink from './src/inline-support-link';
9+
import DescriptionSupportLink from './src/description-support-link';
1010

1111
const createLocalizedDescriptionWithLearnMore = (
1212
title: string,
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { localizeUrl } from '@automattic/i18n-utils';
22
import { useAnalytics } from '@automattic/jetpack-shared-extension-utils';
3-
import { Button, ExternalLink } from '@wordpress/components';
4-
import { useDispatch } from '@wordpress/data';
3+
import { WpcomSupportLink } from '@automattic/jetpack-shared-extension-utils/components';
54
import { __ } from '@wordpress/i18n';
65
import React, { useState, JSXElementConstructor, ReactElement } from 'react';
76

@@ -33,9 +32,6 @@ export default function DescriptionSupportLink( {
3332
// Since there was no identifier in the environment to differentiate.
3433
const [ ref, setRef ] = useState< Element | null >();
3534
const { tracks } = useAnalytics();
36-
const helpCenterDispatch = useDispatch( 'automattic/help-center' );
37-
const setShowHelpCenter = helpCenterDispatch?.setShowHelpCenter;
38-
const setShowSupportDoc = helpCenterDispatch?.setShowSupportDoc;
3935

4036
if ( ref && ! ref?.closest( '.block-editor-block-inspector' ) ) {
4137
return children as React.JSX.Element;
@@ -45,39 +41,20 @@ export default function DescriptionSupportLink( {
4541
<>
4642
{ children }
4743
<br />
48-
{ setShowHelpCenter ? (
49-
<Button
50-
onClick={ () => {
51-
setShowHelpCenter( true );
52-
setShowSupportDoc( localizeUrl( url ), postId );
53-
tracks.recordEvent( 'jetpack_mu_wpcom_block_description_support_link_click', {
54-
block: title,
55-
support_link: url,
56-
} );
57-
} }
58-
style={ { marginTop: 10, height: 'unset' } }
59-
ref={ reference => ref !== reference && setRef( reference ) }
60-
className="fse-inline-support-link is-compact"
61-
variant="link"
62-
>
63-
{ __( 'Block guide', 'jetpack-mu-wpcom' ) }
64-
</Button>
65-
) : (
66-
<ExternalLink
67-
onClick={ () => {
68-
tracks.recordEvent( 'jetpack_mu_wpcom_block_description_support_link_click', {
69-
block: title,
70-
support_link: url,
71-
} );
72-
} }
73-
ref={ reference => ref !== reference && setRef( reference ) }
74-
style={ { display: 'block', marginTop: 10, maxWidth: 'fit-content' } }
75-
className="fse-inline-support-link"
76-
href={ url }
77-
>
78-
{ __( 'Learn more', 'jetpack-mu-wpcom' ) }
79-
</ExternalLink>
80-
) }
44+
<WpcomSupportLink
45+
supportLink={ localizeUrl( url ) }
46+
supportPostId={ postId }
47+
onClick={ () => {
48+
tracks.recordEvent( 'jetpack_mu_wpcom_block_description_support_link_click', {
49+
block: title,
50+
support_link: url,
51+
} );
52+
} }
53+
style={ { display: 'block', marginTop: 10, maxWidth: 'fit-content' } }
54+
ref={ reference => ref !== reference && setRef( reference ) }
55+
>
56+
{ __( 'Block guide', 'jetpack-mu-wpcom' ) }
57+
</WpcomSupportLink>
8158
</>
8259
);
8360
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
Post editor: Open WP.com support articles in Help Center

projects/plugins/jetpack/extensions/plugins/ai-content-lens/extend/ai-post-excerpt/index.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
isSimpleSite,
1212
useAnalytics,
1313
} from '@automattic/jetpack-shared-extension-utils';
14+
import { WpcomSupportLink } from '@automattic/jetpack-shared-extension-utils/components';
1415
import { TextareaControl, ExternalLink, Button, Notice, BaseControl } from '@wordpress/components';
1516
import { useDispatch, useSelect } from '@wordpress/data';
1617
import {
@@ -218,12 +219,6 @@ ${ postContent }
218219

219220
const { requireUpgrade, isOverLimit } = useAiFeature();
220221

221-
// Set the docs link depending on the site type
222-
const docsLink =
223-
isAtomicSite() || isSimpleSite()
224-
? __( 'https://wordpress.com/support/excerpts/', 'jetpack' )
225-
: __( 'https://jetpack.com/support/create-better-post-excerpts-with-ai/', 'jetpack' );
226-
227222
return (
228223
<div className="jetpack-ai-post-excerpt">
229224
<TextareaControl
@@ -235,9 +230,23 @@ ${ postContent }
235230
disabled={ isTextAreaDisabled }
236231
/>
237232

238-
<ExternalLink href={ docsLink }>
239-
{ __( 'Learn more about manual excerpts', 'jetpack' ) }
240-
</ExternalLink>
233+
{ isAtomicSite() || isSimpleSite() ? (
234+
<WpcomSupportLink
235+
supportLink={ __( 'https://wordpress.com/support/excerpts/', 'jetpack' ) }
236+
supportPostId={ 1569 }
237+
>
238+
{ __( 'Learn more about manual excerpts', 'jetpack' ) }
239+
</WpcomSupportLink>
240+
) : (
241+
<ExternalLink
242+
href={ __(
243+
'https://jetpack.com/support/create-better-post-excerpts-with-ai/',
244+
'jetpack'
245+
) }
246+
>
247+
{ __( 'Learn more about manual excerpts', 'jetpack' ) }
248+
</ExternalLink>
249+
) }
241250

242251
<div className="jetpack-generated-excerpt__ai-container">
243252
{ error?.code && error.code !== 'error_quota_exceeded' && (

projects/plugins/jetpack/extensions/plugins/seo/components/upsell.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useAnalytics, useUpgradeFlow } from '@automattic/jetpack-shared-extension-utils';
2-
import { Button, ExternalLink } from '@wordpress/components';
3-
import { useDispatch } from '@wordpress/data';
2+
import { WpcomSupportLink } from '@automattic/jetpack-shared-extension-utils/components';
3+
import { Button } from '@wordpress/components';
44
import { __, sprintf } from '@wordpress/i18n';
55
import { external } from '@wordpress/icons';
66
import clsx from 'clsx';
@@ -23,10 +23,6 @@ const UpsellNotice = ( { requiredPlan } ) => {
2323
goToCheckoutPage( event );
2424
};
2525

26-
const helpCenterDispatch = useDispatch( 'automattic/help-center' );
27-
const setShowHelpCenter = helpCenterDispatch?.setShowHelpCenter;
28-
const setShowSupportDoc = helpCenterDispatch?.setShowSupportDoc;
29-
3026
return (
3127
<>
3228
<div>
@@ -38,20 +34,7 @@ const UpsellNotice = ( { requiredPlan } ) => {
3834
</div>
3935

4036
<div className="components-seo-upsell__learn-more">
41-
{ setShowHelpCenter ? (
42-
<Button
43-
onClick={ () => {
44-
setShowHelpCenter( true );
45-
setShowSupportDoc( supportUrl );
46-
} }
47-
className="components-seo-upsell__learn-more-link"
48-
variant="link"
49-
>
50-
{ supportLinkTitle }
51-
</Button>
52-
) : (
53-
<ExternalLink href={ supportUrl }>{ supportLinkTitle }</ExternalLink>
54-
) }
37+
<WpcomSupportLink url={ supportUrl } postId={ 120916 } text={ supportLinkTitle } />
5538
</div>
5639

5740
<Button

0 commit comments

Comments
 (0)