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 40bd243
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Automattic\Jetpack\Schema\Schema;
use Automattic\Jetpack_Boost\Contracts\Has_Setup;
use Automattic\Jetpack_Boost\Data_Sync\Foundation_Pages_Entry;
use Automattic\Jetpack_Boost\Data_Sync\Cornerstone_Pages_Entry;

class Foundation_Pages implements Has_Setup {
class Cornerstone_Pages implements Has_Setup {

const PREMIUM_MAX_PAGES = 10;
const FREE_MAX_PAGES = 1;
Expand All @@ -23,8 +23,8 @@ public function setup() {

public function register_ds_stores() {
$schema = Schema::as_array( Schema::as_string() )->fallback( self::default_pages() );
jetpack_boost_register_option( 'foundation_pages_list', $schema, new Foundation_Pages_Entry( 'foundation_pages_list' ) );
jetpack_boost_register_readonly_option( 'foundation_pages_properties', array( $this, 'get_properties' ) );
jetpack_boost_register_option( 'cornerstone_pages_list', $schema, new Cornerstone_Pages_Entry( 'cornerstone_pages_list' ) );
jetpack_boost_register_readonly_option( 'cornerstone_pages_properties', array( $this, 'get_properties' ) );
}

public function remove_ccss_front_page_provider( $providers ) {
Expand Down Expand Up @@ -112,7 +112,7 @@ public function get_pages() {
return array();
}

return jetpack_boost_ds_get( 'foundation_pages_list' );
return jetpack_boost_ds_get( 'cornerstone_pages_list' );
}

public function get_properties() {
Expand All @@ -122,13 +122,13 @@ public function get_properties() {
}

public function add_display_post_states( $post_states, $post ) {
$foundation_pages = $this->get_pages();
if ( ! empty( $foundation_pages ) ) {
$post_url = untrailingslashit( get_permalink( $post ) );
$foundation_pages = array_map( 'untrailingslashit', $foundation_pages );
$cornerstone_pages = $this->get_pages();
if ( ! empty( $cornerstone_pages ) ) {
$post_url = untrailingslashit( get_permalink( $post ) );
$cornerstone_pages = array_map( 'untrailingslashit', $cornerstone_pages );

if ( in_array( $post_url, $foundation_pages, true ) ) {
$post_states[] = __( 'Foundation Page', 'jetpack-boost' );
if ( in_array( $post_url, $cornerstone_pages, true ) ) {
$post_states[] = __( 'Cornerstone Page', 'jetpack-boost' );
}
}

Expand Down
Loading

0 comments on commit 40bd243

Please sign in to comment.