Skip to content

Commit adf26f4

Browse files
JshhhhJustin Shih
andauthored
fix: fix storage field prop import to storagemanager (#1016)
Co-authored-by: Justin Shih <[email protected]>
1 parent 303e915 commit adf26f4

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24848,10 +24848,10 @@ exports[`amplify form renderer tests forms with StorageField tests should render
2484824848
"/* eslint-disable */
2484924849
import * as React from \\"react\\";
2485024850
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
24851+
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
2485124852
import { Field, getOverrideProps } from \\"@aws-amplify/ui-react/internal\\";
2485224853
import { Product } from \\"../models\\";
2485324854
import { fetchByPath, processFile, validateField } from \\"./utils\\";
24854-
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
2485524855
import { DataStore } from \\"aws-amplify\\";
2485624856
export default function CreateProductForm(props) {
2485724857
const {
@@ -25059,10 +25059,10 @@ exports[`amplify form renderer tests forms with StorageField tests should render
2505925059
"/* eslint-disable */
2506025060
import * as React from \\"react\\";
2506125061
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
25062+
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
2506225063
import { Field, getOverrideProps } from \\"@aws-amplify/ui-react/internal\\";
2506325064
import { Product } from \\"../models\\";
2506425065
import { fetchByPath, processFile, validateField } from \\"./utils\\";
25065-
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
2506625066
import { DataStore } from \\"aws-amplify\\";
2506725067
export default function UpdateProductForm(props) {
2506825068
const {
@@ -25287,14 +25287,54 @@ export default function UpdateProductForm(props) {
2528725287
"
2528825288
`;
2528925289

25290+
exports[`amplify form renderer tests forms with StorageField tests should render a update form with StorageField 2`] = `
25291+
"import * as React from \\"react\\";
25292+
import { GridProps, TextFieldProps } from \\"@aws-amplify/ui-react\\";
25293+
import { StorageManagerProps } from \\"@aws-amplify/ui-react-storage\\";
25294+
import { EscapeHatchProps } from \\"@aws-amplify/ui-react/internal\\";
25295+
import { Product } from \\"../models\\";
25296+
export declare type ValidationResponse = {
25297+
hasError: boolean;
25298+
errorMessage?: string;
25299+
};
25300+
export declare type ValidationFunction<T> = (value: T, validationResponse: ValidationResponse) => ValidationResponse | Promise<ValidationResponse>;
25301+
export declare type UpdateProductFormInputValues = {
25302+
name?: string;
25303+
imgKeys?: string[];
25304+
};
25305+
export declare type UpdateProductFormValidationValues = {
25306+
name?: ValidationFunction<string>;
25307+
imgKeys?: ValidationFunction<string>;
25308+
};
25309+
export declare type PrimitiveOverrideProps<T> = Partial<T> & React.DOMAttributes<HTMLDivElement>;
25310+
export declare type UpdateProductFormOverridesProps = {
25311+
UpdateProductFormGrid?: PrimitiveOverrideProps<GridProps>;
25312+
name?: PrimitiveOverrideProps<TextFieldProps>;
25313+
imgKeys?: PrimitiveOverrideProps<StorageManagerProps>;
25314+
} & EscapeHatchProps;
25315+
export declare type UpdateProductFormProps = React.PropsWithChildren<{
25316+
overrides?: UpdateProductFormOverridesProps | undefined | null;
25317+
} & {
25318+
id?: string;
25319+
product?: Product;
25320+
onSubmit?: (fields: UpdateProductFormInputValues) => UpdateProductFormInputValues;
25321+
onSuccess?: (fields: UpdateProductFormInputValues) => void;
25322+
onError?: (fields: UpdateProductFormInputValues, errorMessage: string) => void;
25323+
onChange?: (fields: UpdateProductFormInputValues) => UpdateProductFormInputValues;
25324+
onValidate?: UpdateProductFormValidationValues;
25325+
} & React.CSSProperties>;
25326+
export default function UpdateProductForm(props: UpdateProductFormProps): React.ReactElement;
25327+
"
25328+
`;
25329+
2529025330
exports[`amplify form renderer tests forms with StorageField tests should render a update form with StorageField on non-array field 1`] = `
2529125331
"/* eslint-disable */
2529225332
import * as React from \\"react\\";
2529325333
import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\";
25334+
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
2529425335
import { Field, getOverrideProps } from \\"@aws-amplify/ui-react/internal\\";
2529525336
import { Product } from \\"../models\\";
2529625337
import { fetchByPath, processFile, validateField } from \\"./utils\\";
25297-
import { StorageManager } from \\"@aws-amplify/ui-react-storage\\";
2529825338
import { DataStore } from \\"aws-amplify\\";
2529925339
export default function UpdateProductForm(props) {
2530025340
const {

packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,13 @@ describe('amplify form renderer tests', () => {
663663
});
664664

665665
it('should render a update form with StorageField', () => {
666-
const { componentText } = generateWithAmplifyFormRenderer(
666+
const { componentText, declaration } = generateWithAmplifyFormRenderer(
667667
'forms/product-datastore-update',
668668
'datastore/product',
669669
undefined,
670670
);
671671
expect(componentText).toMatchSnapshot();
672+
expect(declaration).toMatchSnapshot();
672673
});
673674
});
674675

packages/codegen-ui-react/lib/forms/form-renderer-helper/type-helper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,13 @@ export const buildOverrideTypesBindings = (
493493
if (field.split('.').length > 1 || !isValidVariableName(field)) {
494494
propKey = factory.createStringLiteral(field);
495495
}
496-
const componentTypePropName = `${formDefinition.elements[field].componentType}Props`;
496+
let componentTypePropName = `${formDefinition.elements[field].componentType}Props`;
497+
if (formDefinition.elements[field].componentType === 'StorageField') {
498+
componentTypePropName = 'StorageManagerProps';
499+
importCollection.addImport(ImportSource.REACT_STORAGE, componentTypePropName);
500+
} else {
501+
importCollection.addImport(ImportSource.UI_REACT, componentTypePropName);
502+
}
497503
typeNodes.push(
498504
factory.createPropertySignature(
499505
undefined,
@@ -504,7 +510,6 @@ export const buildOverrideTypesBindings = (
504510
]),
505511
),
506512
);
507-
importCollection.addImport(ImportSource.UI_REACT, componentTypePropName);
508513
});
509514
});
510515

0 commit comments

Comments
 (0)