Skip to content

Commit

Permalink
feat(core): I18n for descriptions and labels of ConfigurableOperations
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
ConfigurableOperations descriptions must now be specified as an array of LocalizedString rather than just a plain string. This allows the descriptions to be adapted to other locales.
  • Loading branch information
michaelbromley committed Aug 6, 2019
1 parent d17aaa9 commit a135e15
Show file tree
Hide file tree
Showing 37 changed files with 264 additions and 176 deletions.
9 changes: 2 additions & 7 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export type ConfigArgDefinition = {
__typename?: 'ConfigArgDefinition';
name: Scalars['String'];
type: Scalars['String'];
label?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
config?: Maybe<Scalars['JSON']>;
};

Expand All @@ -230,7 +232,6 @@ export type ConfigurableOperation = {
__typename?: 'ConfigurableOperation';
code: Scalars['String'];
args: Array<ConfigArg>;
description: Scalars['String'];
};

export type ConfigurableOperationDefinition = {
Expand Down Expand Up @@ -1816,12 +1817,6 @@ export type PromotionList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type PromotionOperations = {
__typename?: 'PromotionOperations';
conditions: Array<ConfigurableOperationDefinition>;
actions: Array<ConfigurableOperationDefinition>;
};

export type Query = {
__typename?: 'Query';
activeChannel: Channel;
Expand Down
9 changes: 2 additions & 7 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ export type ConfigArgDefinition = {
__typename?: 'ConfigArgDefinition',
name: Scalars['String'],
type: Scalars['String'],
label?: Maybe<Scalars['String']>,
description?: Maybe<Scalars['String']>,
config?: Maybe<Scalars['JSON']>,
};

Expand All @@ -306,7 +308,6 @@ export type ConfigurableOperation = {
__typename?: 'ConfigurableOperation',
code: Scalars['String'],
args: Array<ConfigArg>,
description: Scalars['String'],
};

export type ConfigurableOperationDefinition = {
Expand Down Expand Up @@ -2584,12 +2585,6 @@ export type PromotionListOptions = {
filter?: Maybe<PromotionFilterParameter>,
};

export type PromotionOperations = {
__typename?: 'PromotionOperations',
conditions: Array<ConfigurableOperationDefinition>,
actions: Array<ConfigurableOperationDefinition>,
};

export type PromotionSortParameter = {
id?: Maybe<SortOrder>,
createdAt?: Maybe<SortOrder>,
Expand Down
10 changes: 2 additions & 8 deletions packages/common/src/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,8 @@ export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boo
* 1. How the argument form field is rendered in the admin-ui
* 2. The JavaScript type into which the value is coerced before being passed to the business logic.
*/
export type ConfigArgType =
| 'string'
| 'int'
| 'float'
| 'boolean'
| 'datetime'
| 'facetValueIds'
| 'stringOperator';
export type ConfigArgType = 'string' | 'int' | 'float' | 'boolean' | 'datetime' | 'facetValueIds';

export type ConfigArgSubset<T extends ConfigArgType> = T;

export type CustomFieldsObject = { [key: string]: any };
Expand Down
2 changes: 0 additions & 2 deletions packages/core/e2e/__snapshots__/collection.e2e-spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Object {
},
],
"code": "facet-value-filter",
"description": "Filter by FacetValues",
},
],
"id": "T_3",
Expand Down Expand Up @@ -109,7 +108,6 @@ Object {
},
],
"code": "facet-value-filter",
"description": "Filter by FacetValues",
},
],
"id": "T_5",
Expand Down
5 changes: 0 additions & 5 deletions packages/core/e2e/__snapshots__/promotion.e2e-spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Object {
},
],
"code": "promo_action",
"description": "description for promo_action",
},
],
"conditions": Array [
Expand All @@ -68,7 +67,6 @@ Object {
},
],
"code": "promo_condition",
"description": "description for promo_condition",
},
],
"enabled": true,
Expand All @@ -88,7 +86,6 @@ Object {
},
],
"code": "promo_action",
"description": "description for promo_action",
},
],
"conditions": Array [
Expand All @@ -101,7 +98,6 @@ Object {
},
],
"code": "promo_condition",
"description": "description for promo_condition",
},
Object {
"args": Array [
Expand All @@ -112,7 +108,6 @@ Object {
},
],
"code": "promo_condition2",
"description": "description for promo_condition2",
},
],
"enabled": true,
Expand Down
7 changes: 3 additions & 4 deletions packages/core/e2e/collection.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import gql from 'graphql-tag';
import path from 'path';

import { pick } from '../../common/lib/pick';
import { StringOperator } from '../src/common/configurable-operation';
import {
facetValueCollectionFilter,
variantNameCollectionFilter,
Expand Down Expand Up @@ -414,7 +413,7 @@ describe('Collection resolver', () => {
{
name: 'operator',
value: 'contains',
type: 'stringOperator',
type: 'string',
},
{
name: 'term',
Expand Down Expand Up @@ -662,7 +661,7 @@ describe('Collection resolver', () => {

describe('variantName filter', () => {
async function createVariantNameFilteredCollection(
operator: StringOperator,
operator: string,
term: string,
): Promise<Collection.Fragment> {
const { createCollection } = await client.query<
Expand All @@ -680,7 +679,7 @@ describe('Collection resolver', () => {
{
name: 'operator',
value: operator,
type: 'stringOperator',
type: 'string',
},
{
name: 'term',
Expand Down
2 changes: 0 additions & 2 deletions packages/core/e2e/graphql/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export const CONFIGURABLE_FRAGMENT = gql`
value
}
code
description
}
`;

Expand Down Expand Up @@ -239,7 +238,6 @@ export const COUNTRY_FRAGMENT = gql`
}
`;


export const ADDRESS_FRAGMENT = gql`
fragment Address on Address {
id
Expand Down
33 changes: 21 additions & 12 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ export type ConfigArgDefinition = {
__typename?: 'ConfigArgDefinition';
name: Scalars['String'];
type: Scalars['String'];
label?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
config?: Maybe<Scalars['JSON']>;
};

Expand All @@ -306,7 +308,6 @@ export type ConfigurableOperation = {
__typename?: 'ConfigurableOperation';
code: Scalars['String'];
args: Array<ConfigArg>;
description: Scalars['String'];
};

export type ConfigurableOperationDefinition = {
Expand Down Expand Up @@ -2518,12 +2519,6 @@ export type PromotionListOptions = {
filter?: Maybe<PromotionFilterParameter>;
};

export type PromotionOperations = {
__typename?: 'PromotionOperations';
conditions: Array<ConfigurableOperationDefinition>;
actions: Array<ConfigurableOperationDefinition>;
};

export type PromotionSortParameter = {
id?: Maybe<SortOrder>;
createdAt?: Maybe<SortOrder>;
Expand Down Expand Up @@ -3825,7 +3820,7 @@ export type RoleFragment = { __typename?: 'Role' } & Pick<

export type ConfigurableOperationFragment = { __typename?: 'ConfigurableOperation' } & Pick<
ConfigurableOperation,
'code' | 'description'
'code'
> & { args: Array<{ __typename?: 'ConfigArg' } & Pick<ConfigArg, 'name' | 'type' | 'value'>> };

export type CollectionFragment = { __typename?: 'Collection' } & Pick<
Expand Down Expand Up @@ -4601,14 +4596,23 @@ export type UpdatePromotionMutation = { __typename?: 'Mutation' } & {
updatePromotion: { __typename?: 'Promotion' } & PromotionFragment;
};

export type ConfigurableOperationDefFragment = { __typename?: 'ConfigurableOperationDefinition' } & Pick<
ConfigurableOperationDefinition,
'code' | 'description'
> & {
args: Array<
{ __typename?: 'ConfigArgDefinition' } & Pick<ConfigArgDefinition, 'name' | 'type' | 'config'>
>;
};

export type GetAdjustmentOperationsQueryVariables = {};

export type GetAdjustmentOperationsQuery = { __typename?: 'Query' } & {
promotionActions: Array<
{ __typename?: 'ConfigurableOperationDefinition' } & ConfigurableOperationFragment
{ __typename?: 'ConfigurableOperationDefinition' } & ConfigurableOperationDefFragment
>;
promotionConditions: Array<
{ __typename?: 'ConfigurableOperationDefinition' } & ConfigurableOperationFragment
{ __typename?: 'ConfigurableOperationDefinition' } & ConfigurableOperationDefFragment
>;
};

Expand Down Expand Up @@ -5716,11 +5720,16 @@ export namespace UpdatePromotion {
export type UpdatePromotion = PromotionFragment;
}

export namespace ConfigurableOperationDef {
export type Fragment = ConfigurableOperationDefFragment;
export type Args = NonNullable<ConfigurableOperationDefFragment['args'][0]>;
}

export namespace GetAdjustmentOperations {
export type Variables = GetAdjustmentOperationsQueryVariables;
export type Query = GetAdjustmentOperationsQuery;
export type PromotionActions = ConfigurableOperationFragment;
export type PromotionConditions = ConfigurableOperationFragment;
export type PromotionActions = ConfigurableOperationDefFragment;
export type PromotionConditions = ConfigurableOperationDefFragment;
}

export namespace GetRoles {
Expand Down
9 changes: 2 additions & 7 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export type ConfigArgDefinition = {
__typename?: 'ConfigArgDefinition';
name: Scalars['String'];
type: Scalars['String'];
label?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
config?: Maybe<Scalars['JSON']>;
};

Expand All @@ -230,7 +232,6 @@ export type ConfigurableOperation = {
__typename?: 'ConfigurableOperation';
code: Scalars['String'];
args: Array<ConfigArg>;
description: Scalars['String'];
};

export type ConfigurableOperationDefinition = {
Expand Down Expand Up @@ -1816,12 +1817,6 @@ export type PromotionList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type PromotionOperations = {
__typename?: 'PromotionOperations';
conditions: Array<ConfigurableOperationDefinition>;
actions: Array<ConfigurableOperationDefinition>;
};

export type Query = {
__typename?: 'Query';
activeChannel: Channel;
Expand Down
7 changes: 4 additions & 3 deletions packages/core/e2e/order.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* tslint:disable:no-non-null-assertion */
import { LanguageCode } from '@vendure/common/lib/generated-shop-types';
import gql from 'graphql-tag';
import path from 'path';

Expand Down Expand Up @@ -1145,7 +1146,7 @@ describe('Orders resolver', () => {
*/
const twoStagePaymentMethod = new PaymentMethodHandler({
code: 'authorize-only-payment-method',
description: 'Test Payment Method',
description: [{ languageCode: LanguageCode.en, value: 'Test Payment Method' }],
args: {},
createPayment: (order, args, metadata) => {
return {
Expand All @@ -1170,7 +1171,7 @@ const twoStagePaymentMethod = new PaymentMethodHandler({
*/
const singleStageRefundablePaymentMethod = new PaymentMethodHandler({
code: 'single-stage-refundable-payment-method',
description: 'Test Payment Method',
description: [{ languageCode: LanguageCode.en, value: 'Test Payment Method' }],
args: {},
createPayment: (order, args, metadata) => {
return {
Expand All @@ -1197,7 +1198,7 @@ const singleStageRefundablePaymentMethod = new PaymentMethodHandler({
*/
const failsToSettlePaymentMethod = new PaymentMethodHandler({
code: 'fails-to-settle-payment-method',
description: 'Test Payment Method',
description: [{ languageCode: LanguageCode.en, value: 'Test Payment Method' }],
args: {},
createPayment: (order, args, metadata) => {
return {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/e2e/promotion.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { pick } from '@vendure/common/lib/pick';
import gql from 'graphql-tag';
import path from 'path';

import { LanguageCode } from '../../common/lib/generated-types';
import { PromotionAction, PromotionOrderAction } from '../src/config/promotion/promotion-action';
import { PromotionCondition } from '../src/config/promotion/promotion-condition';

Expand Down Expand Up @@ -191,7 +192,7 @@ describe('Promotion resolver', () => {
function generateTestCondition(code: string): PromotionCondition<any> {
return new PromotionCondition({
code,
description: `description for ${code}`,
description: [{ languageCode: LanguageCode.en, value: `description for ${code}` }],
args: { arg: { type: 'int' } },
check: (order, args) => true,
});
Expand All @@ -200,7 +201,7 @@ function generateTestCondition(code: string): PromotionCondition<any> {
function generateTestAction(code: string): PromotionAction<any> {
return new PromotionOrderAction({
code,
description: `description for ${code}`,
description: [{ languageCode: LanguageCode.en, value: `description for ${code}` }],
args: { facetValueIds: { type: 'facetValueIds' } },
execute: (order, args) => {
return 42;
Expand Down
7 changes: 4 additions & 3 deletions packages/core/e2e/shop-order.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GetCountryList,
GetCustomer,
GetCustomerList,
LanguageCode,
UpdateCountry,
} from './graphql/generated-e2e-admin-types';
import {
Expand Down Expand Up @@ -868,7 +869,7 @@ describe('Shop orders', () => {

const testPaymentMethod = new PaymentMethodHandler({
code: 'test-payment-method',
description: 'Test Payment Method',
description: [{ languageCode: LanguageCode.en, value: 'Test Payment Method' }],
args: {},
createPayment: (order, args, metadata) => {
return {
Expand All @@ -885,7 +886,7 @@ const testPaymentMethod = new PaymentMethodHandler({

const testFailingPaymentMethod = new PaymentMethodHandler({
code: 'test-failing-payment-method',
description: 'Test Failing Payment Method',
description: [{ languageCode: LanguageCode.en, value: 'Test Failing Payment Method' }],
args: {},
createPayment: (order, args, metadata) => {
return {
Expand All @@ -901,7 +902,7 @@ const testFailingPaymentMethod = new PaymentMethodHandler({

const testErrorPaymentMethod = new PaymentMethodHandler({
code: 'test-error-payment-method',
description: 'Test Error Payment Method',
description: [{ languageCode: LanguageCode.en, value: 'Test Error Payment Method' }],
args: {},
createPayment: (order, args, metadata) => {
return {
Expand Down
Loading

0 comments on commit a135e15

Please sign in to comment.