Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix storage field prop import to storagemanager #1016

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24848,10 +24848,10 @@ exports[`amplify form renderer tests forms with StorageField tests should render
"/* eslint-disable */
import * as React from \\"react\\";
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
import { Field, getOverrideProps } from \\"@aws-amplify/ui-react/internal\\";
import { Product } from \\"../models\\";
import { fetchByPath, processFile, validateField } from \\"./utils\\";
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
import { DataStore } from \\"aws-amplify\\";
export default function CreateProductForm(props) {
const {
Expand Down Expand Up @@ -25059,10 +25059,10 @@ exports[`amplify form renderer tests forms with StorageField tests should render
"/* eslint-disable */
import * as React from \\"react\\";
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
import { Field, getOverrideProps } from \\"@aws-amplify/ui-react/internal\\";
import { Product } from \\"../models\\";
import { fetchByPath, processFile, validateField } from \\"./utils\\";
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
import { DataStore } from \\"aws-amplify\\";
export default function UpdateProductForm(props) {
const {
Expand Down Expand Up @@ -25287,14 +25287,54 @@ export default function UpdateProductForm(props) {
"
`;

exports[`amplify form renderer tests forms with StorageField tests should render a update form with StorageField 2`] = `
"import * as React from \\"react\\";
import { GridProps, TextFieldProps } from \\"@aws-amplify/ui-react\\";
import { StorageManagerProps } from \\"@aws-amplify/ui-react-storage\\";
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
import { Product } from \\"../models\\";
export declare type ValidationResponse = {
hasError: boolean;
errorMessage?: string;
};
export declare type ValidationFunction<T> = (value: T, validationResponse: ValidationResponse) => ValidationResponse | Promise<ValidationResponse>;
export declare type UpdateProductFormInputValues = {
name?: string;
imgKeys?: string[];
};
export declare type UpdateProductFormValidationValues = {
name?: ValidationFunction<string>;
imgKeys?: ValidationFunction<string>;
};
export declare type PrimitiveOverrideProps<T> = Partial<T> & React.DOMAttributes<HTMLDivElement>;
export declare type UpdateProductFormOverridesProps = {
UpdateProductFormGrid?: PrimitiveOverrideProps<GridProps>;
name?: PrimitiveOverrideProps<TextFieldProps>;
imgKeys?: PrimitiveOverrideProps<StorageManagerProps>;
} & EscapeHatchProps;
export declare type UpdateProductFormProps = React.PropsWithChildren<{
overrides?: UpdateProductFormOverridesProps | undefined | null;
} & {
id?: string;
product?: Product;
onSubmit?: (fields: UpdateProductFormInputValues) => UpdateProductFormInputValues;
onSuccess?: (fields: UpdateProductFormInputValues) => void;
onError?: (fields: UpdateProductFormInputValues, errorMessage: string) => void;
onChange?: (fields: UpdateProductFormInputValues) => UpdateProductFormInputValues;
onValidate?: UpdateProductFormValidationValues;
} & React.CSSProperties>;
export default function UpdateProductForm(props: UpdateProductFormProps): React.ReactElement;
"
`;

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\\";
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
import { Field, getOverrideProps } from \\"@aws-amplify/ui-react/internal\\";
import { Product } from \\"../models\\";
import { fetchByPath, processFile, validateField } from \\"./utils\\";
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
import { DataStore } from \\"aws-amplify\\";
export default function UpdateProductForm(props) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,13 @@ describe('amplify form renderer tests', () => {
});

it('should render a update form with StorageField', () => {
const { componentText } = generateWithAmplifyFormRenderer(
const { componentText, declaration } = generateWithAmplifyFormRenderer(
'forms/product-datastore-update',
'datastore/product',
undefined,
);
expect(componentText).toMatchSnapshot();
expect(declaration).toMatchSnapshot();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,13 @@ export const buildOverrideTypesBindings = (
if (field.split('.').length > 1 || !isValidVariableName(field)) {
propKey = factory.createStringLiteral(field);
}
const componentTypePropName = `${formDefinition.elements[field].componentType}Props`;
let componentTypePropName = `${formDefinition.elements[field].componentType}Props`;
if (formDefinition.elements[field].componentType === 'StorageField') {
componentTypePropName = 'StorageManagerProps';
importCollection.addImport(ImportSource.REACT_STORAGE, componentTypePropName);
} else {
importCollection.addImport(ImportSource.UI_REACT, componentTypePropName);
}
typeNodes.push(
factory.createPropertySignature(
undefined,
Expand All @@ -504,7 +510,6 @@ export const buildOverrideTypesBindings = (
]),
),
);
importCollection.addImport(ImportSource.UI_REACT, componentTypePropName);
});
});

Expand Down