From f0d74e56da761e6c2959f3b44bf78a69b333e46d Mon Sep 17 00:00:00 2001 From: Justin Shih <36183898+Jshhhh@users.noreply.github.com> Date: Fri, 2 Dec 2022 12:04:26 -0800 Subject: [PATCH] fix: add form datamodel to requiredDataModels for renderComponentOnly (#815) Co-authored-by: Justin Shih --- .../lib/__tests__/studio-ui-codegen-react-forms.test.ts | 4 +++- packages/codegen-ui-react/lib/forms/react-form-renderer.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts b/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts index dc4f6bb68..998de0329 100644 --- a/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts +++ b/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts @@ -292,11 +292,13 @@ describe('amplify form renderer tests', () => { 'datastore/project-team-model', ); - const teamAlias = importCollection.importAlias.get(ImportSource.LOCAL_MODELS)?.get('Team'); + const teamAlias = importCollection.getMappedAlias(ImportSource.LOCAL_MODELS, 'Team'); const includesTeam = requiredDataModels.includes('Team'); + const includesMember = requiredDataModels.includes('Member'); expect(teamAlias).toBe('Team0'); expect(includesTeam).toBe(true); + expect(includesMember).toBe(true); expect(importCollection).toBeDefined(); }); diff --git a/packages/codegen-ui-react/lib/forms/react-form-renderer.ts b/packages/codegen-ui-react/lib/forms/react-form-renderer.ts index 19653ddd9..10461f408 100644 --- a/packages/codegen-ui-react/lib/forms/react-form-renderer.ts +++ b/packages/codegen-ui-react/lib/forms/react-form-renderer.ts @@ -386,6 +386,7 @@ export abstract class ReactFormTemplateRenderer extends StudioTemplateRenderer< // add model import for datastore type if (dataSourceType === 'DataStore') { + this.requiredDataModels.push(dataTypeName); modelName = this.importCollection.addImport(ImportSource.LOCAL_MODELS, dataTypeName); }