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 Oct 31, 2022
1 parent bad7b04 commit 369e7a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
with:
path: amplify-cli
repository: aws-amplify/amplify-cli
- name: Setup Node.js LTS
- name: Setup Node.js LTS/gallium
uses: actions/setup-node@v2
with:
node-version: lts/*
node-version: lts/gallium
- name: Build amplify-codegen-ui
working-directory: amplify-codegen-ui
run: |
Expand Down
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 @@ -5832,8 +5832,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 @@ -893,7 +893,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 @@ -905,6 +905,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
2 changes: 1 addition & 1 deletion scripts/integ-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

(cd packages/integration-test && (
(npm start &> /dev/null & npx --no-install wait-on http://localhost:3000) &&
npx --no-install cypress run -C cypress.config.ts
TZ=UTC npx --no-install cypress run -C cypress.config.ts
kill -9 `lsof -t -i :3000 -s`
))

0 comments on commit 369e7a9

Please sign in to comment.