Skip to content

Commit

Permalink
Replace foundation with cornerstone
Browse files Browse the repository at this point in the history
  • Loading branch information
dilirity committed Oct 30, 2024
1 parent d4bdd66 commit 3c6bffa
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Meta from './meta/meta';
import SettingsItem from '$features/ui/settings-item/settings-item';
import Pill from '$features/ui/pill/pill';

const FoundationPages = () => {
const CornerstonePages = () => {
const { developmentFeatures } = Jetpack_Boost;

if ( ! developmentFeatures ) {
Expand All @@ -14,14 +14,14 @@ const FoundationPages = () => {
<SettingsItem
title={
<>
{ __( 'Foundation Pages', 'jetpack-boost' ) }
{ __( 'Cornerstone Pages', 'jetpack-boost' ) }
<Pill text="Experiment" />
</>
}
description={
<p>
{ __(
'List the most important pages of your site. They will be optimized. The Page Speed scores are based on the first foundation page.',
'List the most important pages of your site. They will be optimized. The Page Speed scores are based on the first cornerstone page.',
'jetpack-boost'
) }
</p>
Expand All @@ -32,4 +32,4 @@ const FoundationPages = () => {
);
};

export default FoundationPages;
export default CornerstonePages;
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { useDataSync } from '@automattic/jetpack-react-data-sync-client';
import { z } from 'zod';

/**
* Hook to get the Foundation Pages.
* Hook to get the Cornerstone Pages.
*/
export function useFoundationPages(): [
export function useCornerstonePages(): [
string[],
( newValue: string[], onSuccessCallback?: () => void ) => void,
] {
const [ { data }, { mutate } ] = useDataSync(
'jetpack_boost_ds',
'foundation_pages_list',
'cornerstone_pages_list',
z.array( z.string() )
);

Expand All @@ -23,16 +23,16 @@ export function useFoundationPages(): [
return [ data || [], updatePages ];
}

const FoundationPagesProperties = z.object( {
const CornerstonePagesProperties = z.object( {
max_pages: z.number(),
} );
type FoundationPagesProperties = z.infer< typeof FoundationPagesProperties >;
type CornerstonePagesProperties = z.infer< typeof CornerstonePagesProperties >;

export function useFoundationPagesProperties(): FoundationPagesProperties | undefined {
export function useCornerstonePagesProperties(): CornerstonePagesProperties | undefined {
const [ { data } ] = useDataSync(
'jetpack_boost_ds',
'foundation_pages_properties',
FoundationPagesProperties
'cornerstone_pages_properties',
CornerstonePagesProperties
);

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import ChevronUp from '$svg/chevron-up';
import React, { useEffect, useState } from 'react';
import clsx from 'clsx';
import styles from './meta.module.scss';
import { useFoundationPages, useFoundationPagesProperties } from '../lib/stores/foundation-pages';
import {
useCornerstonePages,
useCornerstonePagesProperties,
} from '../lib/stores/cornerstone-pages';
import { createInterpolateElement } from '@wordpress/element';
import { recordBoostEvent } from '$lib/utils/analytics';
import getSupportLink from '$lib/utils/get-support-link';
Expand All @@ -15,29 +18,29 @@ import { useNavigate } from 'react-router-dom';

const Meta = () => {
const [ isExpanded, setIsExpanded ] = useState( false );
const [ foundationPages, setFoundationPages ] = useFoundationPages();
const foundationPagesProperties = useFoundationPagesProperties();
const [ cornerstonePages, setCornerstonePages ] = useCornerstonePages();
const cornerstonePagesProperties = useCornerstonePagesProperties();
const [ { refetch: refetchRegenerationReason } ] = useRegenerationReason();
const premiumFeatures = usePremiumFeatures();
const isPremium = premiumFeatures.includes( 'support' );
const navigate = useNavigate();

const updateFoundationPages = ( newValue: string ) => {
const updateCornerstonePages = ( newValue: string ) => {
const newItems = newValue.split( '\n' ).map( line => line.trim() );

setFoundationPages( newItems, () => {
setCornerstonePages( newItems, () => {
refetchRegenerationReason();
} );
};

let content = null;

if ( foundationPagesProperties !== undefined ) {
if ( cornerstonePagesProperties !== undefined ) {
content = (
<List
items={ foundationPages.join( '\n' ) }
setItems={ updateFoundationPages }
maxItems={ foundationPagesProperties.max_pages }
items={ cornerstonePages.join( '\n' ) }
setItems={ updateCornerstonePages }
maxItems={ cornerstonePagesProperties.max_pages }
description={
<>
{ createInterpolateElement(
Expand All @@ -60,7 +63,7 @@ const Meta = () => {
<b>
{ createInterpolateElement(
__(
'Free users can add only one foundation page. <link>Upgrade to add more</link>.',
'Free users can add only one cornerstone page. <link>Upgrade to add more</link>.',
'jetpack-boost'
),
{
Expand All @@ -69,7 +72,7 @@ const Meta = () => {
<a
href="#/upgrade"
onClick={ () => {
recordBoostEvent( 'foundation_pages_upgrade_link_clicked', {} );
recordBoostEvent( 'cornerstone_pages_upgrade_link_clicked', {} );
navigate( '/upgrade' );
} }
/>
Expand Down Expand Up @@ -104,7 +107,7 @@ const Meta = () => {
target="_blank"
rel="noopener noreferrer"
onClick={ () => {
recordBoostEvent( 'foundation_pages_properties_failed', {} );
recordBoostEvent( 'cornerstone_pages_properties_failed', {} );
} }
/>
),
Expand All @@ -116,15 +119,15 @@ const Meta = () => {
}

return (
<div className={ styles.wrapper } data-testid="foundation-pages-meta">
<div className={ styles.wrapper } data-testid="cornerstone-pages-meta">
<div className={ styles.head }>
<div className={ styles.summary }>
{ foundationPagesProperties &&
{ cornerstonePagesProperties &&
sprintf(
/* translators: %1$d is the number of foundation pages added, %2$d is the maximum number allowed */
/* translators: %1$d is the number of cornerstone pages added, %2$d is the maximum number allowed */
__( '%1$d / %2$d added', 'jetpack-boost' ),
foundationPages.length,
foundationPagesProperties.max_pages
cornerstonePages.length,
cornerstonePagesProperties.max_pages
) }
</div>
<div className={ styles.actions }>
Expand Down Expand Up @@ -181,10 +184,10 @@ const List: React.FC< ListProps > = ( { items, setItems, maxItems, description }
// Check if the number of items exceeds maxItems
if ( lines.length > maxItems ) {
const message = sprintf(
/* translators: %d is the maximum number of foundation page URLs. */
/* translators: %d is the maximum number of cornerstone page URLs. */
_n(
'You can add only %d foundation page URL.',
'You can add up to %d foundation page URLs.',
'You can add only %d cornerstone page URL.',
'You can add up to %d cornerstone page URLs.',
maxItems,
'jetpack-boost'
),
Expand Down Expand Up @@ -232,7 +235,7 @@ const List: React.FC< ListProps > = ( { items, setItems, maxItems, description }
value={ inputValue }
rows={ inputRows }
onChange={ e => validateInputValue( e.target.value ) }
id="jb-foundation-pages"
id="jb-cornerstone-pages"
/>
{ inputInvalid && <p className={ styles.error }>{ validationError?.message }</p> }
{ description && <div className={ styles.description }>{ description }</div> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const allowedSuggestions = [
'post_saved',
'switched_theme',
'plugin_change',
'foundation_page_saved',
'foundation_pages_list_updated',
'cornerstone_page_saved',
'cornerstone_pages_list_updated',
] as const;

export type RegenerationReason = ( typeof allowedSuggestions )[ number ] | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ const suggestionMap: { [ key: string ]: string } = {
"We noticed you've recently updated a plugin that may affect your site's HTML/CSS structure.",
'jetpack-boost'
),
foundation_page_saved: __( 'A Foundation page was updated.', 'jetpack-boost' ),
foundation_pages_list_updated: __( 'The list of Foundation pages was updated.', 'jetpack-boost' ),
cornerstone_page_saved: __( 'A Cornerstone page was updated.', 'jetpack-boost' ),
cornerstone_pages_list_updated: __(
'The list of Cornerstone pages was updated.',
'jetpack-boost'
),
};

const getSuggestionMessage = ( type: RegenerationReason | null ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ContextTooltip = () => {
>
<p>
{ __(
"Your Overall Score is a summary of your first Foundation Page across both mobile and desktop devices. It gives a general idea of your site's overall performance.",
"Your Overall Score is a summary of your first Cornerstone Page across both mobile and desktop devices. It gives a general idea of your site's overall performance.",
'jetpack-boost'
) }
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { useLocalCriticalCssGeneratorStatus } from '$features/critical-css/local
import { queryClient } from '@automattic/jetpack-react-data-sync-client';
import ErrorBoundary from '$features/error-boundary/error-boundary';
import PopOut from './pop-out/pop-out';
import { useFoundationPages } from '$features/foundation-pages/lib/stores/foundation-pages';
import { useCornerstonePages } from '$features/cornerstone-pages/lib/stores/cornerstone-pages';

const SpeedScore = () => {
const [ foundationPages ] = useFoundationPages();
const [ cornerstonePages ] = useCornerstonePages();
const { site, developmentFeatures } = Jetpack_Boost;
const pageSpeedUrl =
developmentFeatures && foundationPages.length > 0 ? foundationPages[ 0 ] : site.url;
developmentFeatures && cornerstonePages.length > 0 ? cornerstonePages[ 0 ] : site.url;
const [ { status, error, scores }, loadScore ] = useSpeedScores( pageSpeedUrl );
const scoreLetter = scores ? getScoreLetter( scores.current.mobile, scores.current.desktop ) : '';
const showPrevScores = scores && didScoresChange( scores ) && ! scores.isStale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MinifyMeta from '$features/minify-meta/minify-meta';
import { QualitySettings, ImageCdnLiar } from '$features/image-cdn';
import styles from './index.module.scss';
import { RecommendationsMeta } from '$features/image-size-analysis';
import FoundationPages from '$features/foundation-pages/foundation-pages';
import CornerstonePages from '$features/cornerstone-pages/cornerstone-pages';
import { useRegenerateCriticalCssAction } from '$features/critical-css/lib/stores/critical-css-state';
import PremiumTooltip from '$features/premium-tooltip/premium-tooltip';
import Upgraded from '$features/ui/upgraded/upgraded';
Expand All @@ -38,7 +38,7 @@ const Index = () => {

return (
<div className="jb-container--narrow">
<FoundationPages />
<CornerstonePages />
<Module
slug="critical_css"
title={ __( 'Optimize Critical CSS Loading (manual)', 'jetpack-boost' ) }
Expand Down
6 changes: 3 additions & 3 deletions projects/plugins/boost/app/class-jetpack-boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
use Automattic\Jetpack_Boost\Lib\Analytics;
use Automattic\Jetpack_Boost\Lib\CLI;
use Automattic\Jetpack_Boost\Lib\Connection;
use Automattic\Jetpack_Boost\Lib\Cornerstone_Pages;
use Automattic\Jetpack_Boost\Lib\Critical_CSS\Critical_CSS_State;
use Automattic\Jetpack_Boost\Lib\Critical_CSS\Critical_CSS_Storage;
use Automattic\Jetpack_Boost\Lib\Critical_CSS\Generator;
use Automattic\Jetpack_Boost\Lib\Foundation_Pages;
use Automattic\Jetpack_Boost\Lib\Setup;
use Automattic\Jetpack_Boost\Lib\Site_Health;
use Automattic\Jetpack_Boost\Lib\Status;
Expand Down Expand Up @@ -109,8 +109,8 @@ public function __construct() {
$modules_setup = new Modules_Setup();
Setup::add( $modules_setup );

$foundation_pages = new Foundation_Pages();
Setup::add( $foundation_pages );
$cornerstone_pages = new Cornerstone_Pages();
Setup::add( $cornerstone_pages );

// Initialize the Admin experience.
$this->init_admin( $modules_setup );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Set;
use Automattic\Jetpack_Boost\Lib\Environment_Change_Detector;

class Foundation_Pages_Entry implements Entry_Can_Get, Entry_Can_Set {
class Cornerstone_Pages_Entry implements Entry_Can_Get, Entry_Can_Set {

private $option_key;

Expand Down Expand Up @@ -34,7 +34,7 @@ public function set( $value ) {

$updated = update_option( $this->option_key, $value );
if ( $updated ) {
( new Environment_Change_Detector() )->handle_foundation_pages_list_update();
( new Environment_Change_Detector() )->handle_cornerstone_pages_list_update();
}
}

Expand Down
30 changes: 15 additions & 15 deletions projects/plugins/boost/app/lib/Environment_Change_Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
*/
class Environment_Change_Detector {

const ENV_CHANGE_LEGACY = '1';
const ENV_CHANGE_PAGE_SAVED = 'page_saved';
const ENV_CHANGE_POST_SAVED = 'post_saved';
const ENV_CHANGE_SWITCHED_THEME = 'switched_theme';
const ENV_CHANGE_PLUGIN_CHANGE = 'plugin_change';
const ENV_CHANGE_FOUNDATION_PAGE_SAVED = 'foundation_page_saved';
const ENV_CHANGE_FOUNDATION_PAGES_LIST_UPDATED = 'foundation_pages_list_updated';
const ENV_CHANGE_LEGACY = '1';
const ENV_CHANGE_PAGE_SAVED = 'page_saved';
const ENV_CHANGE_POST_SAVED = 'post_saved';
const ENV_CHANGE_SWITCHED_THEME = 'switched_theme';
const ENV_CHANGE_PLUGIN_CHANGE = 'plugin_change';
const ENV_CHANGE_CORNERSTONE_PAGE_SAVED = 'cornerstone_page_saved';
const ENV_CHANGE_CORNERSTONE_PAGES_LIST_UPDATED = 'cornerstone_pages_list_updated';

/**
* Initialize the change detection hooks.
Expand Down Expand Up @@ -59,8 +59,8 @@ public function handle_plugin_change() {
$this->do_action( false, $this::ENV_CHANGE_PLUGIN_CHANGE );
}

public function handle_foundation_pages_list_update() {
$this->do_action( false, $this::ENV_CHANGE_FOUNDATION_PAGES_LIST_UPDATED );
public function handle_cornerstone_pages_list_update() {
$this->do_action( false, $this::ENV_CHANGE_CORNERSTONE_PAGES_LIST_UPDATED );
}

/**
Expand Down Expand Up @@ -107,12 +107,12 @@ private function is_post_type_invalidating( $post_type ) {
* @return string The change type.
*/
private function get_post_change_type( $post ) {
$foundation_pages = ( new Foundation_Pages() )->get_pages();
if ( $foundation_pages ) {
$foundation_pages_sanitized = array_map( 'untrailingslashit', $foundation_pages );
$current_url = untrailingslashit( get_permalink( $post ) );
if ( in_array( $current_url, $foundation_pages_sanitized, true ) ) {
return $this::ENV_CHANGE_FOUNDATION_PAGE_SAVED;
$cornerstone_pages = ( new Cornerstone_Pages() )->get_pages();
if ( $cornerstone_pages ) {
$cornerstone_pages_sanitized = array_map( 'untrailingslashit', $cornerstone_pages );
$current_url = untrailingslashit( get_permalink( $post ) );
if ( in_array( $current_url, $cornerstone_pages_sanitized, true ) ) {
return $this::ENV_CHANGE_CORNERSTONE_PAGE_SAVED;
}
}

Expand Down
Loading

0 comments on commit 3c6bffa

Please sign in to comment.