Skip to content

Commit

Permalink
Merge pull request #642 from jetstreamapp/bug/639
Browse files Browse the repository at this point in the history
Deploy: Correct fullName for layouts
  • Loading branch information
paustint authored Nov 29, 2023
2 parents 1dec86f + 7373a07 commit e09f6ef
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
22 changes: 17 additions & 5 deletions apps/api/src/app/services/sf-misc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ensureArray, orderObjectsBy } from '@jetstream/shared/utils';
import { ensureArray, getFullNameFromListMetadata, orderObjectsBy } from '@jetstream/shared/utils';
import { ListMetadataResult, MapOf } from '@jetstream/types';
import type { PackageTypeMembers, RetrieveRequest } from 'jsforce';
import { get as lodashGet, isObjectLike, isString } from 'lodash';
import { isObjectLike, isString, get as lodashGet } from 'lodash';
import { create as xmlBuilder } from 'xmlbuilder2';
import { UserFacingError } from '../utils/error-handler';

Expand All @@ -15,8 +15,14 @@ export function buildPackageXml(types: MapOf<ListMetadataResult[]>, version: str
Object.keys(types).forEach((metadataType) => {
const typesNode = packageNode.ele('types');
if (types[metadataType].length) {
orderObjectsBy(types[metadataType], 'fullName').forEach(({ fullName }) => {
typesNode.ele('members').txt(fullName);
orderObjectsBy(types[metadataType], 'fullName').forEach(({ fullName, namespacePrefix }) => {
typesNode.ele('members').txt(
getFullNameFromListMetadata({
fullName,
metadataType,
namespace: namespacePrefix,
})
);
});
typesNode.ele('name').txt(metadataType);
}
Expand All @@ -42,7 +48,13 @@ export function getRetrieveRequestFromListMetadata(types: MapOf<ListMetadataResu
types: Object.keys(types).map((metadataName) => {
const members = types[metadataName];
return {
members: members.map(({ fullName }) => fullName),
members: members.map(({ fullName, namespacePrefix }) => {
return getFullNameFromListMetadata({
fullName,
metadataType: metadataName,
namespace: namespacePrefix,
});
}),
name: metadataName,
};
}),
Expand Down
41 changes: 40 additions & 1 deletion libs/shared/utils/src/lib/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getExcelSafeSheetName } from '../utils';
import { getExcelSafeSheetName, getFullNameFromListMetadata } from '../utils';

describe('utils.getExcelSafeSheetName', () => {
it('should handle simple cases', () => {
Expand Down Expand Up @@ -37,3 +37,42 @@ describe('utils.getExcelSafeSheetName', () => {
).toEqual('recordsrecordsrecordsrecordsr13');
});
});

describe('utils.getFullNameFromListMetadata', () => {
it('Should convert layout name', () => {
expect(
getFullNameFromListMetadata({
fullName: 'SBQQ__AttributeSet__c-Attribute Set Layout',
metadataType: 'Layout',
namespace: 'SBQQ',
})
).toEqual('SBQQ__AttributeSet__c-SBQQ__Attribute Set Layout');
});
it('Should not double add namespace if already correct', () => {
expect(
getFullNameFromListMetadata({
fullName: 'SBQQ__AttributeSet__c-SBQQ__Attribute Set Layout',
metadataType: 'Layout',
namespace: 'SBQQ',
})
).toEqual('SBQQ__AttributeSet__c-SBQQ__Attribute Set Layout');
});
it('Should not add namespace if non-managed', () => {
expect(
getFullNameFromListMetadata({
fullName: 'AttributeSet__c-Attribute Set Layout',
metadataType: 'Layout',
namespace: null,
})
).toEqual('AttributeSet__c-Attribute Set Layout');
});
it('Should not apply to other managed package types', () => {
expect(
getFullNameFromListMetadata({
fullName: 'AttributeSet__c-Attribute Set Layout',
metadataType: 'ApexClass',
namespace: 'TEST',
})
).toEqual('AttributeSet__c-Attribute Set Layout');
});
});
21 changes: 21 additions & 0 deletions libs/shared/utils/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,24 @@ export function decodeHtmlEntity(value: Maybe<string>) {
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>');
}

/**
* Some fullNames from listMetadata need to be modified
*/
export function getFullNameFromListMetadata({
metadataType,
namespace,
fullName,
}: {
metadataType: string;
fullName: string;
namespace: Maybe<string>;
}) {
// Fix fullName for managed package layouts
if (namespace && metadataType === 'Layout' && !fullName.slice(fullName.indexOf('-') + 1).startsWith(`${namespace}__`)) {
const objectName = fullName.slice(0, fullName.indexOf('-') + 1);
const layoutName = fullName.slice(fullName.indexOf('-') + 1);
return `${objectName}${namespace}__${layoutName}`;
}
return fullName;
}

0 comments on commit e09f6ef

Please sign in to comment.