|
|
@@ -4,30 +4,25 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
import {
|
|
|
BaseDetailComponent,
|
|
|
+ configurableDefinitionToInstance,
|
|
|
ConfigurableOperation,
|
|
|
ConfigurableOperationDefinition,
|
|
|
- ConfigurableOperationInput,
|
|
|
- CreateFacetInput,
|
|
|
CreateShippingMethodInput,
|
|
|
createUpdatedTranslatable,
|
|
|
CustomFieldConfig,
|
|
|
DataService,
|
|
|
- encodeConfigArgValue,
|
|
|
- FacetWithValues,
|
|
|
GetActiveChannel,
|
|
|
getConfigArgValue,
|
|
|
- getDefaultConfigArgValue,
|
|
|
LanguageCode,
|
|
|
NotificationService,
|
|
|
ServerConfigService,
|
|
|
ShippingMethod,
|
|
|
TestShippingMethodInput,
|
|
|
TestShippingMethodResult,
|
|
|
- UpdateFacetInput,
|
|
|
+ toConfigurableOperationInput,
|
|
|
UpdateShippingMethodInput,
|
|
|
} from '@vendure/admin-ui/core';
|
|
|
import { normalizeString } from '@vendure/common/lib/normalize-string';
|
|
|
-import { ConfigArgType } from '@vendure/common/lib/shared-types';
|
|
|
import { combineLatest, merge, Observable, of, Subject } from 'rxjs';
|
|
|
import { mergeMap, switchMap, take, takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
@@ -114,11 +109,8 @@ export class ShippingMethodDetailComponent
|
|
|
const input: TestShippingMethodInput = {
|
|
|
shippingAddress: { ...address, streetLine1: 'test' },
|
|
|
lines: lines.map(l => ({ productVariantId: l.id, quantity: l.quantity })),
|
|
|
- checker: this.toAdjustmentOperationInput(this.selectedChecker, formValue.checker),
|
|
|
- calculator: this.toAdjustmentOperationInput(
|
|
|
- this.selectedCalculator,
|
|
|
- formValue.calculator,
|
|
|
- ),
|
|
|
+ checker: toConfigurableOperationInput(this.selectedChecker, formValue.checker),
|
|
|
+ calculator: toConfigurableOperationInput(this.selectedCalculator, formValue.calculator),
|
|
|
};
|
|
|
return this.dataService.shippingMethod
|
|
|
.testShippingMethod(input)
|
|
|
@@ -155,7 +147,7 @@ export class ShippingMethodDetailComponent
|
|
|
|
|
|
selectChecker(checker: ConfigurableOperationDefinition) {
|
|
|
this.selectedCheckerDefinition = checker;
|
|
|
- this.selectedChecker = this.configurableDefinitionToInstance(checker);
|
|
|
+ this.selectedChecker = configurableDefinitionToInstance(checker);
|
|
|
const formControl = this.detailForm.get('checker');
|
|
|
if (formControl) {
|
|
|
formControl.patchValue(this.selectedChecker);
|
|
|
@@ -165,7 +157,7 @@ export class ShippingMethodDetailComponent
|
|
|
|
|
|
selectCalculator(calculator: ConfigurableOperationDefinition) {
|
|
|
this.selectedCalculatorDefinition = calculator;
|
|
|
- this.selectedCalculator = this.configurableDefinitionToInstance(calculator);
|
|
|
+ this.selectedCalculator = configurableDefinitionToInstance(calculator);
|
|
|
const formControl = this.detailForm.get('calculator');
|
|
|
if (formControl) {
|
|
|
formControl.patchValue(this.selectedCalculator);
|
|
|
@@ -173,18 +165,6 @@ export class ShippingMethodDetailComponent
|
|
|
this.detailForm.markAsDirty();
|
|
|
}
|
|
|
|
|
|
- private configurableDefinitionToInstance(def: ConfigurableOperationDefinition): ConfigurableOperation {
|
|
|
- return {
|
|
|
- ...def,
|
|
|
- args: def.args.map(arg => {
|
|
|
- return {
|
|
|
- ...arg,
|
|
|
- value: getDefaultConfigArgValue(arg),
|
|
|
- };
|
|
|
- }),
|
|
|
- } as ConfigurableOperation;
|
|
|
- }
|
|
|
-
|
|
|
create() {
|
|
|
const selectedChecker = this.selectedChecker;
|
|
|
const selectedCalculator = this.selectedCalculator;
|
|
|
@@ -202,8 +182,8 @@ export class ShippingMethodDetailComponent
|
|
|
this.detailForm,
|
|
|
languageCode,
|
|
|
) as CreateShippingMethodInput),
|
|
|
- checker: this.toAdjustmentOperationInput(selectedChecker, formValue.checker),
|
|
|
- calculator: this.toAdjustmentOperationInput(selectedCalculator, formValue.calculator),
|
|
|
+ checker: toConfigurableOperationInput(selectedChecker, formValue.checker),
|
|
|
+ calculator: toConfigurableOperationInput(selectedCalculator, formValue.calculator),
|
|
|
};
|
|
|
return this.dataService.shippingMethod.createShippingMethod(input);
|
|
|
}),
|
|
|
@@ -242,8 +222,8 @@ export class ShippingMethodDetailComponent
|
|
|
this.detailForm,
|
|
|
languageCode,
|
|
|
) as UpdateShippingMethodInput),
|
|
|
- checker: this.toAdjustmentOperationInput(selectedChecker, formValue.checker),
|
|
|
- calculator: this.toAdjustmentOperationInput(selectedCalculator, formValue.calculator),
|
|
|
+ checker: toConfigurableOperationInput(selectedChecker, formValue.checker),
|
|
|
+ calculator: toConfigurableOperationInput(selectedCalculator, formValue.calculator),
|
|
|
};
|
|
|
return this.dataService.shippingMethod.updateShippingMethod(input);
|
|
|
}),
|
|
|
@@ -313,24 +293,6 @@ export class ShippingMethodDetailComponent
|
|
|
return { ...input, fulfillmentHandler: formValue.fulfillmentHandler };
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Maps an array of conditions or actions to the input format expected by the GraphQL API.
|
|
|
- */
|
|
|
- private toAdjustmentOperationInput(
|
|
|
- operation: ConfigurableOperation,
|
|
|
- formValueOperations: any,
|
|
|
- ): ConfigurableOperationInput {
|
|
|
- return {
|
|
|
- code: operation.code,
|
|
|
- arguments: Object.values<any>(formValueOperations.args || {}).map((value, j) => ({
|
|
|
- name: operation.args[j].name,
|
|
|
- value: value.hasOwnProperty('value')
|
|
|
- ? encodeConfigArgValue((value as any).value)
|
|
|
- : encodeConfigArgValue(value),
|
|
|
- })),
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
protected setFormValues(shippingMethod: ShippingMethod.Fragment, languageCode: LanguageCode): void {
|
|
|
const currentTranslation = shippingMethod.translations.find(t => t.languageCode === languageCode);
|
|
|
this.detailForm.patchValue({
|