From 57d112e42b9d461063f7f27b3decd8b98d573f12 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Fri, 10 Nov 2023 01:16:58 -0800 Subject: [PATCH 1/9] Get compact layout. --- src/commands/wizard/lwcGenerationCommand.ts | 12 ++++++ src/utils/orgUtils.ts | 42 +++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/commands/wizard/lwcGenerationCommand.ts b/src/commands/wizard/lwcGenerationCommand.ts index bf8092e3..98e3257e 100644 --- a/src/commands/wizard/lwcGenerationCommand.ts +++ b/src/commands/wizard/lwcGenerationCommand.ts @@ -4,6 +4,7 @@ import { InstructionsWebviewProvider } from '../../webviews/instructions'; import { UEMParser } from '../../utils/uemParser'; import { WorkspaceUtils } from '../../utils/workspaceUtils'; import { CommonUtils } from '@salesforce/lwc-dev-mobile-core'; +import { OrgUtils } from '../../utils/orgUtils'; import * as fs from 'fs'; import * as path from 'path'; @@ -79,6 +80,17 @@ export class LwcGenerationCommand { { type: 'getQuickActionStatus', action: async (_panel, _data, callback) => { + await OrgUtils.getCompactLayoutForSObject( + 'Contact' + ); + + // TODO: Hook this up to function that parses landing_page.json. + const sobjects = [ + 'Account', + 'Contact', + 'Opportunity', + 'SomeOther' + ]; if (callback) { const quickActionStatus = await LwcGenerationCommand.checkForExistingQuickActions(); diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index 87429d20..c665b4e8 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -65,6 +65,48 @@ export class OrgUtils { } } + public static async getCompactLayoutForSObject( + sObjectName: string + ): Promise { + try { + const org = await Org.create(); + const conn = org.getConnection(); + const result = await conn.request( + `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts` + ); + const fields: string[] = []; + const resultObj = result as Object; + const compactLayouts = resultObj['compactLayouts' as keyof Object]; + if (Array.isArray(compactLayouts)) { + compactLayouts.forEach((compactLayout) => { + const fieldItems = compactLayout['fieldItems']; + fieldItems.forEach((fieldItem: { [key: string]: any }) => { + const editableForNew = fieldItem['editableForNew']; + const editableForUpdate = + fieldItem['editableForUpdate']; + if (editableForNew && editableForUpdate) { + const layoutComponents = + fieldItem['layoutComponents']; + if (Array.isArray(layoutComponents)) { + const layoutComponent = layoutComponents[0]; + const layoutComponentType = + layoutComponent['type']; + if (layoutComponentType === 'Field') { + fields.push(layoutComponent['value']); + } + } + } + }); + }); + } + + return Promise.resolve(fields); + } catch (error) { + console.log(error); + return Promise.reject(error); + } + } + public static async getDefaultUser(): Promise { const aggregator = await ConfigAggregator.create(); From 06d5f7389e662e0d1cfaea1e3f673974354ec4ec Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Fri, 10 Nov 2023 17:39:09 -0800 Subject: [PATCH 2/9] 2-pass retrieval of compact layout. --- src/commands/wizard/lwcGenerationCommand.ts | 7 +- src/utils/orgUtils.ts | 78 ++++++++++++++------- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/commands/wizard/lwcGenerationCommand.ts b/src/commands/wizard/lwcGenerationCommand.ts index 98e3257e..8b9efd5c 100644 --- a/src/commands/wizard/lwcGenerationCommand.ts +++ b/src/commands/wizard/lwcGenerationCommand.ts @@ -80,9 +80,10 @@ export class LwcGenerationCommand { { type: 'getQuickActionStatus', action: async (_panel, _data, callback) => { - await OrgUtils.getCompactLayoutForSObject( - 'Contact' - ); + const layoutFields = + await OrgUtils.getCompactLayoutFieldsForSObject( + 'Contact' + ); // TODO: Hook this up to function that parses landing_page.json. const sobjects = [ diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index c665b4e8..f1e88765 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -18,6 +18,13 @@ export interface Field { label: string; type: string; } + +export interface CompactLayoutField { + editableForNew: boolean; + editableForUpdate: boolean; + label: string; +} + export class OrgUtils { public static async getSobjects(): Promise { try { @@ -65,39 +72,58 @@ export class OrgUtils { } } - public static async getCompactLayoutForSObject( + public static async getCompactLayoutFieldsForSObject( sObjectName: string - ): Promise { + ): Promise { try { const org = await Org.create(); const conn = org.getConnection(); - const result = await conn.request( + + // Get the compact layout info for a sObject first + let result = await conn.request( `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts` ); - const fields: string[] = []; - const resultObj = result as Object; - const compactLayouts = resultObj['compactLayouts' as keyof Object]; - if (Array.isArray(compactLayouts)) { - compactLayouts.forEach((compactLayout) => { - const fieldItems = compactLayout['fieldItems']; - fieldItems.forEach((fieldItem: { [key: string]: any }) => { - const editableForNew = fieldItem['editableForNew']; - const editableForUpdate = - fieldItem['editableForUpdate']; - if (editableForNew && editableForUpdate) { - const layoutComponents = - fieldItem['layoutComponents']; - if (Array.isArray(layoutComponents)) { - const layoutComponent = layoutComponents[0]; - const layoutComponentType = - layoutComponent['type']; - if (layoutComponentType === 'Field') { - fields.push(layoutComponent['value']); - } - } - } - }); + + const fields: CompactLayoutField[] = []; + + if (result) { + const resultObj = result as Object; + + // sObject can have multiple compact layouts associated with it. Get the default. + const defaultCompactLayoutId = + resultObj['defaultCompactLayoutId' as keyof Object]; + const recordTypeCompactLayoutMappings = + resultObj[ + 'recordTypeCompactLayoutMappings' as keyof Object + ]; + + // ID of compact layout need to be normalized + const recordTypeCompactLayoutMapping = ( + recordTypeCompactLayoutMappings as unknown as Array + ).find((element) => { + return ( + element['compactLayoutId' as keyof Object] === + defaultCompactLayoutId + ); }); + + if (recordTypeCompactLayoutMapping) { + const recordTypeId = + recordTypeCompactLayoutMapping[ + 'recordTypeId' as keyof Object + ]; + + // With the compact layout ID mapped back to recordType ID make another network request to get the + // exact compact layout info. + result = await conn.request( + `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts/${recordTypeId}` + ); + if (result) { + return result[ + 'fieldItems' as keyof Object + ] as unknown as CompactLayoutField[]; + } + } } return Promise.resolve(fields); From e4f73bfc4b3158aeea22ffea6ad6b0a1f546c296 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Sun, 12 Nov 2023 20:40:52 -0800 Subject: [PATCH 3/9] Refinement. --- src/utils/orgUtils.ts | 65 +++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index f1e88765..1c3c74a6 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -72,17 +72,39 @@ export class OrgUtils { } } + private static async getAllCompactLayoutsForSObject( + sObjectName: string + ): Promise { + const org = await Org.create(); + const conn = org.getConnection(); + + const result = await conn.request( + `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts` + ); + + return Promise.resolve(result); + } + + private static async getCompactLayoutForSObject( + sObjectName: string, + recordTypeId: string + ): Promise { + const org = await Org.create(); + const conn = org.getConnection(); + + const result = await conn.request( + `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts/${recordTypeId}` + ); + + return Promise.resolve(result); + } + public static async getCompactLayoutFieldsForSObject( sObjectName: string ): Promise { try { - const org = await Org.create(); - const conn = org.getConnection(); - - // Get the compact layout info for a sObject first - let result = await conn.request( - `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts` - ); + // Get all the compact layouts associated to this sObject first + let result = await this.getAllCompactLayoutsForSObject(sObjectName); const fields: CompactLayoutField[] = []; @@ -92,6 +114,8 @@ export class OrgUtils { // sObject can have multiple compact layouts associated with it. Get the default. const defaultCompactLayoutId = resultObj['defaultCompactLayoutId' as keyof Object]; + + // Mapping tab const recordTypeCompactLayoutMappings = resultObj[ 'recordTypeCompactLayoutMappings' as keyof Object @@ -101,10 +125,20 @@ export class OrgUtils { const recordTypeCompactLayoutMapping = ( recordTypeCompactLayoutMappings as unknown as Array ).find((element) => { - return ( - element['compactLayoutId' as keyof Object] === - defaultCompactLayoutId - ); + if (defaultCompactLayoutId) { + return ( + element['compactLayoutId' as keyof Object] === + defaultCompactLayoutId + ); + } else { + // defaultCompactLayoutId can be null when a compact layout is not assigned. + // In that case sObject will always have one default layout called SYSTEM. + // So use that instead. + const compactLayoutName = element[ + 'compactLayoutName' as keyof Object + ] as unknown as string; + return compactLayoutName === 'SYSTEM'; + } }); if (recordTypeCompactLayoutMapping) { @@ -113,11 +147,13 @@ export class OrgUtils { 'recordTypeId' as keyof Object ]; - // With the compact layout ID mapped back to recordType ID make another network request to get the + // With the compact layout ID mapped back to the recordType ID, make another network request to get the // exact compact layout info. - result = await conn.request( - `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts/${recordTypeId}` + result = await this.getCompactLayoutForSObject( + sObjectName, + recordTypeId as unknown as string ); + if (result) { return result[ 'fieldItems' as keyof Object @@ -128,7 +164,6 @@ export class OrgUtils { return Promise.resolve(fields); } catch (error) { - console.log(error); return Promise.reject(error); } } From 248df0b6318bc50ac4bd00cf7edd34992de0c030 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Sun, 12 Nov 2023 21:19:52 -0800 Subject: [PATCH 4/9] Unit tests. --- src/test/suite/utils/orgUtils.test.ts | 126 ++++++++++++++++++++++++++ src/utils/orgUtils.ts | 9 +- 2 files changed, 131 insertions(+), 4 deletions(-) diff --git a/src/test/suite/utils/orgUtils.test.ts b/src/test/suite/utils/orgUtils.test.ts index 1ba29689..f91aeb9d 100644 --- a/src/test/suite/utils/orgUtils.test.ts +++ b/src/test/suite/utils/orgUtils.test.ts @@ -140,6 +140,132 @@ suite('Org Utils Test Suite', () => { assert.equal(sobject.labelPlural, 'Labels'); }); + test('Returns SYSTEM compact layout', async () => { + // Simplified all compact layout data structure + const allCompactLayouts = { + defaultCompactLayoutId: null, + recordTypeCompactLayoutMappings: [ + { + available: true, + compactLayoutId: null, + compactLayoutName: 'SYSTEM', + recordTypeId: '012000000000000AAA', + recordTypeName: 'Master', + urls: { + compactLayout: + '/services/data/v59.0/sobjects/Contact/describe/compactLayouts/012000000000000AAA' + } + } + ] + }; + + // Simplified compact layout data structure + const compactLayout = { + fieldItems: [ + { + editableForNew: true, + editableForUpdate: true, + label: 'Name' + }, + { + editableForNew: true, + editableForUpdate: true, + label: 'Title' + }, + { + editableForNew: false, + editableForUpdate: false, + label: 'Contact Owner' + } + ], + id: null, + label: 'System Default', + name: 'SYSTEM', + objectType: 'Contact' + }; + + sinon + .stub(OrgUtils, 'getAllCompactLayoutsForSObject') + .returns(Promise.resolve(allCompactLayouts)); + sinon + .stub(OrgUtils, 'getCompactLayoutForSObject') + .returns(Promise.resolve(compactLayout)); + + const result = + await OrgUtils.getCompactLayoutFieldsForSObject('Contact'); + + assert.equal(result, compactLayout.fieldItems); + }); + + test('Returns Contact compact layout', async () => { + // Simplified all compact layout data structure + const allCompactLayouts = { + defaultCompactLayoutId: '123456789', + recordTypeCompactLayoutMappings: [ + { + available: true, + compactLayoutId: null, + compactLayoutName: 'SYSTEM', + recordTypeId: '012000000000000AAA', + recordTypeName: 'Master', + urls: { + compactLayout: + '/services/data/v59.0/sobjects/Contact/describe/compactLayouts/012000000000000AAA' + } + }, + { + available: true, + compactLayoutId: '123456789', + compactLayoutName: 'Mobile layout', + recordTypeId: '012000000000000BBB', + recordTypeName: 'Contact', + urls: { + compactLayout: + '/services/data/v59.0/sobjects/Contact/describe/compactLayouts/012000000000000BBB' + } + } + ] + }; + + // Simplified compact layout data structure + const compactLayout = { + fieldItems: [ + { + editableForNew: true, + editableForUpdate: true, + label: 'Name' + }, + { + editableForNew: true, + editableForUpdate: true, + label: 'Title' + }, + { + editableForNew: false, + editableForUpdate: false, + label: 'Contact Owner' + } + ], + id: null, + label: 'Mobile layout', + name: 'Mobile layout', + objectType: 'Contact' + }; + + sinon + .stub(OrgUtils, 'getAllCompactLayoutsForSObject') + .returns(Promise.resolve(allCompactLayouts)); + sinon + .stub(OrgUtils, 'getCompactLayoutForSObject') + .withArgs('Contact', '012000000000000BBB') + .returns(Promise.resolve(compactLayout)); + + const result = + await OrgUtils.getCompactLayoutFieldsForSObject('Contact'); + + assert.equal(result, compactLayout.fieldItems); + }); + test('Returns list of fields for given sObject', async () => { const sobjectFields: FieldType[] = [ buildField('City', 'string', 'Label'), diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index 1c3c74a6..3baf09e2 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -72,7 +72,7 @@ export class OrgUtils { } } - private static async getAllCompactLayoutsForSObject( + public static async getAllCompactLayoutsForSObject( sObjectName: string ): Promise { const org = await Org.create(); @@ -85,7 +85,7 @@ export class OrgUtils { return Promise.resolve(result); } - private static async getCompactLayoutForSObject( + public static async getCompactLayoutForSObject( sObjectName: string, recordTypeId: string ): Promise { @@ -103,11 +103,11 @@ export class OrgUtils { sObjectName: string ): Promise { try { + const fields: CompactLayoutField[] = []; + // Get all the compact layouts associated to this sObject first let result = await this.getAllCompactLayoutsForSObject(sObjectName); - const fields: CompactLayoutField[] = []; - if (result) { const resultObj = result as Object; @@ -116,6 +116,7 @@ export class OrgUtils { resultObj['defaultCompactLayoutId' as keyof Object]; // Mapping tab + console.error(resultObj); const recordTypeCompactLayoutMappings = resultObj[ 'recordTypeCompactLayoutMappings' as keyof Object From a7ee4730341c3ae324ff6f3598acad217ceef284 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Mon, 13 Nov 2023 12:31:13 -0800 Subject: [PATCH 5/9] Update after review. --- src/test/suite/utils/orgUtils.test.ts | 4 ++-- src/utils/orgUtils.ts | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/test/suite/utils/orgUtils.test.ts b/src/test/suite/utils/orgUtils.test.ts index f91aeb9d..b7df59e0 100644 --- a/src/test/suite/utils/orgUtils.test.ts +++ b/src/test/suite/utils/orgUtils.test.ts @@ -185,7 +185,7 @@ suite('Org Utils Test Suite', () => { }; sinon - .stub(OrgUtils, 'getAllCompactLayoutsForSObject') + .stub(OrgUtils, 'getCompactLayoutsForSObject') .returns(Promise.resolve(allCompactLayouts)); sinon .stub(OrgUtils, 'getCompactLayoutForSObject') @@ -253,7 +253,7 @@ suite('Org Utils Test Suite', () => { }; sinon - .stub(OrgUtils, 'getAllCompactLayoutsForSObject') + .stub(OrgUtils, 'getCompactLayoutsForSObject') .returns(Promise.resolve(allCompactLayouts)); sinon .stub(OrgUtils, 'getCompactLayoutForSObject') diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index 3baf09e2..47d064e4 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -72,13 +72,13 @@ export class OrgUtils { } } - public static async getAllCompactLayoutsForSObject( + public static async getCompactLayoutsForSObject( sObjectName: string - ): Promise { + ): Promise { const org = await Org.create(); const conn = org.getConnection(); - const result = await conn.request( + const result = await conn.request( `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts` ); @@ -88,11 +88,11 @@ export class OrgUtils { public static async getCompactLayoutForSObject( sObjectName: string, recordTypeId: string - ): Promise { + ): Promise { const org = await Org.create(); const conn = org.getConnection(); - const result = await conn.request( + const result = await conn.request( `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts/${recordTypeId}` ); @@ -106,21 +106,16 @@ export class OrgUtils { const fields: CompactLayoutField[] = []; // Get all the compact layouts associated to this sObject first - let result = await this.getAllCompactLayoutsForSObject(sObjectName); + let result = await this.getCompactLayoutsForSObject(sObjectName); if (result) { - const resultObj = result as Object; - // sObject can have multiple compact layouts associated with it. Get the default. const defaultCompactLayoutId = - resultObj['defaultCompactLayoutId' as keyof Object]; + result['defaultCompactLayoutId' as keyof Object]; // Mapping tab - console.error(resultObj); const recordTypeCompactLayoutMappings = - resultObj[ - 'recordTypeCompactLayoutMappings' as keyof Object - ]; + result['recordTypeCompactLayoutMappings' as keyof Object]; // ID of compact layout need to be normalized const recordTypeCompactLayoutMapping = ( From 2d62ccfc43542ec0aef29cb8945b9d18cd55bf95 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Mon, 13 Nov 2023 15:07:21 -0800 Subject: [PATCH 6/9] Strong typing. --- src/utils/orgUtils.ts | 62 +++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index 47d064e4..7239eb72 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -25,6 +25,17 @@ export interface CompactLayoutField { label: string; } +export type SObjectCompactLayoutMapping = { + compactLayoutId: string | null; + compactLayoutName: string; + recordTypeId: string; +}; + +export type SObjectCompactLayouts = { + defaultCompactLayoutId: string | null; + recordTypeCompactLayoutMappings: SObjectCompactLayoutMapping[]; +}; + export class OrgUtils { public static async getSobjects(): Promise { try { @@ -74,11 +85,11 @@ export class OrgUtils { public static async getCompactLayoutsForSObject( sObjectName: string - ): Promise { + ): Promise { const org = await Org.create(); const conn = org.getConnection(); - const result = await conn.request( + const result = await conn.request( `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts` ); @@ -110,32 +121,31 @@ export class OrgUtils { if (result) { // sObject can have multiple compact layouts associated with it. Get the default. - const defaultCompactLayoutId = - result['defaultCompactLayoutId' as keyof Object]; + const defaultCompactLayoutId = result.defaultCompactLayoutId; + result['defaultCompactLayoutId']; // Mapping tab const recordTypeCompactLayoutMappings = - result['recordTypeCompactLayoutMappings' as keyof Object]; + result.recordTypeCompactLayoutMappings; // ID of compact layout need to be normalized - const recordTypeCompactLayoutMapping = ( - recordTypeCompactLayoutMappings as unknown as Array - ).find((element) => { - if (defaultCompactLayoutId) { - return ( - element['compactLayoutId' as keyof Object] === - defaultCompactLayoutId - ); - } else { - // defaultCompactLayoutId can be null when a compact layout is not assigned. - // In that case sObject will always have one default layout called SYSTEM. - // So use that instead. - const compactLayoutName = element[ - 'compactLayoutName' as keyof Object - ] as unknown as string; - return compactLayoutName === 'SYSTEM'; - } - }); + const recordTypeCompactLayoutMapping = + recordTypeCompactLayoutMappings.find((element) => { + if (defaultCompactLayoutId) { + return ( + element.compactLayoutId === + defaultCompactLayoutId + ); + } else { + // defaultCompactLayoutId can be null when a compact layout is not assigned. + // In that case sObject will always have one default layout called SYSTEM. + // So use that instead. + const compactLayoutName = element[ + 'compactLayoutName' as keyof Object + ] as unknown as string; + return compactLayoutName === 'SYSTEM'; + } + }); if (recordTypeCompactLayoutMapping) { const recordTypeId = @@ -145,13 +155,13 @@ export class OrgUtils { // With the compact layout ID mapped back to the recordType ID, make another network request to get the // exact compact layout info. - result = await this.getCompactLayoutForSObject( + const compactLayout = await this.getCompactLayoutForSObject( sObjectName, recordTypeId as unknown as string ); - if (result) { - return result[ + if (compactLayout) { + return compactLayout[ 'fieldItems' as keyof Object ] as unknown as CompactLayoutField[]; } From 7c8d457f74d101f28849663c001ed17f175d2048 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Tue, 14 Nov 2023 11:22:38 -0800 Subject: [PATCH 7/9] More trimming. --- src/utils/orgUtils.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index 7239eb72..aee39bd9 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -36,6 +36,10 @@ export type SObjectCompactLayouts = { recordTypeCompactLayoutMappings: SObjectCompactLayoutMapping[]; }; +export type SObjectCompactLayout = { + fieldItems: CompactLayoutField[]; +}; + export class OrgUtils { public static async getSobjects(): Promise { try { @@ -99,11 +103,11 @@ export class OrgUtils { public static async getCompactLayoutForSObject( sObjectName: string, recordTypeId: string - ): Promise { + ): Promise { const org = await Org.create(); const conn = org.getConnection(); - const result = await conn.request( + const result = await conn.request( `/services/data/v59.0/sobjects/${sObjectName}/describe/compactLayouts/${recordTypeId}` ); @@ -124,9 +128,8 @@ export class OrgUtils { const defaultCompactLayoutId = result.defaultCompactLayoutId; result['defaultCompactLayoutId']; - // Mapping tab - const recordTypeCompactLayoutMappings = - result.recordTypeCompactLayoutMappings; + // Mapping table + const recordTypeCompactLayoutMappings = result.recordTypeCompactLayoutMappings; // ID of compact layout need to be normalized const recordTypeCompactLayoutMapping = @@ -140,30 +143,20 @@ export class OrgUtils { // defaultCompactLayoutId can be null when a compact layout is not assigned. // In that case sObject will always have one default layout called SYSTEM. // So use that instead. - const compactLayoutName = element[ - 'compactLayoutName' as keyof Object - ] as unknown as string; - return compactLayoutName === 'SYSTEM'; + return element.compactLayoutName === 'SYSTEM'; } }); if (recordTypeCompactLayoutMapping) { - const recordTypeId = - recordTypeCompactLayoutMapping[ - 'recordTypeId' as keyof Object - ]; - // With the compact layout ID mapped back to the recordType ID, make another network request to get the // exact compact layout info. const compactLayout = await this.getCompactLayoutForSObject( sObjectName, - recordTypeId as unknown as string + recordTypeCompactLayoutMapping.recordTypeId ); if (compactLayout) { - return compactLayout[ - 'fieldItems' as keyof Object - ] as unknown as CompactLayoutField[]; + return compactLayout.fieldItems; } } } From 0684db5c9769785d060f00a6a420d44067d28830 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Tue, 14 Nov 2023 11:24:07 -0800 Subject: [PATCH 8/9] Prettier. --- src/utils/orgUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index aee39bd9..e123e007 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -129,7 +129,8 @@ export class OrgUtils { result['defaultCompactLayoutId']; // Mapping table - const recordTypeCompactLayoutMappings = result.recordTypeCompactLayoutMappings; + const recordTypeCompactLayoutMappings = + result.recordTypeCompactLayoutMappings; // ID of compact layout need to be normalized const recordTypeCompactLayoutMapping = From d62c5870ee32034d19f6dbf833d4fcc79b7dfdf0 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Tue, 14 Nov 2023 15:52:34 -0800 Subject: [PATCH 9/9] Merge conflict. Simple integration. --- src/commands/wizard/lwcGenerationCommand.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/commands/wizard/lwcGenerationCommand.ts b/src/commands/wizard/lwcGenerationCommand.ts index 8b9efd5c..2591aada 100644 --- a/src/commands/wizard/lwcGenerationCommand.ts +++ b/src/commands/wizard/lwcGenerationCommand.ts @@ -80,21 +80,17 @@ export class LwcGenerationCommand { { type: 'getQuickActionStatus', action: async (_panel, _data, callback) => { - const layoutFields = - await OrgUtils.getCompactLayoutFieldsForSObject( - 'Contact' - ); - - // TODO: Hook this up to function that parses landing_page.json. - const sobjects = [ - 'Account', - 'Contact', - 'Opportunity', - 'SomeOther' - ]; if (callback) { const quickActionStatus = await LwcGenerationCommand.checkForExistingQuickActions(); + + for (const key in quickActionStatus.sobjects) { + const layoutFields = + await OrgUtils.getCompactLayoutFieldsForSObject( + key + ); + } + callback(quickActionStatus); } }