From 42327ec5c2d06480318e370db5ed8364f9541217 Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Tue, 18 Jul 2023 10:07:19 -0300 Subject: [PATCH] Add-Ons: Hide Jetpack AI add-on card for sites that already support the feature (#79495) * Use the site active features to decide if the add-on should be showed * Use a constant instead of the literal feature name * Move feature flag to staging level, so we can test it easily --- client/my-sites/add-ons/hooks/use-add-ons.ts | 12 ++++++++++++ config/horizon.json | 2 +- config/stage.json | 2 +- config/wpcalypso.json | 2 +- packages/calypso-products/src/constants/features.ts | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/my-sites/add-ons/hooks/use-add-ons.ts b/client/my-sites/add-ons/hooks/use-add-ons.ts index a8474cabd25fc..8b04f610f271b 100644 --- a/client/my-sites/add-ons/hooks/use-add-ons.ts +++ b/client/my-sites/add-ons/hooks/use-add-ons.ts @@ -4,6 +4,7 @@ import { PRODUCT_WPCOM_CUSTOM_DESIGN, PRODUCT_WPCOM_UNLIMITED_THEMES, PRODUCT_1GB_SPACE, + WPCOM_FEATURES_AI_ASSISTANT, } from '@automattic/calypso-products'; import { TranslateResult, useTranslate } from 'i18n-calypso'; import useMediaStorageQuery from 'calypso/data/media-storage/use-media-storage-query'; @@ -15,6 +16,7 @@ import { getProductName, } from 'calypso/state/products-list/selectors'; import getBillingTransactionFilters from 'calypso/state/selectors/get-billing-transaction-filters'; +import getFeaturesBySiteId from 'calypso/state/selectors/get-site-features'; import { usePastBillingTransactions } from 'calypso/state/sites/hooks/use-billing-history'; import { STORAGE_LIMIT } from '../constants'; import customDesignIcon from '../icons/custom-design'; @@ -103,6 +105,8 @@ const useAddOns = ( siteId?: number ): ( AddOnMeta | null )[] => { const { billingTransactions, isLoading } = usePastBillingTransactions(); return useSelector( ( state ): ( AddOnMeta | null )[] => { + // get the list of supported features + const siteFeatures = getFeaturesBySiteId( state, siteId ); const filter = getBillingTransactionFilters( state, 'past' ); const filteredTransactions = billingTransactions && filterTransactions( billingTransactions, filter, siteId ); @@ -133,6 +137,14 @@ const useAddOns = ( siteId?: number ): ( AddOnMeta | null )[] => { return false; } + // remove the Jetpack AI add-on if the site already supports the feature + if ( + addOn.productSlug === PRODUCT_JETPACK_AI_MONTHLY && + siteFeatures?.active?.includes( WPCOM_FEATURES_AI_ASSISTANT ) + ) { + return false; + } + return true; } ) .map( ( addOn ) => { diff --git a/config/horizon.json b/config/horizon.json index b3156533b2060..3e5460c6710dd 100644 --- a/config/horizon.json +++ b/config/horizon.json @@ -44,7 +44,7 @@ "i18n/empathy-mode": false, "i18n/translation-scanner": true, "importer/unified": true, - "jetpack/ai-assistant-request-limit": false, + "jetpack/ai-assistant-request-limit": true, "jetpack/api-cache": true, "jetpack/backup-messaging-i3": true, "jetpack/backup-retention-settings": true, diff --git a/config/stage.json b/config/stage.json index 2ab69319821a0..b59635556e632 100644 --- a/config/stage.json +++ b/config/stage.json @@ -48,7 +48,7 @@ "i18n/empathy-mode": true, "importer/unified": true, "jetpack/agency-dashboard": true, - "jetpack/ai-assistant-request-limit": false, + "jetpack/ai-assistant-request-limit": true, "jetpack/api-cache": true, "jetpack/backup-messaging-i3": true, "jetpack/backup-retention-settings": true, diff --git a/config/wpcalypso.json b/config/wpcalypso.json index 9f0930c0d6654..3e64fbe562c37 100644 --- a/config/wpcalypso.json +++ b/config/wpcalypso.json @@ -60,7 +60,7 @@ "importers/substack": true, "importer/unified": true, "jetpack/agency-dashboard": true, - "jetpack/ai-assistant-request-limit": false, + "jetpack/ai-assistant-request-limit": true, "jetpack/api-cache": true, "jetpack/backup-retention-settings": true, "jetpack/cancel-through-main-flow": true, diff --git a/packages/calypso-products/src/constants/features.ts b/packages/calypso-products/src/constants/features.ts index dd241a6e828c7..be972217a5953 100644 --- a/packages/calypso-products/src/constants/features.ts +++ b/packages/calypso-products/src/constants/features.ts @@ -237,6 +237,7 @@ export const FEATURE_WOOCOMMERCE = 'woocommerce'; export const FEATURE_SOCIAL_MEDIA_TOOLS = 'social-media-tools'; // From class-wpcom-features.php in WPCOM +export const WPCOM_FEATURES_AI_ASSISTANT = 'ai-assistant'; export const WPCOM_FEATURES_AKISMET = 'akismet'; export const WPCOM_FEATURES_ANTISPAM = 'antispam'; export const WPCOM_FEATURES_ATOMIC = 'atomic';