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

Split lib/products-values #44567

Merged
merged 71 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
f4ba244
Split assertValidProduct into a new utils folder
sgomes Jul 30, 2020
9650cf7
Split out formatProduct
sgomes Jul 30, 2020
4740486
Split out isChargeback
sgomes Jul 30, 2020
2dd9f0f
Split out includesProduct
sgomes Jul 30, 2020
1e8b4ee
Split out isFreePlan
sgomes Jul 30, 2020
375cc99
Split out isFreeJetpackPlan
sgomes Jul 30, 2020
f41a5d4
Split out isFreeTrial
sgomes Jul 30, 2020
bbd91a5
Split out isPersonal
sgomes Jul 30, 2020
d5de7d3
Split out isBlogger
sgomes Jul 30, 2020
b49ce12
Split out isPremium
sgomes Jul 30, 2020
e69c4d9
Split out isBusiness
sgomes Jul 30, 2020
10fb5b3
Split out isEcommerce
sgomes Jul 30, 2020
cc1a1dd
Split out isEnterprise
sgomes Jul 30, 2020
dd65e4b
Split out isJetpackPlanSlug
sgomes Jul 30, 2020
1534e3b
Split out isJetpackPlan
sgomes Jul 30, 2020
1c9617f
Split out isJetpackBusiness
sgomes Jul 30, 2020
1c8b46a
Split out isJetpackPremium
sgomes Jul 30, 2020
f74a1b8
Split out isVipPlan
sgomes Jul 30, 2020
a215613
Split out isMonthly
sgomes Jul 30, 2020
8477b53
Split out isYearly
sgomes Jul 30, 2020
754ab72
Split out isBiennially
sgomes Jul 30, 2020
c365962
Split out isJetpackMonthlyPlan
sgomes Jul 30, 2020
17ed489
Split out isJetpackBackupSlug
sgomes Jul 30, 2020
e548c07
Split out isJetpackBackup
sgomes Jul 30, 2020
42a25c9
Split out isJetpackScanSlug
sgomes Jul 30, 2020
909d8e7
Split out isJetpackAntiSpamSlug
sgomes Jul 30, 2020
72335ee
Split out isJetpackScan
sgomes Jul 30, 2020
2d9fa38
Split out isJetpackAntiSpam
sgomes Jul 30, 2020
2151664
Split out isJetpackCloudProductSlug
sgomes Jul 30, 2020
3126d01
Split out isJetpackProductSlug
sgomes Jul 30, 2020
ca8daf4
Split out isJetpackProduct
sgomes Jul 30, 2020
ac1a697
Move translated constants to new translations file
sgomes Jul 30, 2020
55f581f
Split out getProductFromSlug
sgomes Jul 30, 2020
63aa767
Split out isJpphpBundle
sgomes Jul 30, 2020
efcdc98
Split out isPlan
sgomes Jul 30, 2020
6df76f6
Split out isDotComPlan
sgomes Jul 30, 2020
cf92b4c
Split out isDomainMapping
sgomes Jul 30, 2020
3e89c52
Split out isDomainRegistration
sgomes Jul 30, 2020
943e042
Split out isDomainProduct
sgomes Jul 30, 2020
7942b4e
Split out isDomainRedemption
sgomes Jul 30, 2020
ae992df
Split out getIncludedDomainPurchaseAmount
sgomes Jul 30, 2020
122b48a
Split out isSiteRedirect
sgomes Jul 30, 2020
c5d8b1b
Split out allowedProductAttributes
sgomes Jul 30, 2020
aa1266f
Split out isDomainTransfer
sgomes Jul 30, 2020
1290fe8
Split out isDomainTransferProduct
sgomes Jul 30, 2020
3e3d80e
Split out isDelayedDomainTransfer
sgomes Jul 30, 2020
79d42e7
Split out isBundled
sgomes Jul 30, 2020
7e40b9a
Split out isCredits
sgomes Jul 30, 2020
cde9012
Split out getDomainProductRanking
sgomes Jul 30, 2020
8fd8c18
Split out getDomain
sgomes Jul 30, 2020
994ad61
Split out getProductsSlugs
sgomes Jul 30, 2020
750680b
Split out getProductClass
sgomes Jul 30, 2020
2930520
Split out getJetpackProductDisplayName
sgomes Jul 30, 2020
48ab059
Split out getJetpackProductTagline
sgomes Jul 30, 2020
1e6b714
Split out isDependentProduct
sgomes Jul 30, 2020
d57b1a2
Split out isFreeWordPressComDomain
sgomes Jul 30, 2020
6b52307
Split out isGoogleApps
sgomes Jul 30, 2020
01703b5
Split out isGuidedTransfer
sgomes Jul 30, 2020
dba027d
Split out isTheme
sgomes Jul 30, 2020
db35342
Split out isCustomDesign
sgomes Jul 30, 2020
895e4c1
Split out isNoAds
sgomes Jul 30, 2020
5539c5d
Split out isVideoPress
sgomes Jul 30, 2020
51e5127
Split out isUnlimitedSpace
sgomes Jul 30, 2020
b96d774
Split out isUnlimitedThemes
sgomes Jul 30, 2020
76271f4
Split out isSpaceUpgrade
sgomes Jul 30, 2020
a99d371
Split out isConciergeSession
sgomes Jul 30, 2020
4686833
Sort exports alphabetically
sgomes Jul 30, 2020
6e5a84f
Add package.json with sideEffects config
sgomes Jul 30, 2020
55ae77e
Import from new individual modules in lib/plans
sgomes Jul 30, 2020
f086cfb
Import from new individual modules in lib/domains
sgomes Jul 30, 2020
89a7882
Update checkout-thank-you test mocks
sgomes Jul 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/lib/domains/cart-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isEmpty, find, values } from 'lodash';
* Internal dependencies
*/
import { hasDomainRegistration, getDomainRegistrations } from 'lib/cart-values/cart-items';
import { isDomainRegistration } from 'lib/products-values';
import { isDomainRegistration } from 'lib/products-values/is-domain-registration';

/**
* Depending on the current step in checkout, the user's domain can be found in
Expand Down
4 changes: 3 additions & 1 deletion client/lib/plans/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { difference, get, includes, pick, values, isFunction } from 'lodash';
* Internal dependencies
*/
import { isEnabled } from 'config';
import { isFreeJetpackPlan, isJetpackPlan, isMonthly } from 'lib/products-values';
import { isFreeJetpackPlan } from 'lib/products-values/is-free-jetpack-plan';
import { isJetpackPlan } from 'lib/products-values/is-jetpack-plan';
import { isMonthly } from 'lib/products-values/is-monthly';
import { format as formatUrl, getUrlParts, getUrlFromParts, determineUrlType } from 'lib/url';
import {
PLAN_FREE,
Expand Down
13 changes: 13 additions & 0 deletions client/lib/products-values/allowed-product-attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* External dependencies
*/
import { pick } from 'lodash';

/**
* Internal dependencies
*/
import schema from 'lib/products-values/schema.json';

export function allowedProductAttributes( product ) {
return pick( product, Object.keys( schema.properties ) );
}
289 changes: 0 additions & 289 deletions client/lib/products-values/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* External dependencies
*/
import React from 'react';
import { numberFormat, translate } from 'i18n-calypso';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -94,286 +88,3 @@ export const JETPACK_PRODUCT_PRICE_MATRIX = {
ratio: 12,
},
};

// Translatable strings
export const getJetpackProductsShortNames = () => {
return {
[ PRODUCT_JETPACK_BACKUP_DAILY ]: translate( 'Daily Backups' ),
[ PRODUCT_JETPACK_BACKUP_DAILY_MONTHLY ]: translate( 'Daily Backups' ),
[ PRODUCT_JETPACK_BACKUP_REALTIME ]: translate( 'Real-Time Backups' ),
[ PRODUCT_JETPACK_BACKUP_REALTIME_MONTHLY ]: translate( 'Real-Time Backups' ),
[ PRODUCT_JETPACK_SEARCH ]: translate( 'Search' ),
[ PRODUCT_JETPACK_SEARCH_MONTHLY ]: translate( 'Search' ),
[ PRODUCT_WPCOM_SEARCH ]: translate( 'Search' ),
[ PRODUCT_WPCOM_SEARCH_MONTHLY ]: translate( 'Search' ),
[ PRODUCT_JETPACK_SCAN ]: translate( 'Daily Scan' ),
[ PRODUCT_JETPACK_SCAN_MONTHLY ]: translate( 'Daily Scan' ),
[ PRODUCT_JETPACK_ANTI_SPAM ]: translate( 'Anti-Spam' ),
[ PRODUCT_JETPACK_ANTI_SPAM_MONTHLY ]: translate( 'Anti-Spam' ),
};
};

export const getJetpackProductsDisplayNames = () => {
const backupDaily = (
<>
{ translate( 'Jetpack Backup {{em}}Daily{{/em}}', {
components: {
em: <em />,
},
} ) }{ ' ' }
</>
);
const backupRealtime = (
<>
{ ' ' }
{ translate( 'Jetpack Backup {{em}}Real-Time{{/em}}', {
components: {
em: <em />,
},
} ) }{ ' ' }
</>
);
const search = translate( 'Jetpack Search' );
const scanDaily = (
<>
{ translate( 'Jetpack Scan {{em}}Daily{{/em}}', {
components: {
em: <em />,
},
} ) }{ ' ' }
</>
);

const antiSpam = <>{ translate( 'Jetpack Anti-Spam' ) }</>;
return {
[ PRODUCT_JETPACK_BACKUP_DAILY ]: backupDaily,
[ PRODUCT_JETPACK_BACKUP_DAILY_MONTHLY ]: backupDaily,
[ PRODUCT_JETPACK_BACKUP_REALTIME ]: backupRealtime,
[ PRODUCT_JETPACK_BACKUP_REALTIME_MONTHLY ]: backupRealtime,
[ PRODUCT_JETPACK_SEARCH ]: search,
[ PRODUCT_JETPACK_SEARCH_MONTHLY ]: search,
[ PRODUCT_WPCOM_SEARCH ]: search,
[ PRODUCT_WPCOM_SEARCH_MONTHLY ]: search,
[ PRODUCT_JETPACK_SCAN ]: scanDaily,
[ PRODUCT_JETPACK_SCAN_MONTHLY ]: scanDaily,
[ PRODUCT_JETPACK_ANTI_SPAM ]: antiSpam,
[ PRODUCT_JETPACK_ANTI_SPAM_MONTHLY ]: antiSpam,
};
};
export const getJetpackProductsTaglines = () => {
const searchTagline = translate( 'Search your site.' );
const scanTagline = translate( 'Scan your site.' );
const antiSpamTagline = translate( 'Automatically clear spam from comments and forms.' );
return {
[ PRODUCT_JETPACK_BACKUP_DAILY ]: translate(
'Your data is being securely backed up every day with a 30-day archive.'
),
[ PRODUCT_JETPACK_BACKUP_DAILY_MONTHLY ]: translate(
'Your data is being securely backed up every day with a 30-day archive.'
),
[ PRODUCT_JETPACK_BACKUP_REALTIME ]: translate(
'Your data is being securely backed up as you edit.'
),
[ PRODUCT_JETPACK_BACKUP_REALTIME_MONTHLY ]: translate(
'Your data is being securely backed up as you edit.'
),
[ PRODUCT_JETPACK_SEARCH ]: searchTagline,
[ PRODUCT_JETPACK_SEARCH_MONTHLY ]: searchTagline,
[ PRODUCT_WPCOM_SEARCH ]: searchTagline,
[ PRODUCT_WPCOM_SEARCH_MONTHLY ]: searchTagline,
[ PRODUCT_JETPACK_SCAN ]: scanTagline,
[ PRODUCT_JETPACK_SCAN_MONTHLY ]: scanTagline,
[ PRODUCT_JETPACK_ANTI_SPAM ]: antiSpamTagline,
[ PRODUCT_JETPACK_ANTI_SPAM_MONTHLY ]: antiSpamTagline,
};
};

export const getJetpackProductsDescriptions = () => {
const searchDescription = translate(
'Incredibly powerful and customizable, Jetpack Search helps your visitors instantly find the right content – right when they need it.'
);
const scanDescription = translate(
'Automatic scanning and one-click fixes keep your site one step ahead of security threats.'
);
const antiSpamDescription = translate(
'Automatically clear spam from comments and forms. Save time, get more responses, give your visitors a better experience – all without lifting a finger.'
);
return {
[ PRODUCT_JETPACK_BACKUP_DAILY ]: translate(
'Always-on backups ensure you never lose your site. Your changes are saved every day with a 30-day archive.'
),
[ PRODUCT_JETPACK_BACKUP_DAILY_MONTHLY ]: translate(
'Always-on backups ensure you never lose your site. Your changes are saved every day with a 30-day archive.'
),
[ PRODUCT_JETPACK_BACKUP_REALTIME ]: translate(
'Always-on backups ensure you never lose your site. Your changes are saved as you edit and you have unlimited backup archives.'
),
[ PRODUCT_JETPACK_BACKUP_REALTIME_MONTHLY ]: translate(
'Always-on backups ensure you never lose your site. Your changes are saved as you edit and you have unlimited backup archives.'
),
[ PRODUCT_JETPACK_SEARCH ]: searchDescription,
[ PRODUCT_JETPACK_SEARCH_MONTHLY ]: searchDescription,
[ PRODUCT_JETPACK_SCAN ]: scanDescription,
[ PRODUCT_JETPACK_SCAN_MONTHLY ]: scanDescription,
[ PRODUCT_JETPACK_ANTI_SPAM ]: antiSpamDescription,
[ PRODUCT_JETPACK_ANTI_SPAM_MONTHLY ]: antiSpamDescription,
};
};

export const getJetpackProducts = () => {
const output = [
{
title: translate( 'Jetpack Backup' ),
description: translate(
'Always-on backups ensure you never lose your site. Choose from real-time or daily backups.'
),
hasPromo: true,
id: PRODUCT_JETPACK_BACKUP,
link: {
label: translate( 'Which backup option is best for me?' ),
props: {
location: 'product_jetpack_backup_description',
slug: 'which-one-do-i-need',
},
url: JETPACK_BACKUP_PRODUCT_LANDING_PAGE_URL,
},
options: {
yearly: JETPACK_BACKUP_PRODUCTS_YEARLY,
monthly: JETPACK_BACKUP_PRODUCTS_MONTHLY,
},
optionShortNames: getJetpackProductsShortNames(),
optionDisplayNames: getJetpackProductsDisplayNames(),
optionDescriptions: getJetpackProductsDescriptions(),
optionsLabel: translate( 'Select a backup option:' ),
slugs: JETPACK_BACKUP_PRODUCTS,
},
];
isEnabled( 'jetpack/scan-product' ) &&
output.push( {
title: translate( 'Jetpack Scan' ),
description: getJetpackProductsDescriptions()[ PRODUCT_JETPACK_SCAN ],
// There is only one option per billing interval, but this
// component still needs the full display with radio buttons.
forceRadios: true,
hasPromo: false,
id: PRODUCT_JETPACK_SCAN,
link: {
label: translate( 'Learn more' ),
props: {
location: 'product_jetpack_scan_description',
slug: 'learn-more-scan',
},
url: JETPACK_SCAN_PRODUCT_LANDING_PAGE_URL,
},
options: {
yearly: [ PRODUCT_JETPACK_SCAN ],
monthly: [ PRODUCT_JETPACK_SCAN_MONTHLY ],
},
optionShortNames: getJetpackProductsShortNames(),
optionDisplayNames: getJetpackProductsDisplayNames(),
optionDescriptions: getJetpackProductsDescriptions(),
optionsLabel: translate( 'Select a product option:' ),
slugs: JETPACK_SCAN_PRODUCTS,
} );
isEnabled( 'jetpack/anti-spam-product' ) &&
output.push( {
title: translate( 'Jetpack Anti-Spam' ),
description: getJetpackProductsDescriptions()[ PRODUCT_JETPACK_ANTI_SPAM ],
// There is only one option per billing interval, but this
// component still needs the full display with radio buttons.
forceRadios: true,
hasPromo: false,
id: PRODUCT_JETPACK_ANTI_SPAM,
link: {
label: translate( 'Learn more' ),
props: {
location: 'product_jetpack_anti_spam_description',
slug: 'learn-more-anti-spam',
},
url: JETPACK_ANTI_SPAM_PRODUCT_LANDING_PAGE_URL,
},
options: {
yearly: [ PRODUCT_JETPACK_ANTI_SPAM ],
monthly: [ PRODUCT_JETPACK_ANTI_SPAM_MONTHLY ],
},
optionShortNames: getJetpackProductsShortNames(),
optionDisplayNames: getJetpackProductsDisplayNames(),
optionDescriptions: getJetpackProductsDescriptions(),
optionsLabel: translate( 'Select a product option:' ),
slugs: JETPACK_ANTI_SPAM_PRODUCTS,
} );
isEnabled( 'jetpack/search-product' ) &&
output.push( {
title: translate( 'Jetpack Search' ),
description: getJetpackProductsDescriptions()[ PRODUCT_JETPACK_SEARCH ],
// There is only one option per billing interval, but this
// component still needs the full display with radio buttons.
forceRadios: true,
hasPromo: false,
id: PRODUCT_JETPACK_SEARCH,
link: {
label: translate( 'Learn more' ),
props: {
location: 'product_jetpack_search_description',
slug: 'learn-more-search',
},
url: JETPACK_SEARCH_PRODUCT_LANDING_PAGE_URL,
},
options: {
yearly: [ PRODUCT_JETPACK_SEARCH ],
monthly: [ PRODUCT_JETPACK_SEARCH_MONTHLY ],
},
optionShortNamesCallback: ( productObject ) => {
const numberOfDefinedTiers = 5;
switch ( productObject.price_tier_slug ) {
case JETPACK_SEARCH_TIER_UP_TO_100_RECORDS:
return translate( 'Tier 1: Up to 100 records' );
case JETPACK_SEARCH_TIER_UP_TO_1K_RECORDS:
return translate( 'Tier 2: Up to 1,000 records' );
case JETPACK_SEARCH_TIER_UP_TO_10K_RECORDS:
return translate( 'Tier 3: Up to 10,000 records' );
case JETPACK_SEARCH_TIER_UP_TO_100K_RECORDS:
return translate( 'Tier 4: Up to 100,000 records' );
case JETPACK_SEARCH_TIER_UP_TO_1M_RECORDS:
return translate( 'Tier 5: Up to 1,000,000 records' );
case JETPACK_SEARCH_TIER_MORE_THAN_1M_RECORDS: {
// This is a catch-all tier with prices increasing
// proportionally per million records, so define fake
// tiers here to show the user what they will actually
// pay and why.
const tierNumber =
numberOfDefinedTiers +
Math.floor( productObject.price_tier_usage_quantity / 1000000 );
const tierMaximumRecords =
1000000 * Math.ceil( productObject.price_tier_usage_quantity / 1000000 );
return translate( 'Tier %(tierNumber)d: Up to %(tierMaximumRecords)s records', {
args: {
tierNumber,
tierMaximumRecords: numberFormat( tierMaximumRecords ),
},
} );
}
default:
return null;
}
},
optionActionButtonNames: getJetpackProductsShortNames(),
optionDisplayNames: getJetpackProductsDisplayNames(),
optionDescriptions: getJetpackProductsDescriptions(),
optionsLabelCallback: ( productObject ) => {
return translate(
'Your current site record size: %(numberOfRecords)s record',
'Your current site record size: %(numberOfRecords)s records',
{
count: productObject.price_tier_usage_quantity,
args: {
numberOfRecords: numberFormat( productObject.price_tier_usage_quantity ),
},
}
);
},
slugs: JETPACK_SEARCH_PRODUCTS,
} );

return output;
};
18 changes: 18 additions & 0 deletions client/lib/products-values/format-product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* External dependencies
*/
import { assign } from 'lodash';

export function formatProduct( product ) {
return assign( {}, product, {
product_slug: product.product_slug || product.productSlug,
product_type: product.product_type || product.productType,
included_domain_purchase_amount:
product.included_domain_purchase_amount || product.includedDomainPurchaseAmount,
is_domain_registration:
product.is_domain_registration !== undefined
? product.is_domain_registration
: product.isDomainRegistration,
free_trial: product.free_trial || product.freeTrial,
} );
}
18 changes: 18 additions & 0 deletions client/lib/products-values/get-domain-product-ranking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Internal dependencies
*/
import { assertValidProduct } from 'lib/products-values/utils/assert-valid-product';
import { formatProduct } from 'lib/products-values/format-product';
import { isDomainRegistration } from 'lib/products-values/is-domain-registration';
import { isDomainMapping } from 'lib/products-values/is-domain-mapping';

export function getDomainProductRanking( product ) {
product = formatProduct( product );
assertValidProduct( product );

if ( isDomainRegistration( product ) ) {
return 0;
} else if ( isDomainMapping( product ) ) {
return 1;
}
}
22 changes: 22 additions & 0 deletions client/lib/products-values/get-domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* Internal dependencies
*/
import { assertValidProduct } from 'lib/products-values/utils/assert-valid-product';
import { formatProduct } from 'lib/products-values/format-product';

export function getDomain( product ) {
product = formatProduct( product );
assertValidProduct( product );

const domainToBundle = get( product, 'extra.domain_to_bundle', false );
if ( domainToBundle ) {
return domainToBundle;
}

return product.meta;
}