Commit 3b9b980c authored by vvempati's avatar vvempati

Inject translations and avoid avoidable logic in app component

- Removes the need to have a logic to swtich i18n in app component
- Moves planCode to the only file its being used in for simplicity
parent 3c099d39
...@@ -7,7 +7,7 @@ import { ERROR_FETCHING_DATA_HEADER, ERROR_FETCHING_DATA_DESCRIPTION } from '~/e ...@@ -7,7 +7,7 @@ import { ERROR_FETCHING_DATA_HEADER, ERROR_FETCHING_DATA_DESCRIPTION } from '~/e
import Checkout from 'ee/subscriptions/buy_addons_shared/components/checkout.vue'; import Checkout from 'ee/subscriptions/buy_addons_shared/components/checkout.vue';
import AddonPurchaseDetails from 'ee/subscriptions/buy_addons_shared/components/checkout/addon_purchase_details.vue'; import AddonPurchaseDetails from 'ee/subscriptions/buy_addons_shared/components/checkout/addon_purchase_details.vue';
import { formatNumber, sprintf } from '~/locale'; import { formatNumber, sprintf } from '~/locale';
import { CUSTOMERSDOT_CLIENT, I18N_ADDON } from 'ee/subscriptions/buy_addons_shared/constants'; import { CUSTOMERSDOT_CLIENT } from 'ee/subscriptions/buy_addons_shared/constants';
import plansQuery from 'ee/subscriptions/graphql/queries/plans.customer.query.graphql'; import plansQuery from 'ee/subscriptions/graphql/queries/plans.customer.query.graphql';
import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql'; import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql';
...@@ -20,7 +20,7 @@ export default { ...@@ -20,7 +20,7 @@ export default {
GlAlert, GlAlert,
OrderSummary, OrderSummary,
}, },
inject: ['tags'], inject: ['tags', 'i18n'],
data() { data() {
return { return {
hasError: false, hasError: false,
...@@ -28,9 +28,6 @@ export default { ...@@ -28,9 +28,6 @@ export default {
}; };
}, },
computed: { computed: {
i18n() {
return this.plan?.code ? I18N_ADDON[this.plan.code] || {} : {};
},
emptySvgPath() { emptySvgPath() {
return `data:image/svg+xml;utf8,${encodeURIComponent(emptySvg)}`; return `data:image/svg+xml;utf8,${encodeURIComponent(emptySvg)}`;
}, },
......
...@@ -6,10 +6,6 @@ export const planTags = { ...@@ -6,10 +6,6 @@ export const planTags = {
STORAGE_PLAN: 'STORAGE_PLAN', STORAGE_PLAN: 'STORAGE_PLAN',
}; };
/* eslint-enable @gitlab/require-i18n-strings */ /* eslint-enable @gitlab/require-i18n-strings */
export const planCode = {
CI_1000_MINUTES_PLAN: 'ci_minutes',
STORAGE_PLAN: 'storage',
};
export const CUSTOMERSDOT_CLIENT = 'customersDotClient'; export const CUSTOMERSDOT_CLIENT = 'customersDotClient';
export const GITLAB_CLIENT = 'gitlabClient'; export const GITLAB_CLIENT = 'gitlabClient';
...@@ -59,33 +55,28 @@ export const I18N_API_ERROR = s__( ...@@ -59,33 +55,28 @@ export const I18N_API_ERROR = s__(
); );
// Addon label translations // Addon label translations
export const I18N_ADDON = { export const I18N_CI_1000_MINUTES_PLAN = {
[planCode.CI_1000_MINUTES_PLAN]: { alertText: s__(
alertText: s__( "Checkout|CI minute packs are only used after you've used your subscription's monthly quota. The additional minutes will roll over month to month and are valid for one year.",
"Checkout|CI minute packs are only used after you've used your subscription's monthly quota. The additional minutes will roll over month to month and are valid for one year.", ),
), formula: I18N_DETAILS_FORMULA,
formula: I18N_DETAILS_FORMULA, formulaWithAlert: I18N_DETAILS_FORMULA_WITH_ALERT,
formulaWithAlert: I18N_DETAILS_FORMULA_WITH_ALERT, formulaTotal: s__('Checkout|%{quantity} CI minutes'),
formulaTotal: s__('Checkout|%{quantity} CI minutes'), pricePerUnit: s__('Checkout|$%{selectedPlanPrice} per pack of 1,000 minutes'),
pricePerUnit: s__('Checkout|$%{selectedPlanPrice} per pack of 1,000 minutes'), summaryTitle: (quantity) =>
summaryTitle: (quantity) => n__('Checkout|%d CI minute pack', 'Checkout|%d CI minute packs', quantity),
n__('Checkout|%d CI minute pack', 'Checkout|%d CI minute packs', quantity), summaryTotal: s__('Checkout|Total minutes: %{quantity}'),
summaryTotal: s__('Checkout|Total minutes: %{quantity}'), title: s__("Checkout|%{name}'s CI minutes"),
title: s__("Checkout|%{name}'s CI minutes"), };
tooltipNote: '',
}, export const I18N_STORAGE_PLAN = {
[planCode.STORAGE_PLAN]: { alertText: '',
alertText: '', formula: I18N_DETAILS_FORMULA,
formula: I18N_DETAILS_FORMULA, formulaWithAlert: I18N_DETAILS_FORMULA_WITH_ALERT,
formulaWithAlert: I18N_DETAILS_FORMULA_WITH_ALERT, formulaTotal: s__('Checkout|%{quantity} GB of storage'),
formulaTotal: s__('Checkout|%{quantity} GB of storage'), pricePerUnit: s__('Checkout|$%{selectedPlanPrice} per 10 GB storage pack per year'),
pricePerUnit: s__('Checkout|$%{selectedPlanPrice} per 10 GB storage pack per year'), summaryTitle: (quantity) =>
summaryTitle: (quantity) => n__('Checkout|%{quantity} storage pack', 'Checkout|%{quantity} storage packs', quantity),
n__('Checkout|%{quantity} storage pack', 'Checkout|%{quantity} storage packs', quantity), summaryTotal: s__('Checkout|Total storage: %{quantity} GB'),
summaryTotal: s__('Checkout|Total storage: %{quantity} GB'), title: s__("Checkout|%{name}'s storage subscription"),
title: s__("Checkout|%{name}'s storage subscription"),
tooltipNote: s__(
'Checkout|Your storage subscription has the same term as your main subscription, and the price is prorated accordingly.',
),
},
}; };
...@@ -11,12 +11,16 @@ import { ...@@ -11,12 +11,16 @@ import {
I18N_CI_MINUTES_PRODUCT_UNIT, I18N_CI_MINUTES_PRODUCT_UNIT,
I18N_STORAGE_PRODUCT_LABEL, I18N_STORAGE_PRODUCT_LABEL,
I18N_STORAGE_PRODUCT_UNIT, I18N_STORAGE_PRODUCT_UNIT,
planCode,
STORAGE_PER_PACK, STORAGE_PER_PACK,
} from 'ee/subscriptions/buy_addons_shared/constants'; } from 'ee/subscriptions/buy_addons_shared/constants';
import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql'; import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql';
import createFlash from '~/flash'; import createFlash from '~/flash';
const planCode = {
CI_1000_MINUTES_PLAN: 'ci_minutes',
STORAGE_PLAN: 'storage',
};
const planData = { const planData = {
[planCode.CI_1000_MINUTES_PLAN]: { [planCode.CI_1000_MINUTES_PLAN]: {
hasExpiration: false, hasExpiration: false,
......
import Vue from 'vue'; import Vue from 'vue';
import ensureData from '~/ensure_data'; import ensureData from '~/ensure_data';
import { planTags } from 'ee/subscriptions/buy_addons_shared/constants'; import { planTags, I18N_CI_1000_MINUTES_PLAN } from 'ee/subscriptions/buy_addons_shared/constants';
import App from 'ee/subscriptions/buy_addons_shared/components/app.vue'; import App from 'ee/subscriptions/buy_addons_shared/components/app.vue';
import { writeInitialDataToApolloCache } from '../buy_addons_shared/utils'; import { writeInitialDataToApolloCache } from '../buy_addons_shared/utils';
import apolloProvider from '../buy_addons_shared/graphql'; import apolloProvider from '../buy_addons_shared/graphql';
...@@ -16,6 +16,7 @@ export default (el) => { ...@@ -16,6 +16,7 @@ export default (el) => {
shouldLog: true, shouldLog: true,
provide: { provide: {
tags: [planTags.CI_1000_MINUTES_PLAN], tags: [planTags.CI_1000_MINUTES_PLAN],
i18n: I18N_CI_1000_MINUTES_PLAN,
}, },
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import ensureData from '~/ensure_data'; import ensureData from '~/ensure_data';
import { planTags } from 'ee/subscriptions/buy_addons_shared/constants'; import { planTags, I18N_STORAGE_PLAN } from 'ee/subscriptions/buy_addons_shared/constants';
import App from 'ee/subscriptions/buy_addons_shared/components/app.vue'; import App from 'ee/subscriptions/buy_addons_shared/components/app.vue';
import apolloProvider from '../buy_addons_shared/graphql'; import apolloProvider from '../buy_addons_shared/graphql';
import { writeInitialDataToApolloCache } from '../buy_addons_shared/utils'; import { writeInitialDataToApolloCache } from '../buy_addons_shared/utils';
...@@ -16,6 +16,7 @@ export default (el) => { ...@@ -16,6 +16,7 @@ export default (el) => {
shouldLog: true, shouldLog: true,
provide: { provide: {
tags: [planTags.STORAGE_PLAN], tags: [planTags.STORAGE_PLAN],
i18n: I18N_STORAGE_PLAN,
}, },
}); });
......
...@@ -3,9 +3,9 @@ import { createLocalVue } from '@vue/test-utils'; ...@@ -3,9 +3,9 @@ import { createLocalVue } from '@vue/test-utils';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import { pick } from 'lodash'; import { pick } from 'lodash';
import { import {
I18N_ADDON, I18N_CI_1000_MINUTES_PLAN,
I18N_STORAGE_PLAN,
I18N_API_ERROR, I18N_API_ERROR,
planCode,
planTags, planTags,
} from 'ee/subscriptions/buy_addons_shared/constants'; } from 'ee/subscriptions/buy_addons_shared/constants';
import Checkout from 'ee/subscriptions/buy_addons_shared/components/checkout.vue'; import Checkout from 'ee/subscriptions/buy_addons_shared/components/checkout.vue';
...@@ -59,6 +59,7 @@ describe('Buy Addons Shared App', () => { ...@@ -59,6 +59,7 @@ describe('Buy Addons Shared App', () => {
describe('Storage', () => { describe('Storage', () => {
const injectedProps = { const injectedProps = {
tags: [planTags.STORAGE_PLAN], tags: [planTags.STORAGE_PLAN],
i18n: I18N_STORAGE_PLAN,
}; };
describe('when data is received', () => { describe('when data is received', () => {
beforeEach(async () => { beforeEach(async () => {
...@@ -81,7 +82,7 @@ describe('Buy Addons Shared App', () => { ...@@ -81,7 +82,7 @@ describe('Buy Addons Shared App', () => {
it('provides the correct props to order summary', () => { it('provides the correct props to order summary', () => {
expect(findOrderSummary().props()).toMatchObject({ expect(findOrderSummary().props()).toMatchObject({
plan: { ...getStoragePlan, isAddon: true }, plan: { ...getStoragePlan, isAddon: true },
title: I18N_ADDON[planCode.STORAGE_PLAN].title, title: I18N_STORAGE_PLAN.title,
}); });
}); });
...@@ -185,6 +186,7 @@ describe('Buy Addons Shared App', () => { ...@@ -185,6 +186,7 @@ describe('Buy Addons Shared App', () => {
describe('CI Minutes', () => { describe('CI Minutes', () => {
const injectedProps = { const injectedProps = {
tags: [planTags.CI_1000_MINUTES_PLAN], tags: [planTags.CI_1000_MINUTES_PLAN],
i18n: I18N_CI_1000_MINUTES_PLAN,
}; };
describe('when data is received', () => { describe('when data is received', () => {
...@@ -208,7 +210,7 @@ describe('Buy Addons Shared App', () => { ...@@ -208,7 +210,7 @@ describe('Buy Addons Shared App', () => {
it('provides the correct props to order summary', () => { it('provides the correct props to order summary', () => {
expect(findOrderSummary().props()).toMatchObject({ expect(findOrderSummary().props()).toMatchObject({
plan: { ...getCiMinutesPlan, isAddon: true }, plan: { ...getCiMinutesPlan, isAddon: true },
title: I18N_ADDON[planCode.CI_1000_MINUTES_PLAN].title, title: I18N_CI_1000_MINUTES_PLAN.title,
}); });
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment