Skip to content

Commit

Permalink
Tagged release/forms and views (#555)
Browse files Browse the repository at this point in the history
* chore: update view types to use string primitives (#535)

* chore: update validation type to match model (#545)

Co-authored-by: Justin Shih <jushih@amazon.com>

* chore: tidying forms renderer (#549)

Co-authored-by: Justin Shih <jushih@amazon.com>

* chore: update react import & updated factory methods for import collection (#551)

Co-authored-by: awinberg-aws <100880084+awinberg-aws@users.noreply.github.com>
Co-authored-by: Justin Shih <36183898+Jshhhh@users.noreply.github.com>
Co-authored-by: Justin Shih <jushih@amazon.com>
Co-authored-by: Josue Ruiz <7465495+SwaySway@users.noreply.github.com>
  • Loading branch information
5 people authored Aug 3, 2022
1 parent af9265d commit 118cc6f
Show file tree
Hide file tree
Showing 28 changed files with 1,757 additions and 1,165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`react-studio-template-renderer-helper transpile fails to transpile with
exports[`react-studio-template-renderer-helper transpile fails to transpile with ScriptTarget Latest 1`] = `"ScriptTarget 99 not supported with type declarations enabled, expected one of [0,1,2,3,4,5,6,7,8]"`;

exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES3 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -24,7 +24,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES5 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -35,7 +35,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES2015 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -46,7 +46,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES2016 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -57,7 +57,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES2017 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -68,7 +68,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES2018 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -79,7 +79,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES2019 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -90,7 +90,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES2020 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand All @@ -101,7 +101,7 @@ export default function CustomParentAndChildren(props: CustomParentAndChildrenPr
`;
exports[`react-studio-template-renderer-helper transpile successfully transpiles with ScriptTarget ES2021 1`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { ViewTestProps } from \\"./ViewTest\\";
export declare type CustomParentAndChildrenProps = React.PropsWithChildren<Partial<ViewTestProps> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`amplify form renderer tests custom form tests should render a custom backed form 1`] = `
"/* eslint-disable */
import React from \\"react\\";
import * as React from \\"react\\";
import { validateField } from \\"./utils.js\\";
import {
getOverrideProps,
Expand All @@ -14,25 +14,23 @@ export default function customDataForm(props) {
const {
onSubmit: customDataFormOnSubmit,
onCancel,
onValidate,
overrides,
...rest
} = props;
const [nameFieldError, setNameFieldError] = useStateMutationAction({});
const [emailFieldError, setEmailFieldError] = useStateMutationAction({});
const [customDataFormFields, setCustomDataFormFields] =
useStateMutationAction({});
const [modelFields, setModelFields] = useStateMutationAction({});
const [formValid, setFormValid] = useStateMutationAction(true);
return (
<form
onSubmit={async (event) => {
event.preventDefault();
if (onSubmitBefore) {
setCustomDataFormFields(
onSubmitBefore({ fields: customDataFormFields })
);
setModelFields(onSubmitBefore({ fields: modelFields }));
}
try {
await DataStore.save(new Post(customDataFormFields));
await DataStore.save(new Post(modelFields));
if (onSubmitComplete) {
onSubmitComplete({ saveSuccessful: true });
}
Expand Down Expand Up @@ -137,7 +135,7 @@ export default function customDataForm(props) {
`;
exports[`amplify form renderer tests custom form tests should render a custom backed form 2`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
export declare type customDataFormProps = React.PropsWithChildren<{
overrides?: EscapeHatchProps | undefined | null;
Expand All @@ -151,36 +149,44 @@ export default function customDataForm(props: customDataFormProps): React.ReactE
exports[`amplify form renderer tests datastore form tests should generate a create form 1`] = `
"/* eslint-disable */
import React from \\"react\\";
import * as React from \\"react\\";
import { validateField } from \\"./utils.js\\";
import {
getOverrideProps,
useDataStoreCreateAction,
useStateMutationAction,
} from \\"@aws-amplify/ui-react/internal\\";
import { Post } from \\"../models\\";
import { schema } from \\"../models/schema\\";
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
import { DataStore } from \\"aws-amplify\\";
export default function myPostForm(props) {
const { onSubmitBefore, onSubmitComplete, onCancel, overrides, ...rest } =
props;
const [myPostFormFields, setMyPostFormFields] = useStateMutationAction({});
const {
onSubmitBefore,
onSubmitComplete,
onCancel,
onValidate,
overrides,
...rest
} = props;
const [captionFieldError, setCaptionFieldError] = useStateMutationAction({});
const [usernameFieldError, setUsernameFieldError] = useStateMutationAction(
{}
);
const [post_urlFieldError, setPost_urlFieldError] = useStateMutationAction(
{}
);
const [profile_urlFieldError, setProfile_urlFieldError] =
useStateMutationAction({});
const [modelFields, setModelFields] = useStateMutationAction({});
const [formValid, setFormValid] = useStateMutationAction(true);
const myPostFormOnSubmit = useDataStoreCreateAction({
model: Post,
fields: myPostFormFields,
schema: schema,
});
return (
<form
onSubmit={async (event) => {
event.preventDefault();
if (onSubmitBefore) {
setMyPostFormFields(onSubmitBefore({ fields: myPostFormFields }));
setModelFields(onSubmitBefore({ fields: modelFields }));
}
try {
await DataStore.save(new Post(myPostFormFields));
await DataStore.save(new Post(modelFields));
if (onSubmitComplete) {
onSubmitComplete({ saveSuccessful: true });
}
Expand Down Expand Up @@ -215,7 +221,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"caption\\"]
? await onValidate[\\"caption\\"](value)
: validateField(value, caption - validation - rules);
: validateField(
value,
undefined - caption - validation - rules
);
setCaptionFieldError({ ...captionFieldError, ...isValidResult });
setFormValid(!captionFieldError.hasError);
setModelFields({ ...modelFields, caption: value });
Expand All @@ -239,7 +248,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"username\\"]
? await onValidate[\\"username\\"](value)
: validateField(value, username - validation - rules);
: validateField(
value,
undefined - username - validation - rules
);
setUsernameFieldError({
...usernameFieldError,
...isValidResult,
Expand All @@ -266,7 +278,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"post_url\\"]
? await onValidate[\\"post_url\\"](value)
: validateField(value, post_url - validation - rules);
: validateField(
value,
undefined - post_url - validation - rules
);
setPost_urlFieldError({
...post_urlFieldError,
...isValidResult,
Expand All @@ -293,7 +308,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"profile_url\\"]
? await onValidate[\\"profile_url\\"](value)
: validateField(value, profile_url - validation - rules);
: validateField(
value,
undefined - profile_url - validation - rules
);
setProfile_urlFieldError({
...profile_urlFieldError,
...isValidResult,
Expand Down Expand Up @@ -342,7 +360,7 @@ export default function myPostForm(props) {
`;
exports[`amplify form renderer tests datastore form tests should generate a create form 2`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
export declare type myPostFormProps = React.PropsWithChildren<{
overrides?: EscapeHatchProps | undefined | null;
Expand All @@ -360,37 +378,45 @@ export default function myPostForm(props: myPostFormProps): React.ReactElement;
exports[`amplify form renderer tests datastore form tests should generate a update form 1`] = `
"/* eslint-disable */
import React from \\"react\\";
import * as React from \\"react\\";
import { validateField } from \\"./utils.js\\";
import {
getOverrideProps,
useDataStoreUpdateAction,
useStateMutationAction,
} from \\"@aws-amplify/ui-react/internal\\";
import { Post } from \\"../models\\";
import { schema } from \\"../models/schema\\";
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
import { DataStore } from \\"aws-amplify\\";
export default function myPostForm(props) {
const { id, onSubmitBefore, onSubmitComplete, onCancel, overrides, ...rest } =
props;
const [myPostFormFields, setMyPostFormFields] = useStateMutationAction({});
const {
id,
onSubmitBefore,
onSubmitComplete,
onCancel,
onValidate,
overrides,
...rest
} = props;
const [captionFieldError, setCaptionFieldError] = useStateMutationAction({});
const [usernameFieldError, setUsernameFieldError] = useStateMutationAction(
{}
);
const [post_urlFieldError, setPost_urlFieldError] = useStateMutationAction(
{}
);
const [profile_urlFieldError, setProfile_urlFieldError] =
useStateMutationAction({});
const [modelFields, setModelFields] = useStateMutationAction({});
const [formValid, setFormValid] = useStateMutationAction(true);
const myPostFormOnSubmit = useDataStoreUpdateAction({
model: Post,
fields: myPostFormFields,
id: id,
schema: schema,
});
return (
<form
onSubmit={async (event) => {
event.preventDefault();
if (onSubmitBefore) {
setMyPostFormFields(onSubmitBefore({ fields: myPostFormFields }));
setModelFields(onSubmitBefore({ fields: modelFields }));
}
try {
await DataStore.save(new Post(myPostFormFields));
await DataStore.save(new Post(modelFields));
if (onSubmitComplete) {
onSubmitComplete({ saveSuccessful: true });
}
Expand Down Expand Up @@ -425,7 +451,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"caption\\"]
? await onValidate[\\"caption\\"](value)
: validateField(value, caption - validation - rules);
: validateField(
value,
undefined - caption - validation - rules
);
setCaptionFieldError({ ...captionFieldError, ...isValidResult });
setFormValid(!captionFieldError.hasError);
setModelFields({ ...modelFields, caption: value });
Expand All @@ -449,7 +478,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"username\\"]
? await onValidate[\\"username\\"](value)
: validateField(value, username - validation - rules);
: validateField(
value,
undefined - username - validation - rules
);
setUsernameFieldError({
...usernameFieldError,
...isValidResult,
Expand All @@ -476,7 +508,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"post_url\\"]
? await onValidate[\\"post_url\\"](value)
: validateField(value, post_url - validation - rules);
: validateField(
value,
undefined - post_url - validation - rules
);
setPost_urlFieldError({
...post_urlFieldError,
...isValidResult,
Expand All @@ -503,7 +538,10 @@ export default function myPostForm(props) {
const { value } = e.target;
const isValidResult = onValidate?.[\\"profile_url\\"]
? await onValidate[\\"profile_url\\"](value)
: validateField(value, profile_url - validation - rules);
: validateField(
value,
undefined - profile_url - validation - rules
);
setProfile_urlFieldError({
...profile_urlFieldError,
...isValidResult,
Expand Down Expand Up @@ -552,7 +590,7 @@ export default function myPostForm(props) {
`;
exports[`amplify form renderer tests datastore form tests should generate a update form 2`] = `
"import React from \\"react\\";
"import * as React from \\"react\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
export declare type myPostFormProps = React.PropsWithChildren<{
overrides?: EscapeHatchProps | undefined | null;
Expand Down
Loading

0 comments on commit 118cc6f

Please sign in to comment.