Skip to content

Commit

Permalink
fix: allow empty string for url field (#735)
Browse files Browse the repository at this point in the history
* chore: set timezone to UTC before starting cypress tests (#730)

* chore: set timezone to UTC before starting cypress tests

* fix: cli test fix

Co-authored-by: Brandon Lyons <lyonsbp@amazon.com>
Co-authored-by: Scott Young <scoyou@amazon.com>

* fix: allow empty string for url field

Co-authored-by: Brandon Lyons <lyonsbp@amazon.com>
Co-authored-by: Scott Young <scoyou@amazon.com>
Co-authored-by: Justin Shih <jushih@amazon.com>
  • Loading branch information
4 people committed Nov 3, 2022
1 parent 7ab3126 commit 2e50ca5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,9 @@ export default function MyPostForm(props) {
username,
caption,
Customtags,
post_url,
post_url: post_url || undefined,
metadata,
profile_url,
profile_url: profile_url || undefined,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -3045,9 +3045,9 @@ export default function MyPostForm(props) {
let modelFields = {
caption,
username,
post_url,
post_url: post_url || undefined,
metadata,
profile_url,
profile_url: profile_url || undefined,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -3400,8 +3400,8 @@ export default function MyPostForm(props) {
TextAreaFieldbbd63464,
caption,
username,
profile_url,
post_url,
profile_url: profile_url || undefined,
post_url: post_url || undefined,
metadata,
};
const validationResponses = await Promise.all(
Expand Down Expand Up @@ -5834,8 +5834,8 @@ export default function PostCreateFormRow(props) {
let modelFields = {
username,
caption,
post_url,
profile_url,
post_url: post_url || undefined,
profile_url: profile_url || undefined,
status,
metadata,
};
Expand Down
18 changes: 17 additions & 1 deletion packages/codegen-ui-react/lib/forms/form-renderer-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ export const buildModelFieldObject = (
const fieldSet = new Set<string>();
const fields = Object.keys(fieldConfigs).reduce<ObjectLiteralElementLike[]>((acc, value) => {
const fieldName = value.split('.')[0];
const { sanitizedFieldName } = fieldConfigs[value];
const { sanitizedFieldName, dataType } = fieldConfigs[value];
const renderedFieldName = sanitizedFieldName || fieldName;
if (!fieldSet.has(renderedFieldName)) {
let assignment = nameOverrides[fieldName]
Expand All @@ -928,6 +928,22 @@ export const buildModelFieldObject = (
factory.createIdentifier(sanitizedFieldName),
);
}
/*
Empty string value for not required url field fails to save at datastore
let modelFields = {
url: url || undefined,
}
*/
if (dataType === 'AWSURL' && !shouldBeConst) {
assignment = factory.createPropertyAssignment(
factory.createStringLiteral(fieldName),
factory.createBinaryExpression(
factory.createIdentifier(renderedFieldName),
factory.createToken(SyntaxKind.BarBarToken),
factory.createIdentifier('undefined'),
),
);
}

acc.push(assignment);
fieldSet.add(renderedFieldName);
Expand Down

0 comments on commit 2e50ca5

Please sign in to comment.