From cf764bb9ce02844553e6374efa1d538e414ab697 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Thu, 30 Sep 2021 11:35:13 -0600 Subject: [PATCH] fix: resolve CustomFieldTranslations properly (#461) Co-authored-by: Willie Ruemmele --- .../adapters/decomposedSourceAdapter.ts | 5 +++- .../adapters/decomposedSourceAdapter.ts | 28 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/resolve/adapters/decomposedSourceAdapter.ts b/src/resolve/adapters/decomposedSourceAdapter.ts index e724a80283..8f21365138 100644 --- a/src/resolve/adapters/decomposedSourceAdapter.ts +++ b/src/resolve/adapters/decomposedSourceAdapter.ts @@ -85,7 +85,10 @@ export class DecomposedSourceAdapter extends MixedContentSourceAdapter { if (metaXml) { const pathToContent = this.trimPathToContent(trigger); const childTypeId = this.type.children.suffixes[metaXml.suffix]; - const triggerIsAChild = !!childTypeId; + + // If the child is explicitly not addressable, return the parent SourceComponent. + const triggerIsAChild = + !!childTypeId && this.type.children.types[childTypeId].isAddressable !== false; const strategy = this.type.strategies.decomposition; if ( triggerIsAChild && diff --git a/test/resolve/adapters/decomposedSourceAdapter.ts b/test/resolve/adapters/decomposedSourceAdapter.ts index 20128f3343..a25b3c8b0d 100644 --- a/test/resolve/adapters/decomposedSourceAdapter.ts +++ b/test/resolve/adapters/decomposedSourceAdapter.ts @@ -11,15 +11,12 @@ import { decomposedtoplevel, mockRegistryData, xmlInFolder, - matchingContentFile, } from '../../mock/registry'; -import { assert, expect } from 'chai'; -import { VirtualTreeContainer, SourceComponent } from '../../../src'; +import { expect } from 'chai'; +import { VirtualTreeContainer, SourceComponent, MetadataType } from '../../../src'; import { RegistryTestUtil } from '../registryTestUtil'; import { join } from 'path'; import { META_XML_SUFFIX } from '../../../src/common'; -import { TypeInferenceError } from '../../../src/errors'; -import { nls } from '../../../src/i18n'; describe('DecomposedSourceAdapter', () => { const type = mockRegistryData.types.decomposed; @@ -39,6 +36,27 @@ describe('DecomposedSourceAdapter', () => { ); }); + it('should return parent SourceComponent when given a child xml of non-addressable type', () => { + const nonAddressableType = JSON.parse( + JSON.stringify(mockRegistryData.types.decomposedtoplevel) + ) as MetadataType; + nonAddressableType.children.types.g.isAddressable = false; + const decompTree = new VirtualTreeContainer(decomposedtoplevel.DECOMPOSED_VIRTUAL_FS); + const decompAdapter = new DecomposedSourceAdapter( + nonAddressableType, + mockRegistry, + undefined, + decompTree + ); + const expectedComp = new SourceComponent( + decomposedtoplevel.DECOMPOSED_TOP_LEVEL_COMPONENT, + decompTree + ); + expectedComp.type.children.types.g.isAddressable = false; + const childComp = decomposedtoplevel.DECOMPOSED_TOP_LEVEL_CHILD_XML_PATHS[0]; + expect(decompAdapter.getComponent(childComp)).to.deep.equal(expectedComp); + }); + it('should return expected SourceComponent when given a child xml in its decomposed folder', () => { const expectedChild = children.find((c) => c.xml === decomposed.DECOMPOSED_CHILD_XML_PATH_2); expect(adapter.getComponent(decomposed.DECOMPOSED_CHILD_XML_PATH_2)).to.deep.equal(