Skip to content
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

Deploy: Correct fullName for layouts #642

Merged
merged 1 commit into from
Nov 29, 2023
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
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;
}