Skip to content

Commit

Permalink
fix: fix value passed to onChange override
Browse files Browse the repository at this point in the history
  • Loading branch information
Hein Jeong authored and hein-j committed Nov 17, 2022
1 parent f62a8ad commit d30aacf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export default function CustomDataForm(props) {
const modelFields = {
name,
email,
\\"metadata-field\\": metadatafield,
\\"metadata-field\\": value,
city,
category,
pages,
Expand Down Expand Up @@ -2002,7 +2002,7 @@ export default function NestedJson(props) {
let { value } = e.target;
if (onChange) {
const modelFields = {
\\"first-Name\\": firstName,
\\"first-Name\\": value,
lastName,
bio,
Nicknames1,
Expand Down Expand Up @@ -2211,7 +2211,7 @@ export default function NestedJson(props) {
lastName,
bio,
Nicknames1,
\\"nick-names2\\": nicknames,
\\"nick-names2\\": values,
\\"first Name\\": firstName1,
};
const result = onChange(modelFields);
Expand Down Expand Up @@ -2258,7 +2258,7 @@ export default function NestedJson(props) {
bio,
Nicknames1,
\\"nick-names2\\": nicknames,
\\"first Name\\": firstName1,
\\"first Name\\": value,
};
const result = onChange(modelFields);
value = result?.[\\"first Name\\"] ?? value;
Expand Down Expand Up @@ -2645,7 +2645,7 @@ export default function NestedJson(props) {
if (onChange) {
const modelFields = {
firstName,
\\"last-Name\\": lastName,
\\"last-Name\\": value,
lastName: lastName1,
bio,
};
Expand All @@ -2669,7 +2669,7 @@ export default function NestedJson(props) {
const modelFields = {
firstName,
\\"last-Name\\": lastName,
lastName: lastName1,
lastName: values,
bio,
};
const result = onChange(modelFields);
Expand Down Expand Up @@ -4685,7 +4685,7 @@ export default function BlogCreateForm(props) {
const modelFields = {
title,
content,
switch: switch1,
switch: value,
published,
editedAt,
};
Expand Down
17 changes: 10 additions & 7 deletions packages/codegen-ui-react/lib/forms/form-renderer-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ export const buildOverrideOnChangeStatement = (
const keyName = keyPath[0];
const valueName = valueNameOverride ?? factory.createIdentifier('value');
let keyValueExpression = factory.createPropertyAssignment(
isValidVariableName(keyName)
? factory.createIdentifier(keyName)
: factory.createComputedPropertyName(factory.createStringLiteral(keyName)),
isValidVariableName(keyName) ? factory.createIdentifier(keyName) : factory.createStringLiteral(keyName),
valueName,
);
if (keyPath.length > 1) {
Expand Down Expand Up @@ -920,10 +918,15 @@ export const buildModelFieldObject = (
const { sanitizedFieldName, dataType } = fieldConfigs[value];
const renderedFieldName = sanitizedFieldName || fieldName;
if (!fieldSet.has(renderedFieldName)) {
let assignment = nameOverrides[fieldName]
? nameOverrides[fieldName]
: factory.createShorthandPropertyAssignment(factory.createIdentifier(fieldName), undefined);
if (sanitizedFieldName) {
let assignment: ObjectLiteralElementLike = factory.createShorthandPropertyAssignment(
factory.createIdentifier(fieldName),
undefined,
);

if (nameOverrides[fieldName]) {
assignment = nameOverrides[fieldName];
} else if (sanitizedFieldName) {
// if overrides present, ignore sanitizedFieldName
assignment = factory.createPropertyAssignment(
factory.createStringLiteral(fieldName),
factory.createIdentifier(sanitizedFieldName),
Expand Down

0 comments on commit d30aacf

Please sign in to comment.