Skip to content

Commit

Permalink
Add-Ons: Hide Jetpack AI add-on card for sites that already support t…
Browse files Browse the repository at this point in the history
…he 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
  • Loading branch information
lhkowalski authored and timur987 committed Jul 20, 2023
1 parent e59900c commit 42327ec
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
12 changes: 12 additions & 0 deletions client/my-sites/add-ons/hooks/use-add-ons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) => {
Expand Down
2 changes: 1 addition & 1 deletion config/horizon.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion config/stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion config/wpcalypso.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/calypso-products/src/constants/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 42327ec

Please sign in to comment.