Skip to content

Fix recomposition failing for child components #112

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

Merged
merged 2 commits into from
Aug 13, 2020
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
18 changes: 10 additions & 8 deletions src/metadata-registry/manifestGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ export class ManifestGenerator {
private createMetadataMap(components: MetadataComponent[]): Map<string, Set<string>> {
const metadataMap: Map<string, Set<string>> = new Map<string, Set<string>>();
for (const component of components) {
const metadataType = this.registryAccess.getTypeFromName(component.type.name).name;
const metadataName = component.fullName;
if (metadataMap.has(metadataType)) {
const metadataNames = metadataMap.get(metadataType);
metadataNames.add(metadataName);
metadataMap.set(metadataType, metadataNames);
const {
fullName,
type: { name: typeName },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of asking the RegistryAccess for the type, this just pulls it right off the component since we have that information already. getTypeFromName currently only supports top level metadata types. If we feel like it's necessary to strictly enforce a metadata type defined in the registry.json file to use the manifest generator, this could be done instead:

const { name: typeName } = component.parent
        ? this.registryAccess.getTypeFromName(component.parent.type.name).children.types[
            component.type.id
          ]
        : this.registryAccess.getTypeFromName(component.type.name);

Most of the time however, components are constructed from the registry code and even the type property itself is strictly typed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier fix - "," at the end

} = component;
if (metadataMap.has(typeName)) {
const metadataNames = metadataMap.get(typeName);
metadataNames.add(fullName);
metadataMap.set(typeName, metadataNames);
} else {
const metadataNames: Set<string> = new Set<string>();
metadataNames.add(metadataName);
metadataMap.set(metadataType, metadataNames);
metadataNames.add(fullName);
metadataMap.set(typeName, metadataNames);
}
}
return metadataMap;
Expand Down
25 changes: 9 additions & 16 deletions test/metadata-registry/manifestGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ import { fail } from 'assert';
describe('ManifestGenerator', () => {
let sandboxStub: SinonSandbox;
const manifestGenerator = new ManifestGenerator();

beforeEach(async () => {
sandboxStub = createSandbox();
});

afterEach(() => {
sandboxStub.restore();
});

it('should generate manifest for one type', () => {
const component = {
fullName: 'someName',
type: { id: 'apexclass', name: 'ApexClass' },
type: { id: 'foobar', name: 'FooBar' },
};
let expectedManifest = '<?xml version="1.0" encoding="UTF-8"?>\n';
expectedManifest += '<Package xmlns="http://soap.sforce.com/2006/04/metadata">\n';
expectedManifest +=
' <types>\n <members>someName</members>\n <name>ApexClass</name>\n </types>\n';
' <types>\n <members>someName</members>\n <name>FooBar</name>\n </types>\n';
expectedManifest += ' <version>48.0</version>\n</Package>';
expect(manifestGenerator.createManifest([component])).to.equal(expectedManifest);
});

it('should generate manifest for multiple types', () => {
const component1 = {
fullName: 'apexClass1',
Expand All @@ -52,6 +56,7 @@ describe('ManifestGenerator', () => {
expectedManifest += ' <version>48.0</version>\n</Package>';
expect(manifestGenerator.createManifest([component1, component2])).to.equal(expectedManifest);
});

it('should generate manifest for multiple components', () => {
const component1 = {
fullName: 'apexClass1',
Expand All @@ -76,6 +81,7 @@ describe('ManifestGenerator', () => {
expectedManifest
);
});

it('should generate manifest for multiple components passed in different order', () => {
const component1 = {
fullName: 'apexClass1',
Expand All @@ -100,6 +106,7 @@ describe('ManifestGenerator', () => {
expectedManifest
);
});

it('should generate manifest by overriding apiversion', () => {
const component = {
fullName: 'someName',
Expand All @@ -112,20 +119,6 @@ describe('ManifestGenerator', () => {
expectedManifest += ' <version>45.0</version>\n</Package>';
expect(manifestGenerator.createManifest([component], '45.0')).to.equal(expectedManifest);
});
it('should throw error for non valid type', () => {
const component = {
fullName: 'someName',
type: { id: 'someveryunknowntype', name: 'someveryunknowntype' },
};
try {
manifestGenerator.createManifest([component]);
expect.fail('should have failed');
} catch (e) {
expect(e.message).to.equal(
"Missing metadata type definition in registry for id 'someveryunknowntype'"
);
}
});

const rootPath = path.join('file', 'path');
const mdComponents = [
Expand Down