Skip to content

Commit

Permalink
feat: add getAliasMap method to importCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Hein Jeong authored and hein-j committed Dec 14, 2022
1 parent bd65d82 commit cb49a06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 13 additions & 0 deletions packages/codegen-ui-react/lib/imports/import-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cb49a06

Please sign in to comment.