Skip to content

Commit

Permalink
fix(admin-ui): Fix encoding of configurable arg values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelbromley committed Nov 23, 2023
1 parent 56f65cc commit 84764b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 ?? '');
}

/**
Expand All @@ -34,9 +34,9 @@ export function configurableDefinitionToInstance(
return {
...def,
args: def.args.map(arg => ({
...arg,
value: getDefaultConfigArgValue(arg),
})),
...arg,
value: getDefaultConfigArgValue(arg),
})),
} as ConfigurableOperation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

1 comment on commit 84764b1

@StampixSMO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Michael!

Please sign in to comment.