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 f0d9130a5..425a9f0b3 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,6 +292,10 @@ describe('amplify form renderer tests', () => { 'datastore/project-team-model', ); + const aliasMap = importCollection.getAliasMap(); + expect(aliasMap.model.Team).toBe('Team0'); + expect(aliasMap.model.Member).toBe('Member'); + const teamAlias = importCollection.getMappedAlias(ImportSource.LOCAL_MODELS, 'Team'); const includesTeam = requiredDataModels.includes('Team'); diff --git a/packages/codegen-ui-react/lib/imports/import-collection.ts b/packages/codegen-ui-react/lib/imports/import-collection.ts index 803f2e6d1..87bca3a22 100644 --- a/packages/codegen-ui-react/lib/imports/import-collection.ts +++ b/packages/codegen-ui-react/lib/imports/import-collection.ts @@ -109,6 +109,19 @@ export class ImportCollection { ]; } + getAliasMap(): { model: { [modelName: string]: string } } { + const modelMap: { [modelName: string]: string } = {}; + const modelSet = this.#collection.get(ImportSource.LOCAL_MODELS); + const modelAliases = this.importAlias.get(ImportSource.LOCAL_MODELS); + if (modelSet) { + [...modelSet].forEach((item) => { + const alias = modelAliases?.get(item); + if (alias) modelMap[item] = alias; + }); + } + return { model: modelMap }; + } + buildImportStatements(skipReactImport?: boolean): ImportDeclaration[] { const importDeclarations = ([] as ImportDeclaration[]) .concat(