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

Add a GS limit notice in the Global Styles sidebar #74510

Merged
merged 24 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1fee108
Add a GS limit notice in the Global Styles Root Screen
BogdanUngureanu Mar 16, 2023
b804958
Moved useGlobalStylesConfig in a js file so we can bypass the TS erro…
BogdanUngureanu Mar 20, 2023
9a9f0e5
Merge branch 'trunk' into add/global-styles-notice
BogdanUngureanu Mar 23, 2023
302cad5
Add the upgrade nudge using the ComplementaryArea slot.
BogdanUngureanu Mar 23, 2023
22ec730
Added comment explaining why we are doing the condition check inside …
BogdanUngureanu Mar 24, 2023
86c882c
Refactor the implementation based on code review feedback.
BogdanUngureanu Mar 31, 2023
ab25a9f
Merge branch 'trunk' into add/global-styles-notice
BogdanUngureanu Mar 31, 2023
a81ba6a
Add blog_id property in the tracks events.
BogdanUngureanu Mar 31, 2023
222b376
Remove redundant else branch.
BogdanUngureanu Mar 31, 2023
f3e0d79
Rename the event functions and change copy
BogdanUngureanu Mar 31, 2023
b979e46
Add return type and make the component default.
BogdanUngureanu Mar 31, 2023
06eefdf
Update apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-style…
BogdanUngureanu Mar 31, 2023
4dfc39d
Fix the Fill hard reset when the nudge appears and disappears the fir…
BogdanUngureanu Mar 31, 2023
3eced05
Add docblock explaining why we need the fragment.
BogdanUngureanu Mar 31, 2023
daee364
Merge branch 'trunk' into add/global-styles-notice
BogdanUngureanu Apr 3, 2023
e8c08ba
Update apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-style…
BogdanUngureanu Apr 3, 2023
8318b9c
Update apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-style…
BogdanUngureanu Apr 3, 2023
946907a
Changed the background color in the test trying to fix the failure.
BogdanUngureanu Apr 3, 2023
05269ff
Try to fix the failing test (take 2).
BogdanUngureanu Apr 3, 2023
dddc04b
Remove filter
BogdanUngureanu Apr 3, 2023
76a8131
Add cache clear.
BogdanUngureanu Apr 3, 2023
ff9f7ec
Pass the theme directly.
BogdanUngureanu Apr 3, 2023
eb5d520
Try to fix the failing test.
BogdanUngureanu Apr 3, 2023
f9c8484
Fix unit test
mmtr Apr 3, 2023
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,52 @@
declare const wpcomGlobalStyles: { upgradeUrl: string };

import { ExternalLink, Fill, Notice } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { createInterpolateElement, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useGlobalStylesConfig } from './use-global-styles-config';
import { recordUpgradeNoticeClick, recordUpgradeNoticeShow } from './utils';

const GLOBAL_STYLES_SIDEBAR = 'edit-site/global-styles';

export function GlobalStylesSidebarNotice() {
const area = useSelect(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
( select ) => select( 'core/interface' ).getActiveComplementaryArea( 'core/edit-site' ),
[]
);

const isGlobalStylesSidebar = GLOBAL_STYLES_SIDEBAR === area;

const isVisible = useGlobalStylesConfig().isVisible;

useEffect( () => {
if ( isVisible && isGlobalStylesSidebar ) {
recordUpgradeNoticeShow( GLOBAL_STYLES_SIDEBAR );
}
}, [ isVisible, isGlobalStylesSidebar ] );

return (
<Fill name="ComplementaryArea/core/edit-site">
{ !! isVisible && isGlobalStylesSidebar && (
<div className="interface-complementary-area">
<Notice status="warning" isDismissible={ false } className="wpcom-global-styles-notice">
{ createInterpolateElement(
__( '<a>Upgrade your plan</a> to keep your style changes.', 'full-site-editing' ),
{
a: (
<ExternalLink
href={ wpcomGlobalStyles.upgradeUrl }
target="_blank"
onClick={ () => recordUpgradeNoticeClick( GLOBAL_STYLES_SIDEBAR ) }
/>
),
}
) }
</Notice>
</div>
) }
</Fill>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './public-path';

import domReady from '@wordpress/dom-ready';
import { registerPlugin } from '@wordpress/plugins';
import { GlobalStylesSidebarNotice } from './global-style-sidebar-notice';
import GlobalStylesModal from './modal';
import GlobalStylesNotice from './notice';
import './store';
Expand All @@ -13,6 +14,7 @@ const showGlobalStylesComponents = () => {
<>
<GlobalStylesModal />
<GlobalStylesNotice />
<GlobalStylesSidebarNotice />
</>
),
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,14 @@
/* global wpcomGlobalStyles */
import { recordTracksEvent } from '@automattic/calypso-analytics';
import { ExternalLink, Notice } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { createInterpolateElement, render, useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

import './notice.scss';
import { useGlobalStylesConfig } from './use-global-styles-config';
import { recordUpgradeNoticeClick, recordUpgradeNoticeShow } from './utils';

function GlobalStylesNoticeComponent() {
const { globalStylesConfig, siteChanges } = useSelect( ( select ) => {
const {
getEditedEntityRecord,
__experimentalGetCurrentGlobalStylesId,
__experimentalGetDirtyEntityRecords,
} = select( 'core' );

const _globalStylesId = __experimentalGetCurrentGlobalStylesId
? __experimentalGetCurrentGlobalStylesId()
: null;
const globalStylesRecord = getEditedEntityRecord( 'root', 'globalStyles', _globalStylesId );

return {
globalStylesConfig: {
styles: globalStylesRecord?.styles ?? {},
settings: globalStylesRecord?.settings ?? {},
},
siteChanges: __experimentalGetDirtyEntityRecords ? __experimentalGetDirtyEntityRecords() : [],
};
}, [] );

// Do not show the notice if the use is trying to save the default styles.
const isVisible =
Object.keys( globalStylesConfig.styles ).length ||
Object.keys( globalStylesConfig.settings ).length;
const { siteChanges, isVisible } = useGlobalStylesConfig();

// Closes the sidebar if there are no more changes to be saved.
useEffect( () => {
Expand All @@ -51,9 +27,7 @@ function GlobalStylesNoticeComponent() {

useEffect( () => {
if ( isVisible ) {
recordTracksEvent( 'calypso_global_styles_gating_notice_show', {
context: 'site-editor',
} );
recordUpgradeNoticeShow( 'site-editor' );
}
}, [ isVisible ] );

Expand All @@ -73,11 +47,7 @@ function GlobalStylesNoticeComponent() {
<ExternalLink
href={ wpcomGlobalStyles.upgradeUrl }
target="_blank"
onClick={ () =>
recordTracksEvent( 'calypso_global_styles_gating_notice_upgrade_click', {
context: 'site-editor',
} )
}
onClick={ () => recordUpgradeNoticeClick( 'site-editor' ) }
/>
),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useSelect } from '@wordpress/data';

export function useGlobalStylesConfig() {
return useSelect( ( select ) => {
const {
getEditedEntityRecord,
__experimentalGetCurrentGlobalStylesId,
__experimentalGetDirtyEntityRecords,
} = select( 'core' );

const _globalStylesId = __experimentalGetCurrentGlobalStylesId
? __experimentalGetCurrentGlobalStylesId()
: null;
const globalStylesRecord = getEditedEntityRecord( 'root', 'globalStyles', _globalStylesId );

const globalStylesConfig = {
styles: globalStylesRecord?.styles ?? {},
settings: globalStylesRecord?.settings ?? {},
};

// Do not show the notice if the use is trying to save the default styles.
const isVisible =
Object.keys( globalStylesConfig.styles ).length ||
Object.keys( globalStylesConfig.settings ).length;

return {
globalStylesConfig,
isVisible,
siteChanges: __experimentalGetDirtyEntityRecords ? __experimentalGetDirtyEntityRecords() : [],
};
}, [] );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { recordTracksEvent } from '@automattic/calypso-analytics';

export function recordUpgradeNoticeClick( context: string ): void {
recordTracksEvent( 'calypso_global_styles_gating_notice_upgrade_click', {
context,
} );
}

export function recordUpgradeNoticeShow( context: string ): void {
recordTracksEvent( 'calypso_global_styles_gating_notice_show', {
context,
} );
}