Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-Ons: Hide Jetpack AI add-on card for sites that already support the feature #79495

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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