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

Social | Hide irrelevant UI on social admin page #41393

Open
wants to merge 31 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2e90863
Hide Social Notes if Social plugin is not active
manzoorwanijk Jan 29, 2025
abfbd5a
Hide connection screen and pricing page for WPCOM
manzoorwanijk Jan 29, 2025
ccc53f6
Hide upgrade nudge for WPCOM
manzoorwanijk Jan 29, 2025
d0c1801
Add safe fallbacks for settings selectors for WPCOM
manzoorwanijk Jan 29, 2025
eca5d9e
Hide shares data on WPCOM
manzoorwanijk Jan 29, 2025
1980c2a
Hide plugin footer on WPCOM
manzoorwanijk Jan 29, 2025
f1f7850
Hide license notice for WPCOM
manzoorwanijk Jan 29, 2025
70f0e22
Hide publicize toggle on WPCOM
manzoorwanijk Jan 29, 2025
c88feec
Hide UTM toggle for now on WPCOM
manzoorwanijk Jan 29, 2025
54d6e49
Merge branch 'trunk' into update/social-hide-irrelevant-ui-on-admin-page
manzoorwanijk Jan 29, 2025
f106652
Merge branch 'trunk' into update/social-hide-irrelevant-ui-on-admin-page
manzoorwanijk Jan 30, 2025
50207a9
Revert "Hide UTM toggle for now on WPCOM"
manzoorwanijk Jan 30, 2025
2c324fe
Merge branch 'trunk' into update/social-hide-irrelevant-ui-on-admin-page
manzoorwanijk Jan 30, 2025
bd56a9b
Merge branch 'trunk' into update/social-hide-irrelevant-ui-on-admin-page
manzoorwanijk Jan 31, 2025
05133f4
Fix unit tests
manzoorwanijk Jan 31, 2025
e580c5f
Merge branch 'trunk' into update/social-hide-irrelevant-ui-on-admin-page
manzoorwanijk Jan 31, 2025
c126920
Merge branch 'trunk' into update/social-hide-irrelevant-ui-on-admin-page
manzoorwanijk Jan 31, 2025
45ff34b
Merge branch 'trunk' into update/social-hide-irrelevant-ui-on-admin-page
manzoorwanijk Jan 31, 2025
bf1f14d
Adjust the WPCOM test and display of the toggle section.
pablinos Feb 2, 2025
35ba633
Merge remote-tracking branch 'origin/trunk' into update/social-hide-i…
pablinos Feb 2, 2025
b244130
Adjust styling and fix selector name.
pablinos Feb 2, 2025
0d7f208
Add dummy arg to avoid optimisation problems.
pablinos Feb 3, 2025
e0bb04f
Create our helper function
gmjuhasz Feb 3, 2025
76588a3
Hide everything that's not self hosted
gmjuhasz Feb 3, 2025
f4d39a6
Move util to script data package
gmjuhasz Feb 3, 2025
ef62856
changelog
gmjuhasz Feb 3, 2025
fa4a2ba
Clean up function
gmjuhasz Feb 3, 2025
abafa4c
Use function in admin page
gmjuhasz Feb 3, 2025
8bcd8f5
Update support doc link and general publicize help link
gmjuhasz Feb 3, 2025
ae761c7
Fix selector to check that the module is active.
pablinos Feb 3, 2025
ec669e8
Swap to using _x rather than a dummy arg to fix the optimisation
pablinos Feb 4, 2025
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
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Hide Social Notes if Social plugin is not active
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { __ } from '@wordpress/i18n';
import { Icon, postList } from '@wordpress/icons';
import { store as socialStore } from '../../../social-store';
import { getSocialScriptData } from '../../../utils';
import { getSharedPostsCount, getTotalSharesCount } from '../../../utils/shares-data';
import {
getSharedPostsCount,
getTotalSharesCount,
isShareLimitEnabled,
} from '../../../utils/shares-data';
import StatCards from './stat-cards';
import styles from './styles.module.scss';

Expand All @@ -22,7 +26,7 @@ const Header = () => {
const store = select( socialStore );
return {
hasConnections: store.getConnections().length > 0,
isModuleEnabled: select( socialStore ).getSocialModuleSettings().publicize,
isModuleEnabled: store.getSocialModuleSettings().publicize_active,
};
} );

Expand Down Expand Up @@ -76,22 +80,24 @@ const Header = () => {
</Button>
</div>
</Col>
<Col sm={ 4 } md={ 4 } lg={ { start: 7, end: 12 } }>
<StatCards
stats={ [
{
icon: <SocialIcon />,
label: __( 'Total shares past 30 days', 'jetpack-publicize-components' ),
value: formatter.format( getTotalSharesCount() ),
},
{
icon: <Icon icon={ postList } />,
label: __( 'Posted this month', 'jetpack-publicize-components' ),
value: formatter.format( getSharedPostsCount() ),
},
] }
/>
</Col>
{ isShareLimitEnabled() ? (
pablinos marked this conversation as resolved.
Show resolved Hide resolved
<Col sm={ 4 } md={ 4 } lg={ { start: 7, end: 12 } }>
<StatCards
stats={ [
{
icon: <SocialIcon />,
label: __( 'Total shares past 30 days', 'jetpack-publicize-components' ),
value: formatter.format( getTotalSharesCount() ),
},
{
icon: <Icon icon={ postList } />,
label: __( 'Posted this month', 'jetpack-publicize-components' ),
value: formatter.format( getSharedPostsCount() ),
},
] }
/>
</Col>
) : null }
</Container>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GlobalNotices,
} from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { siteHasFeature } from '@automattic/jetpack-script-data';
import { getScriptData, siteHasFeature } from '@automattic/jetpack-script-data';
import { useSelect } from '@wordpress/data';
import { useState, useCallback } from '@wordpress/element';
import { store as socialStore } from '../../social-store';
Expand All @@ -25,8 +25,12 @@ import SocialNotesToggle from './toggles/social-notes-toggle';
import UtmToggle from './toggles/utm-toggle';

export const SocialAdminPage = () => {
const is_wpcom = getScriptData().site.host === 'wpcom';
const is_woa = getScriptData().site.host === 'woa';

const { isUserConnected, isRegistered } = useConnection();
const showConnectionCard = ! isRegistered || ! isUserConnected;
const showConnectionCard = ! is_wpcom && ( ! isRegistered || ! isUserConnected );

const [ forceDisplayPricingPage, setForceDisplayPricingPage ] = useState( false );

const onPricingPageDismiss = useCallback( () => setForceDisplayPricingPage( false ), [] );
Expand All @@ -42,9 +46,9 @@ export const SocialAdminPage = () => {
};
}, [] );

const pluginVersion = getSocialScriptData().plugin_info.social.version;
const socialPluginVersion = getSocialScriptData().plugin_info.social.version;

const moduleName = `Jetpack Social ${ pluginVersion }`;
const moduleName = `Jetpack Social ${ socialPluginVersion }`;

if ( showConnectionCard ) {
return (
Expand All @@ -59,9 +63,10 @@ export const SocialAdminPage = () => {
}

return (
<AdminPage moduleName={ moduleName } header={ <AdminPageHeader /> }>
<AdminPage moduleName={ moduleName } header={ <AdminPageHeader /> } showFooter={ ! is_wpcom }>
<GlobalNotices />
{ ( ! hasSocialPaidFeatures() && showPricingPage ) || forceDisplayPricingPage ? (
{ ( ! is_wpcom && ! is_woa && ! hasSocialPaidFeatures() && showPricingPage ) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we probably shouldn't show the pricing page on WoA either. I think we can see the plan there, but it would make for a more consistent experience.

forceDisplayPricingPage ? (
<AdminSectionHero>
<Container horizontalSpacing={ 3 } horizontalGap={ 3 }>
<Col>
Expand All @@ -77,7 +82,12 @@ export const SocialAdminPage = () => {
<AdminSection>
<SocialModuleToggle />
{ isModuleEnabled && <UtmToggle /> }
{ isModuleEnabled && <SocialNotesToggle disabled={ isUpdatingJetpackSettings } /> }
{
// Only show the Social Notes toggle if Social plugin is active
socialPluginVersion && isModuleEnabled && (
<SocialNotesToggle disabled={ isUpdatingJetpackSettings } />
)
}
{ isModuleEnabled && siteHasFeature( features.IMAGE_GENERATOR ) && (
<SocialImageGeneratorToggle disabled={ isUpdatingJetpackSettings } />
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ import { hasSocialPaidFeatures } from '../../../utils';
import Logo from './logo';
import styles from './styles.module.scss';

/**
* @type {Array<import('@automattic/jetpack-script-data').AdminSiteData['host']>}
*/
const HIDE_LICENSE_UI_FOR = [ 'woa', 'wpcom' ];

const AdminPageHeader = () => {
const activateLicenseUrl = getMyJetpackUrl( '#/add-license' );
const showLicenceUi = ! HIDE_LICENSE_UI_FOR.includes( getScriptData().site.host );

return (
<div className={ styles.header }>
<span className={ styles.logo }>
<Logo />
</span>

{ ! hasSocialPaidFeatures() && getScriptData().site.host !== 'woa' && (
{ ! hasSocialPaidFeatures() && showLicenceUi && (
<p>
{ createInterpolateElement(
__(
'Already have an existing plan or license key? <a>Click here to get started</a>',
'jetpack-publicize-components'
),
{
a: <a href={ activateLicenseUrl } />,
a: <a href={ getMyJetpackUrl( '#/add-license' ) } />,
}
) }
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ describe( 'load the app', () => {

beforeEach( () => {
window.JetpackScriptData = {
site: {
host: 'unknown',
},
social: {
api_paths: {},
plugin_info: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const SocialModuleToggle: React.FC = () => {
};
}, [] );

const blogID = getScriptData().site.wpcom.blog_id;
const siteSuffix = getScriptData().site.suffix;
const { wpcom, host, suffix: siteSuffix } = getScriptData().site;
const is_wpcom = host === 'wpcom';

const { urls, feature_flags } = getSocialScriptData();

Expand Down Expand Up @@ -79,6 +79,7 @@ const SocialModuleToggle: React.FC = () => {

return (
<ToggleSection
hideToggle={ is_wpcom }
title={ __(
'Automatically share your posts to social networks',
'jetpack-publicize-components'
Expand All @@ -88,22 +89,31 @@ const SocialModuleToggle: React.FC = () => {
onChange={ toggleModule }
>
<Text className={ styles.text }>
{ __(
'When enabled, you’ll be able to connect your social media accounts and send a post’s featured image and content to the selected channels with a single click when the post is published.',
'jetpack-publicize-components'
) }
{ ! is_wpcom
? __(
'When enabled, you’ll be able to connect your social media accounts and send a post’s featured image and content to the selected channels with a single click when the post is published.',
'jetpack-publicize-components',
/* dummy arg to avoid bad minification */ 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS won't be happy with this. A better solution will be to use __ in one string and _x in the other with some optional/empty context.

)
: __(
'Connect your social media accounts and send a post’s featured image and content to the selected channels with a single click when the post is published.',
'jetpack-publicize-components'
) }
&nbsp;
<ExternalLink href="https://jetpack.com/redirect/?source=social-plugin-publicize-support-admin-page">
<ExternalLink
href="https://jetpack.com/redirect/?source=social-plugin-publicize-support-admin-page"
className={ styles.learn }
>
{ __( 'Learn more', 'jetpack-publicize-components' ) }
</ExternalLink>
</Text>
{ ! hasSocialPaidFeatures() ? (
{ ! is_wpcom && ! hasSocialPaidFeatures() ? (
<ContextualUpgradeTrigger
className={ clsx( styles.cut, { [ styles.small ]: isSmall } ) }
description={ __( 'Unlock advanced sharing options', 'jetpack-publicize-components' ) }
cta={ __( 'Power up Jetpack Social', 'jetpack-publicize-components' ) }
href={ getRedirectUrl( 'jetpack-social-admin-page-upsell', {
site: `${ blogID ?? siteSuffix }`,
site: `${ wpcom.blog_id ?? siteSuffix }`,
query: 'redirect_to=admin.php?page=jetpack-social',
} ) }
tooltipText={ __(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@
grid-column: span 2;
}
}

.learn {
text-wrap: nowrap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
}
}

.column.notoggle {
grid-template-columns: 1fr 0;
> * {
grid-column: span 2;
}
}

.title {
grid-row: 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type ToggleSectionProps = {
* Children to be rendered inside the toggle.
*/
children: React.ReactNode;

/**
* Whether to hide the toggle.
*/
hideToggle?: boolean;
};

/**
Expand All @@ -51,17 +56,20 @@ const ToggleSection: React.FC< ToggleSectionProps > = ( {
checked,
disabled,
children,
hideToggle,
} ) => (
<Container horizontalSpacing={ 7 } horizontalGap={ 3 }>
<div className={ styles.column }>
<ToggleControl
label={ '' }
className={ styles.toggle }
disabled={ disabled }
checked={ checked }
onChange={ onChange }
__nextHasNoMarginBottom={ true }
/>
<div className={ `${ styles.column } ${ hideToggle ? styles.notoggle : '' }` }>
{ ! hideToggle && (
<ToggleControl
label={ '' }
className={ styles.toggle }
disabled={ disabled }
checked={ checked }
onChange={ onChange }
__nextHasNoMarginBottom={ true }
/>
) }
<Text className={ styles.title } variant="title-medium">
{ title }
{ beta && <div className={ styles.beta }>Beta</div> }
Expand Down
3 changes: 2 additions & 1 deletion projects/js-packages/publicize-components/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type SharesData = {
to_be_publicized_count: number;
publicized_count: number;
shared_posts_count: number;
is_share_limit_enabled: boolean;
};

export interface FeatureFlags {
Expand Down Expand Up @@ -44,7 +45,7 @@ export type SocialSettings = {
showPricingPage: boolean;
};

export type PluginInfo = Record< 'social' | 'jetpack', { version: string } >;
export type PluginInfo = Record< 'social' | 'jetpack', { version: string | null } >;

export interface SocialScriptData {
api_paths: ApiPaths;
Expand Down
12 changes: 12 additions & 0 deletions projects/js-packages/publicize-components/src/utils/shares-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@ export function getTotalSharesCount() {
export function getSharedPostsCount() {
return getSharesData().shared_posts_count ?? 0;
}

/**
* Get whether the sharing limits are enabled. This is partially
* irrelevant now as we have given the feature to all sites, but
* if the limits are enabled we count the shares made, and can
* display those stats.
*
* @return {boolean} Whether the sharing limits are enabled
*/
export function isShareLimitEnabled() {
return getSharesData().is_share_limit_enabled ?? false;
}
Loading