From f804687c39aa81688eb03f0f60d90fba4b79006b Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Mon, 29 Jul 2024 17:40:35 -0300 Subject: [PATCH 1/6] Move current checks to a helper function --- .../extended-blocks/core-site-logo/index.tsx | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx b/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx index 0fe0f9091e78d..eef1e8597e2d6 100644 --- a/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx +++ b/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx @@ -137,21 +137,34 @@ const siteLogoEditWithAiComponents = createHigherOrderComponent( BlockEdit => { }, 'SiteLogoEditWithAiComponents' ); /** - * Function to override the core Site Logo block edit settings. - * Will create a HOC to use as the edit implementation. + * Function to check if the block can be extended. * - * @param {object} settings - The block settings. * @param {string} name - The block name. - * @returns {object} The new block settings. + * @returns {boolean} True if the block can be extended. */ -function jetpackSiteLogoWithAiSupport( settings, name: string ) { - // Only extend the core Site Logo block. +function canExtendBlock( name: string ): boolean { if ( name !== 'core/site-logo' ) { - return settings; + return false; } // Disable if the feature is not available. if ( ! getFeatureAvailability( SITE_LOGO_BLOCK_AI_EXTENSION ) ) { + return false; + } + + return true; +} + +/** + * Function to override the core Site Logo block edit settings. + * Will create a HOC to use as the edit implementation. + * + * @param {object} settings - The block settings. + * @param {string} name - The block name. + * @returns {object} The new block settings. + */ +function jetpackSiteLogoWithAiSupport( settings, name: string ) { + if ( ! canExtendBlock( name ) ) { return settings; } From 39c6b7afca0905758f1ec3f7e661e83732e11039 Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Mon, 29 Jul 2024 17:42:45 -0300 Subject: [PATCH 2/6] Disable the extension when the AI Assistant block is not registered --- .../extensions/extended-blocks/core-site-logo/index.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx b/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx index eef1e8597e2d6..64b421290eced 100644 --- a/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx +++ b/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx @@ -3,6 +3,7 @@ */ import { GeneratorModal } from '@automattic/jetpack-ai-client'; import { BlockControls } from '@wordpress/block-editor'; +import { getBlockType } from '@wordpress/blocks'; import { createHigherOrderComponent } from '@wordpress/compose'; import { useDispatch, useSelect } from '@wordpress/data'; import { useCallback, useEffect, useState } from '@wordpress/element'; @@ -147,6 +148,13 @@ function canExtendBlock( name: string ): boolean { return false; } + // Check if the AI Assistant block is registered. If not, we understand that Jetpack AI is not active. + const isAIAssistantBlockRegistered = getBlockType( 'jetpack/ai-assistant' ); + + if ( ! isAIAssistantBlockRegistered ) { + return false; + } + // Disable if the feature is not available. if ( ! getFeatureAvailability( SITE_LOGO_BLOCK_AI_EXTENSION ) ) { return false; From 0eb07bc409515c682476154a6330f339cd2675c5 Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Mon, 29 Jul 2024 17:49:21 -0300 Subject: [PATCH 3/6] Do not extend the block when the AI Assistant block is hidden on the editor --- .../extended-blocks/core-site-logo/index.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx b/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx index 64b421290eced..d97f0a50f2207 100644 --- a/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx +++ b/projects/plugins/jetpack/extensions/extended-blocks/core-site-logo/index.tsx @@ -5,7 +5,7 @@ import { GeneratorModal } from '@automattic/jetpack-ai-client'; import { BlockControls } from '@wordpress/block-editor'; import { getBlockType } from '@wordpress/blocks'; import { createHigherOrderComponent } from '@wordpress/compose'; -import { useDispatch, useSelect } from '@wordpress/data'; +import { useDispatch, useSelect, select } from '@wordpress/data'; import { useCallback, useEffect, useState } from '@wordpress/element'; import { addFilter } from '@wordpress/hooks'; /* @@ -70,8 +70,8 @@ const useSetLogo = () => { }; const useSiteDetails = () => { - const siteSettings = useSelect( select => { - return ( select( 'core' ) as CoreSelect ).getEntityRecord( 'root', 'site' ); + const siteSettings = useSelect( selectData => { + return ( selectData( 'core' ) as CoreSelect ).getEntityRecord( 'root', 'site' ); }, [] ); return { @@ -160,6 +160,19 @@ function canExtendBlock( name: string ): boolean { return false; } + /* + * Do not extend if the AI Assistant block is hidden, + * as a way for the user to hide the extension. + * TODO: the `editPostStore` is undefined for P2 sites. + * Let's find a way to check if the block is hidden there. + */ + const { getHiddenBlockTypes } = select( 'core/edit-post' ) || {}; + const hiddenBlocks = getHiddenBlockTypes?.() || []; // It will extend the block if the function is undefined + + if ( hiddenBlocks.includes( 'jetpack/ai-assistant' ) ) { + return false; + } + return true; } From ff96040036c91b39ff85f2085138a84e62f59b56 Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Mon, 29 Jul 2024 17:51:03 -0300 Subject: [PATCH 4/6] Changelog --- ...ate-ai-logo-generator-improve-extension-availability-check | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/update-ai-logo-generator-improve-extension-availability-check diff --git a/projects/plugins/jetpack/changelog/update-ai-logo-generator-improve-extension-availability-check b/projects/plugins/jetpack/changelog/update-ai-logo-generator-improve-extension-availability-check new file mode 100644 index 0000000000000..1072f17dc400a --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-ai-logo-generator-improve-extension-availability-check @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +AI Logo Generator: only extend the logo block when the AI Assistant is available and not hidden on the editor. From 3b72a75e02ad8cc83e5f2b18ce55e76ab2c8e0c5 Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Tue, 30 Jul 2024 12:32:25 -0300 Subject: [PATCH 5/6] Bump versions --- projects/plugins/wpcomsh/composer.json | 2 +- projects/plugins/wpcomsh/package.json | 2 +- projects/plugins/wpcomsh/wpcomsh.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/plugins/wpcomsh/composer.json b/projects/plugins/wpcomsh/composer.json index 2a274920f23ce..3b3f7dec0adea 100644 --- a/projects/plugins/wpcomsh/composer.json +++ b/projects/plugins/wpcomsh/composer.json @@ -128,7 +128,7 @@ "composer/installers": true, "roots/wordpress-core-installer": true }, - "autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_1" + "autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_2_alpha" }, "extra": { "mirror-repo": "Automattic/wpcom-site-helper", diff --git a/projects/plugins/wpcomsh/package.json b/projects/plugins/wpcomsh/package.json index de9cd4ef2f088..7b7b61907ef5d 100644 --- a/projects/plugins/wpcomsh/package.json +++ b/projects/plugins/wpcomsh/package.json @@ -3,7 +3,7 @@ "name": "@automattic/jetpack-wpcomsh", "description": "A helper for connecting WordPress.com sites to external host infrastructure.", "homepage": "https://jetpack.com", - "version": "5.1.1", + "version": "5.1.2-alpha", "bugs": { "url": "https://github.com/Automattic/jetpack/labels/[Plugin] Wpcomsh" }, diff --git a/projects/plugins/wpcomsh/wpcomsh.php b/projects/plugins/wpcomsh/wpcomsh.php index b152dbeed752b..377e08b2a8344 100644 --- a/projects/plugins/wpcomsh/wpcomsh.php +++ b/projects/plugins/wpcomsh/wpcomsh.php @@ -2,14 +2,14 @@ /** * Plugin Name: WordPress.com Site Helper * Description: A helper for connecting WordPress.com sites to external host infrastructure. - * Version: 5.1.1 + * Version: 5.1.2-alpha * Author: Automattic * Author URI: http://automattic.com/ * * @package wpcomsh */ -define( 'WPCOMSH_VERSION', '5.1.1' ); +define( 'WPCOMSH_VERSION', '5.1.2-alpha' ); // If true, Typekit fonts will be available in addition to Google fonts add_filter( 'jetpack_fonts_enable_typekit', '__return_true' ); From 538b4eed4884ec94744e5598e94054a3cbd17d2e Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Tue, 30 Jul 2024 12:34:16 -0300 Subject: [PATCH 6/6] Changelog --- ...te-ai-logo-generator-improve-extension-availability-check | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 projects/plugins/wpcomsh/changelog/update-ai-logo-generator-improve-extension-availability-check diff --git a/projects/plugins/wpcomsh/changelog/update-ai-logo-generator-improve-extension-availability-check b/projects/plugins/wpcomsh/changelog/update-ai-logo-generator-improve-extension-availability-check new file mode 100644 index 0000000000000..2b86d65fe2c9a --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/update-ai-logo-generator-improve-extension-availability-check @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Just bumping versions to comply with changelogger checks. + +