Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into add/performance-impr…
Browse files Browse the repository at this point in the history
…ovements
  • Loading branch information
kraftbj committed Oct 24, 2024
2 parents 4ff7eab + 0ddb726 commit b7470d6
Show file tree
Hide file tree
Showing 293 changed files with 2,786 additions and 2,186 deletions.
2 changes: 1 addition & 1 deletion .github/versions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Versions of tools to use in CI.
PHP_VERSION=8.2
COMPOSER_VERSION=2.7.7
NODE_VERSION=20.8.1
NODE_VERSION=22.9.0
PNPM_VERSION=9.3.0

# Other useful version numbers.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/block-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
npx playwright install chromium --with-deps
npm run build:packages
- name: Setup tools for J
- name: Setup tools for Jetpack
uses: ./.github/actions/tool-setup

- name: Build Production Jetpack
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.8.1
22.9.0
8 changes: 4 additions & 4 deletions .phan/stubs/wpcom-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* `bin/teamcity-builds/jetpack-stubs/stub-defs.php` and regenerate the stubs
* by triggering the Jetpack Staging → Update WPCOM Stubs job in TeamCity.
*
* Stubs automatically generated from WordPress.com commit 2ed424b4493f3450b67bb248706d6e29170e6042.
* Stubs automatically generated from WordPress.com commit 4fd96546151f08483e92c0807b89830093fc1aee.
*/

namespace {
Expand Down Expand Up @@ -548,7 +548,7 @@ function is_automattic($blog_id = \null)
{
}
/**
* @param int|null $blog_id
* @param int|string|null $blog_id
* @return bool
*/
function wpcom_is_automattic_p2_site($blog_id = \null)
Expand Down Expand Up @@ -716,7 +716,7 @@ function is_simple_site_redirect($blog_id = 0)
}
class Subscription_Mailer extends \WordPressMailer
{
public function __construct(\Blog_Subscriber $subscriber, $use_wp = \true)
public function __construct(\Blog_Subscriber $subscriber, $use_wp = \true, $locale_type = self::USER_LOCALE)
{
}
/**
Expand Down Expand Up @@ -1058,7 +1058,7 @@ function wpcom_fetch_subs_counts($include_paid_subscribers = \false)
function wpcom_is_child_theme()
{
}
function queue_publish_post($post_id, $post = \null)
function queue_publish_post($post_id, $post = \null, $old_post_status = \null)
{
}
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"jetpack-js-tools": "workspace:*"
},
"engines": {
"node": "^20.8.1",
"node": "^22.9.0",
"pnpm": "^9.3.0"
}
}
20 changes: 19 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/js-packages/ai-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.22.0] - 2024-10-21
### Changed
- AI Client: Add types for AI assistant feature payload data branch featuresControl. [#39826]

## [0.21.0] - 2024-10-14
### Added
- AI Client: Add image styles 'auto' and 'none' to the logo generator. Order styles so those are on top in the dropdown selector. [#39689]
Expand Down Expand Up @@ -435,6 +439,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated package dependencies. [#31659]
- Updated package dependencies. [#31785]

[0.22.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.21.0...v0.22.0
[0.21.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.20.1...v0.21.0
[0.20.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.20.0...v0.20.1
[0.20.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.19.0...v0.20.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

AI Client: make reload handler prop optional as it still works in a fuzzy way. The error notice (modal) will instruct to reload the page when the optional prop is not provided
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fixed

AI Client: fix initial state being mapped even when fetch fails, making the default state nonsensical
2 changes: 1 addition & 1 deletion projects/js-packages/ai-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "@automattic/jetpack-ai-client",
"version": "0.21.0",
"version": "0.22.0",
"description": "A JS client for consuming Jetpack AI services",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/ai-client/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,34 @@ import type React from 'react';

export const FeatureFetchFailureScreen: React.FC< {
onCancel: () => void;
onRetry: () => void;
onRetry?: () => void;
} > = ( { onCancel, onRetry } ) => {
const errorMessage = __(
'We are sorry. There was an error loading your Jetpack AI plan data. Please, try again.',
'jetpack-ai-client'
);

const errorMessageWithoutRetry = __(
'We are sorry. There was an error loading your Jetpack AI plan data. Please, reload the page and try again.',
'jetpack-ai-client'
);

return (
<div className="jetpack-ai-logo-generator-modal__notice-message-wrapper">
<div className="jetpack-ai-logo-generator-modal__notice-message">
<span className="jetpack-ai-logo-generator-modal__loading-message">{ errorMessage }</span>
<span className="jetpack-ai-logo-generator-modal__loading-message">
{ onRetry ? errorMessage : errorMessageWithoutRetry }
</span>
</div>
<div className="jetpack-ai-logo-generator-modal__notice-actions">
<Button variant="tertiary" onClick={ onCancel }>
{ __( 'Cancel', 'jetpack-ai-client' ) }
</Button>
<Button variant="primary" onClick={ onRetry }>
{ __( 'Try again', 'jetpack-ai-client' ) }
</Button>
{ onRetry && (
<Button variant="primary" onClick={ onRetry }>
{ __( 'Try again', 'jetpack-ai-client' ) }
</Button>
) }
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
isOpen,
onClose,
onApplyLogo,
onReload,
onReload = null,
siteDetails,
context,
placement,
Expand Down Expand Up @@ -73,7 +73,8 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
site,
requireUpgrade,
} = useLogoGenerator();
const { featureFetchError, firstLogoPromptFetchError, clearErrors } = useRequestErrors();
const { featureFetchError, setFeatureFetchError, firstLogoPromptFetchError, clearErrors } =
useRequestErrors();
const siteId = siteDetails?.ID;
const [ logoAccepted, setLogoAccepted ] = useState( false );
const { nextTierCheckoutURL: upgradeURL } = useCheckout();
Expand Down Expand Up @@ -105,6 +106,15 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
*/
const initializeModal = useCallback( async () => {
try {
if ( ! siteId ) {
throw new Error( 'Site ID is missing' );
}

if ( ! feature?.featuresControl?.[ 'logo-generator' ]?.enabled ) {
setFeatureFetchError( 'Failed to fetch feature data' );
throw new Error( 'Failed to fetch feature data' );
}

const hasHistory = ! isLogoHistoryEmpty( String( siteId ) );

const logoCost = feature?.costs?.[ 'jetpack-ai-logo-generator' ]?.logo ?? DEFAULT_LOGO_COST;
Expand All @@ -125,10 +135,10 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
: currentLimit < currentUsage );

// If the site requires an upgrade, show the upgrade screen immediately.
setNeedsFeature( currentLimit === 0 );
setNeedsFeature( currentValue === 0 );
setNeedsMoreRequests( siteNeedsMoreRequests );

if ( currentLimit === 0 || siteNeedsMoreRequests ) {
if ( currentValue === 0 || siteNeedsMoreRequests ) {
setLoadingState( null );
return;
}
Expand Down Expand Up @@ -179,6 +189,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
isLogoHistoryEmpty,
siteId,
requireUpgrade,
setFeatureFetchError,
] );

const handleModalOpen = useCallback( async () => {
Expand All @@ -201,6 +212,15 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
recordTracksEvent( EVENT_MODAL_CLOSE, { context, placement } );
};

const handleReload = useCallback( () => {
if ( ! onReload ) {
return;
}
closeModal();
requestedFeatureData.current = false;
onReload();
}, [ onReload, closeModal ] );

const handleApplyLogo = ( mediaId: number ) => {
setLogoAccepted( true );
onApplyLogo?.( mediaId );
Expand Down Expand Up @@ -229,7 +249,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
// Handles modal opening logic
useEffect( () => {
// While the modal is not open, the siteId is not set, or the feature data is not available, do nothing.
if ( ! isOpen || ! siteId || ! feature?.costs ) {
if ( ! isOpen ) {
return;
}

Expand All @@ -238,7 +258,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
needsToHandleModalOpen.current = false;
handleModalOpen();
}
}, [ isOpen, siteId, handleModalOpen, feature ] );
}, [ isOpen, handleModalOpen ] );

let body: React.ReactNode;

Expand All @@ -248,10 +268,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
body = (
<FeatureFetchFailureScreen
onCancel={ closeModal }
onRetry={ () => {
closeModal();
onReload?.();
} }
onRetry={ onReload ? handleReload : null }
/>
);
} else if ( needsFeature || needsMoreRequests ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
color: var(--studio-gray-50, #646970);
}

&[data-placeholder]:empty:focus::before {
&[data-placeholder]:empty:focus::before:not([contentEditable="false"]) {
content: "";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const Prompt = ( { initialPrompt = '' }: PromptProps ) => {
}, [ prompt ] );

useEffect( () => {
if ( imageStyles.length > 0 ) {
if ( imageStyles && imageStyles.length > 0 ) {
// Sort styles to have "None" and "Auto" first
setStyles(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const useLogoGenerator = () => {
const logoGeneratorControl = aiAssistantFeatureData?.featuresControl?.[
'logo-generator'
] as LogoGeneratorFeatureControl;
const imageStyles: Array< ImageStyleObject > = logoGeneratorControl?.styles;
const imageStyles: Array< ImageStyleObject > = logoGeneratorControl?.styles || [];

const generateFirstPrompt = useCallback(
async function (): Promise< string > {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const actions = {
query: 'force=wpcom',
} );

if ( response.data ) {
throw new Error( 'Failed to fetch' );
}

// Store the feature in the store.
dispatch(
actions.storeAiAssistantFeature( mapAiFeatureResponseToAiFeatureProps( response ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const INITIAL_STATE: LogoGeneratorStateProp = {
asyncRequestTimerId: 0,
isRequestingImage: false,
},
featuresControl: {
'logo-generator': {
enabled: false,
styles: [],
},
},
},
},
history: [],
Expand Down
10 changes: 10 additions & 0 deletions projects/js-packages/ai-client/src/logo-generator/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,16 @@ export default function reducer(
case ACTION_SET_FEATURE_FETCH_ERROR:
return {
...state,
features: {
...state.features,
aiAssistantFeature: {
...state?.features?.aiAssistantFeature,
_meta: {
...state?.features?.aiAssistantFeature?._meta,
isRequesting: false,
},
},
},
_meta: {
...( state._meta ?? {} ),
featureFetchError: action.error,
Expand Down
Loading

0 comments on commit b7470d6

Please sign in to comment.