diff --git a/packages/admin-ui/src/app/common/utilities/get-default-config-arg-value.ts b/packages/admin-ui/src/app/common/utilities/get-default-config-arg-value.ts new file mode 100644 index 0000000000..7fcd5e795e --- /dev/null +++ b/packages/admin-ui/src/app/common/utilities/get-default-config-arg-value.ts @@ -0,0 +1,23 @@ +import { ConfigArgType } from 'shared/shared-types'; +import { assertNever } from 'shared/shared-utils'; + +import { ConfigArg, ConfigArgDefinition } from '../generated-types'; + +export function getDefaultConfigArgValue(arg: ConfigArg | ConfigArgDefinition): any { + const type = arg.type as ConfigArgType; + switch (type) { + case 'boolean': + return false; + case 'int': + case 'float': + return '0'; + case 'facetValueIds': + return []; + case 'string': + return ''; + case 'datetime': + return new Date(); + default: + assertNever(type); + } +} diff --git a/packages/admin-ui/src/app/marketing/components/promotion-detail/promotion-detail.component.ts b/packages/admin-ui/src/app/marketing/components/promotion-detail/promotion-detail.component.ts index aa302b0261..3482fa2ef3 100644 --- a/packages/admin-ui/src/app/marketing/components/promotion-detail/promotion-detail.component.ts +++ b/packages/admin-ui/src/app/marketing/components/promotion-detail/promotion-detail.component.ts @@ -16,6 +16,7 @@ import { Promotion, UpdatePromotionInput, } from '../../../common/generated-types'; +import { getDefaultConfigArgValue } from '../../../common/utilities/get-default-config-arg-value'; import { _ } from '../../../core/providers/i18n/mark-for-extraction'; import { NotificationService } from '../../../core/providers/notification/notification.service'; import { DataService } from '../../../data/providers/data.service'; @@ -233,7 +234,7 @@ export class PromotionDetailComponent extends BaseDetailComponent ({ ...output, - [arg.name]: arg.value, + [arg.name]: getDefaultConfigArgValue(arg), }), {}, ); diff --git a/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.html b/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.html index d4770922b5..fc4e687f34 100644 --- a/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.html +++ b/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.html @@ -7,7 +7,7 @@ class="btn btn-primary" *ngIf="isNew$ | async; else updateButton" (click)="create()" - [disabled]="detailForm.pristine || detailForm.invalid" + [disabled]="detailForm.pristine || detailForm.invalid || !selectedChecker || !selectedCalculator" > {{ 'common.create' | translate }} @@ -16,7 +16,7 @@ class="btn btn-primary" (click)="save()" *vdrIfPermissions="'UpdateSettings'" - [disabled]="detailForm.pristine || detailForm.invalid" + [disabled]="detailForm.pristine || detailForm.invalid || !selectedChecker || !selectedCalculator" > {{ 'common.update' | translate }} diff --git a/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.ts b/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.ts index 06e9edb2dd..c07006ec98 100644 --- a/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.ts +++ b/packages/admin-ui/src/app/settings/components/shipping-method-detail/shipping-method-detail.component.ts @@ -7,7 +7,6 @@ import { normalizeString } from 'shared/normalize-string'; import { BaseDetailComponent } from '../../../common/base-detail.component'; import { - ConfigArg, ConfigurableOperation, ConfigurableOperationDefinition, ConfigurableOperationInput, @@ -18,6 +17,7 @@ import { TestShippingMethodResult, UpdateShippingMethodInput, } from '../../../common/generated-types'; +import { getDefaultConfigArgValue } from '../../../common/utilities/get-default-config-arg-value'; import { _ } from '../../../core/providers/i18n/mark-for-extraction'; import { NotificationService } from '../../../core/providers/notification/notification.service'; import { DataService } from '../../../data/providers/data.service'; @@ -133,11 +133,21 @@ export class ShippingMethodDetailComponent extends BaseDetailComponent { return { ...arg, - value: '', + value: getDefaultConfigArgValue(arg), }; }), } as ConfigurableOperation; diff --git a/packages/admin-ui/src/app/shared/components/configurable-input/configurable-input.component.ts b/packages/admin-ui/src/app/shared/components/configurable-input/configurable-input.component.ts index 5146aeec19..aceb0dd484 100644 --- a/packages/admin-ui/src/app/shared/components/configurable-input/configurable-input.component.ts +++ b/packages/admin-ui/src/app/shared/components/configurable-input/configurable-input.component.ts @@ -23,6 +23,7 @@ import { import { Subscription } from 'rxjs'; import { StringFieldOption } from 'shared/generated-types'; import { ConfigArgType } from 'shared/shared-types'; +import { assertNever } from 'shared/shared-utils'; import { ConfigArg, @@ -31,6 +32,7 @@ import { FacetWithValues, GetActiveChannel, } from '../../../common/generated-types'; +import { getDefaultConfigArgValue } from '../../../common/utilities/get-default-config-arg-value'; import { interpolateDescription } from '../../../common/utilities/interpolate-description'; /** @@ -178,8 +180,12 @@ export class ConfigurableInputComponent implements OnChanges, OnDestroy, Control if (this.operation.args) { for (const arg of this.operation.args) { let value: any = arg.value; - if (arg.type === 'boolean') { - value = arg.value === 'true'; + if (value === undefined) { + value = getDefaultConfigArgValue(arg); + } else { + if (arg.type === 'boolean') { + value = arg.value === 'true'; + } } this.form.addControl(arg.name, new FormControl(value, Validators.required)); }