Browse Source

fix(admin-ui): Fix encoding of configurable arg values

Fixes #2539. Previously we were encoding with `.toString()` but decoding with `JSON.parse()` which
broke in the case that we saved a valid JSON string, in which case it would be parsed
into an actual object rather than a string.
Michael Bromley 2 years ago
parent
commit
84764b17c4

+ 5 - 5
packages/admin-ui/src/lib/core/src/common/utilities/configurable-operation-utils.ts

@@ -1,4 +1,4 @@
-import { ConfigArgType, CustomFieldType } from '@vendure/common/lib/shared-types';
+import { ConfigArgType } from '@vendure/common/lib/shared-types';
 import { assertNever } from '@vendure/common/lib/shared-utils';
 
 import {
@@ -22,7 +22,7 @@ export function getConfigArgValue(value: any) {
 }
 
 export function encodeConfigArgValue(value: any): string {
-    return Array.isArray(value) ? JSON.stringify(value) : (value ?? '').toString();
+    return JSON.stringify(value ?? '');
 }
 
 /**
@@ -34,9 +34,9 @@ export function configurableDefinitionToInstance(
     return {
         ...def,
         args: def.args.map(arg => ({
-                ...arg,
-                value: getDefaultConfigArgValue(arg),
-            })),
+            ...arg,
+            value: getDefaultConfigArgValue(arg),
+        })),
     } as ConfigurableOperation;
 }
 

+ 0 - 4
packages/admin-ui/src/lib/core/src/shared/components/configurable-input/configurable-input.component.ts

@@ -21,11 +21,7 @@ import {
     Validator,
     Validators,
 } from '@angular/forms';
-import { ConfigArgType } from '@vendure/common/lib/shared-types';
-import { assertNever } from '@vendure/common/lib/shared-utils';
 import { BehaviorSubject, Observable, Subscription } from 'rxjs';
-
-import { InputComponentConfig } from '../../../common/component-registry-types';
 import {
     ConfigArg,
     ConfigArgDefinition,