Skip to content

Commit

Permalink
fix: selectively write the parent
Browse files Browse the repository at this point in the history
* test: add UT to verify behavior - TDD

* test: update UT - not passing

* fix: selectively write the parent

* chore: cleanup snapshots
  • Loading branch information
WillieRuemmele authored Jun 11, 2024
1 parent 61f4cf7 commit f3cf83a
Show file tree
Hide file tree
Showing 14 changed files with 707 additions and 4 deletions.
26 changes: 23 additions & 3 deletions src/convert/transformers/decomposedMetadataTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { dirname, join } from 'node:path';
import fs from 'node:fs';
import { AnyJson, JsonMap, ensureString, isJsonMap } from '@salesforce/ts-types';
import { ensureArray } from '@salesforce/kit';
import { Messages } from '@salesforce/core';
Expand Down Expand Up @@ -84,7 +85,7 @@ export class DecomposedMetadataTransformer extends BaseMetadataTransformer {

const writeInfoForParent = mergeWith
? getWriteInfosFromMerge(mergeWith)(stateSetter)(parentXmlObject)(component)
: [{ source: new JsToXml(parentXmlObject), output: getOutputFile(component) }];
: getWriteInfosWithoutMerge(this.defaultDirectory)(parentXmlObject)(component);

const childDestinations = new Set(writeInfosForChildren.map((w) => w.output));

Expand Down Expand Up @@ -200,11 +201,30 @@ const getWriteInfosFromMerge =
return [];
};

const getWriteInfosWithoutMerge =
(defaultDirectory: string | undefined) =>
(parentXmlObject: XmlObj) =>
(component: SourceComponent): WriteInfo[] => {
const output = join(defaultDirectory ?? '', getOutputFile(component));
// if the parent would be empty
// and it exists
// and every child is addressable
// don't overwrite the existing parent
if (
!objectHasSomeRealValues(component.type)(parentXmlObject) &&
fs.existsSync(output) &&
Object.values(component.type.children ?? {}).every((child) => !child.isAddressable)
) {
return [];
} else {
return [{ source: new JsToXml(parentXmlObject), output }];
}
};

/**
* Helper for setting the decomposed transaction state
*
* @param forComponent
* @param props
* @param state
*/
const setDecomposedState =
(state: DecompositionState) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="http://soap.sforce.com/2006/04/metadata">
<excludeButtons>Submit</excludeButtons>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>true</detailHeading>
<editHeading>true</editHeading>
<label>Picture</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>Picture_IMG__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Picture__c</field>
</layoutItems>
</layoutColumns>
<style>OneColumn</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Information</label>
<layoutColumns>
<layoutItems>
<behavior>Required</behavior>
<field>Name</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Title__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Email__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>test__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>aab__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>a__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>b__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>tester__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>d__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>testing__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Mobile_Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>OwnerId</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>System Information</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>CreatedById</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>LastModifiedById</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Custom Links</label>
<layoutColumns/>
<layoutColumns/>
<layoutColumns/>
<style>CustomLinks</style>
</layoutSections>
<relatedLists>
<fields>NAME</fields>
<fields>Address__c</fields>
<fields>Price__c</fields>
<fields>Beds__c</fields>
<fields>Baths__c</fields>
<relatedList>Property__c.Broker__c</relatedList>
</relatedLists>
<showEmailCheckbox>false</showEmailCheckbox>
<showHighlightsPanel>false</showHighlightsPanel>
<showInteractionLogPanel>false</showInteractionLogPanel>
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox>
<showSubmitAndAttachButton>false</showSubmitAndAttachButton>
<summaryLayout>
<masterLabel>00hR0000001UMHM</masterLabel>
<sizeX>4</sizeX>
<sizeY>0</sizeY>
<summaryLayoutStyle>Default</summaryLayoutStyle>
</summaryLayout>
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>testing__c</fullName>
<externalId>false</externalId>
<label>testing</label>
<trackTrending>false</trackTrending>
<type>AutoNumber</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="http://soap.sforce.com/2006/04/metadata">
<excludeButtons>Submit</excludeButtons>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>true</detailHeading>
<editHeading>true</editHeading>
<label>Picture</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>Picture_IMG__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Picture__c</field>
</layoutItems>
</layoutColumns>
<style>OneColumn</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Information</label>
<layoutColumns>
<layoutItems>
<behavior>Required</behavior>
<field>Name</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Title__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Email__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>test__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>aab__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>a__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>b__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>tester__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>d__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>testing__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Mobile_Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>OwnerId</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>System Information</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>CreatedById</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>LastModifiedById</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Custom Links</label>
<layoutColumns/>
<layoutColumns/>
<layoutColumns/>
<style>CustomLinks</style>
</layoutSections>
<relatedLists>
<fields>NAME</fields>
<fields>Address__c</fields>
<fields>Price__c</fields>
<fields>Beds__c</fields>
<fields>Baths__c</fields>
<relatedList>Property__c.Broker__c</relatedList>
</relatedLists>
<showEmailCheckbox>false</showEmailCheckbox>
<showHighlightsPanel>false</showHighlightsPanel>
<showInteractionLogPanel>false</showInteractionLogPanel>
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox>
<showSubmitAndAttachButton>false</showSubmitAndAttachButton>
<summaryLayout>
<masterLabel>00hR0000001UMHM</masterLabel>
<sizeX>4</sizeX>
<sizeY>0</sizeY>
<summaryLayoutStyle>Default</summaryLayoutStyle>
</summaryLayout>
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<actionOverrides>
<actionName>Accept</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>CancelEdit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Clone</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Delete</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Edit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>List</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>New</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>SaveEdit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Tab</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>View</actionName>
<type>Default</type>
</actionOverrides>
<allowInChatterGroups>false</allowInChatterGroups>
<compactLayoutAssignment>Broker_Compact</compactLayoutAssignment>
<deploymentStatus>Deployed</deploymentStatus>
<enableActivities>false</enableActivities>
<enableBulkApi>true</enableBulkApi>
<enableFeeds>false</enableFeeds>
<enableHistory>false</enableHistory>
<enableReports>true</enableReports>
<enableSearch>true</enableSearch>
<enableSharing>true</enableSharing>
<enableStreamingApi>true</enableStreamingApi>
<label>Broker</label>
<nameField>
<label>Broker Name</label>
<type>Text</type>
</nameField>
<pluralLabel>Brokers</pluralLabel>
<searchLayouts></searchLayouts>
<sharingModel>ReadWrite</sharingModel>
<visibility>Public</visibility>
</CustomObject>
Loading

0 comments on commit f3cf83a

Please sign in to comment.