Browse Source

chore(admin-ui): Alternate solution for #2539

The prior solution in https://github.com/vendure-ecommerce/vendure/commit/84764b17c471a983b7bae49b9d840068875246f3
is potentially too far-reaching a change. This is a more
localized approach which is less likely to have
unwanted side-effects.
Michael Bromley 2 years ago
parent
commit
c1b806231a

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

@@ -15,14 +15,21 @@ import {
  */
 export function getConfigArgValue(value: any) {
     try {
-        return value != null ? JSON.parse(value) : undefined;
+        const result = value != null ? JSON.parse(value) : undefined;
+        if (result && typeof result === 'object' && !Array.isArray(result)) {
+            // There is an edge-case where the value is a valid JSON-encoded string and
+            // will get parsed as an object, but we actually want it to be a string.
+            return JSON.stringify(result);
+        } else {
+            return result;
+        }
     } catch (e: any) {
         return value;
     }
 }
 
 export function encodeConfigArgValue(value: any): string {
-    return JSON.stringify(value ?? '');
+    return Array.isArray(value) ? JSON.stringify(value) : (value ?? '').toString();
 }
 
 /**