Skip to content

Commit

Permalink
fix: updating snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
bombguy committed Apr 5, 2023
1 parent 752e379 commit f97fa3d
Showing 1 changed file with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24993,7 +24993,7 @@ export default function CreateProductForm(props) {
"
`;

exports[`amplify form renderer tests forms with StorageField tests should render a create form with StorageField on non-array field 1`] = `
exports[`amplify form renderer tests forms with StorageField tests should render a update form with StorageField 1`] = `
"/* eslint-disable */
import * as React from \\"react\\";
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
Expand All @@ -25016,20 +25016,18 @@ export default function UpdateProductForm(props) {
} = props;
const initialValues = {
name: \\"\\",
singleImgKey: undefined,
imgKeys: [],
};
const [name, setName] = React.useState(initialValues.name);
const [singleImgKey, setSingleImgKey] = React.useState(
initialValues.singleImgKey
);
const singleImgKeyRef = React.useRef([]);
const [imgKeys, setImgKeys] = React.useState(initialValues.imgKeys);
const imgKeysRef = React.useRef([]);
const [errors, setErrors] = React.useState({});
const resetStateValues = () => {
const cleanValues = productRecord
? { ...initialValues, ...productRecord }
: initialValues;
setName(cleanValues.name);
setSingleImgKey(cleanValues.singleImgKey);
setImgKeys(cleanValues.imgKeys ?? []);
setErrors({});
};
const [productRecord, setProductRecord] = React.useState(productModelProp);
Expand All @@ -25045,7 +25043,7 @@ export default function UpdateProductForm(props) {
React.useEffect(resetStateValues, [productRecord]);
const validations = {
name: [],
singleImgKey: [],
imgKeys: [],
};
const runValidationTasks = async (
fieldName,
Expand Down Expand Up @@ -25074,7 +25072,7 @@ export default function UpdateProductForm(props) {
event.preventDefault();
let modelFields = {
name,
singleImgKey,
imgKeys,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -25131,7 +25129,7 @@ export default function UpdateProductForm(props) {
if (onChange) {
const modelFields = {
name: value,
singleImgKey,
imgKeys,
};
const result = onChange(modelFields);
value = result?.name ?? value;
Expand All @@ -25147,36 +25145,34 @@ export default function UpdateProductForm(props) {
{...getOverrideProps(overrides, \\"name\\")}
></TextField>
<Field
errorMessage={errors.singleImgKey?.errorMessage}
hasError={errors.singleImgKey?.hasError}
label={\\"Single Image\\"}
errorMessage={errors.imgKeys?.errorMessage}
hasError={errors.imgKeys?.hasError}
label={\\"Images\\"}
isRequired={false}
isReadOnly={false}
>
<StorageManager
ref={singleImgKeyRef}
defaultFiles={[{ s3Key: singleImgKey }]}
ref={imgKeysRef}
defaultFiles={imgKeys.map((s3Key) => ({ s3Key }))}
onFileSuccess={(files) => {
let value = files?.[0]?.s3Key;
let value = files.map(({ s3Key }) => s3Key);
if (onChange) {
const modelFields = {
name,
singleImgKey: value,
imgKeys: value,
};
const result = onChange(modelFields);
value = result?.singleImgKey ?? value;
value = result?.imgKeys ?? value;
}
if (errors.singleImgKey?.hasError) {
runValidationTasks(\\"singleImgKey\\", value);
if (errors.imgKeys?.hasError) {
runValidationTasks(\\"imgKeys\\", value);
}
setSingleImgKey(value);
setImgKeys(value);
}}
accessLevel={\\"protected\\"}
acceptedFileTypes={[\\".txt\\", \\".pdf\\"]}
isResumable={true}
showThumbnails={false}
maxFileCount={1}
maxSize={1024}
accessLevel={\\"private\\"}
acceptedFileTypes={[\\".doc\\", \\".pdf\\"]}
isResumable={false}
showThumbnails={true}
></StorageManager>
</Field>
<Flex
Expand Down Expand Up @@ -25215,7 +25211,7 @@ export default function UpdateProductForm(props) {
"
`;

exports[`amplify form renderer tests forms with StorageField tests should render a update form with StorageField 1`] = `
exports[`amplify form renderer tests forms with StorageField tests should render a update form with StorageField on non-array field 1`] = `
"/* eslint-disable */
import * as React from \\"react\\";
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
Expand All @@ -25238,18 +25234,20 @@ export default function UpdateProductForm(props) {
} = props;
const initialValues = {
name: \\"\\",
imgKeys: [],
singleImgKey: undefined,
};
const [name, setName] = React.useState(initialValues.name);
const [imgKeys, setImgKeys] = React.useState(initialValues.imgKeys);
const imgKeysRef = React.useRef([]);
const [singleImgKey, setSingleImgKey] = React.useState(
initialValues.singleImgKey
);
const singleImgKeyRef = React.useRef([]);
const [errors, setErrors] = React.useState({});
const resetStateValues = () => {
const cleanValues = productRecord
? { ...initialValues, ...productRecord }
: initialValues;
setName(cleanValues.name);
setImgKeys(cleanValues.imgKeys ?? []);
setSingleImgKey(cleanValues.singleImgKey);
setErrors({});
};
const [productRecord, setProductRecord] = React.useState(productModelProp);
Expand All @@ -25265,7 +25263,7 @@ export default function UpdateProductForm(props) {
React.useEffect(resetStateValues, [productRecord]);
const validations = {
name: [],
imgKeys: [],
singleImgKey: [],
};
const runValidationTasks = async (
fieldName,
Expand Down Expand Up @@ -25294,7 +25292,7 @@ export default function UpdateProductForm(props) {
event.preventDefault();
let modelFields = {
name,
imgKeys,
singleImgKey,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -25351,7 +25349,7 @@ export default function UpdateProductForm(props) {
if (onChange) {
const modelFields = {
name: value,
imgKeys,
singleImgKey,
};
const result = onChange(modelFields);
value = result?.name ?? value;
Expand All @@ -25367,34 +25365,36 @@ export default function UpdateProductForm(props) {
{...getOverrideProps(overrides, \\"name\\")}
></TextField>
<Field
errorMessage={errors.imgKeys?.errorMessage}
hasError={errors.imgKeys?.hasError}
label={\\"Images\\"}
errorMessage={errors.singleImgKey?.errorMessage}
hasError={errors.singleImgKey?.hasError}
label={\\"Single Image\\"}
isRequired={false}
isReadOnly={false}
>
<StorageManager
ref={imgKeysRef}
defaultFiles={imgKeys.map((s3Key) => ({ s3Key }))}
ref={singleImgKeyRef}
defaultFiles={[{ s3Key: singleImgKey }]}
onFileSuccess={(files) => {
let value = files.map(({ s3Key }) => s3Key);
let value = files?.[0]?.s3Key;
if (onChange) {
const modelFields = {
name,
imgKeys: value,
singleImgKey: value,
};
const result = onChange(modelFields);
value = result?.imgKeys ?? value;
value = result?.singleImgKey ?? value;
}
if (errors.imgKeys?.hasError) {
runValidationTasks(\\"imgKeys\\", value);
if (errors.singleImgKey?.hasError) {
runValidationTasks(\\"singleImgKey\\", value);
}
setImgKeys(value);
setSingleImgKey(value);
}}
accessLevel={\\"private\\"}
acceptedFileTypes={[\\".doc\\", \\".pdf\\"]}
isResumable={false}
showThumbnails={true}
accessLevel={\\"protected\\"}
acceptedFileTypes={[\\".txt\\", \\".pdf\\"]}
isResumable={true}
showThumbnails={false}
maxFileCount={1}
maxSize={1024}
></StorageManager>
</Field>
<Flex
Expand Down

0 comments on commit f97fa3d

Please sign in to comment.