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

fix: component set maps treat encoded and decoded keys as the same #1138

Merged
merged 6 commits into from
Oct 16, 2023

Conversation

shetzel
Copy link
Contributor

@shetzel shetzel commented Oct 11, 2023

What does this PR do?

ComponentSets use Maps with keys that are built from metadata fullNames. Some fullNames such as Layouts and Profiles can contain encoded characters since they allow end users to name them with any character. When these metadata types are retrieved from the org the fullNames are encoded, which results in encoded filenames written to disk. However, for source tracking the queries return fullNames that are decoded which results in no local matches when they actually refer to the same metadata.

To fix this situation we can search the ComponentSet maps using the keys "as is", and if not found try with a decoded or encoded key.

What issues does this PR fix or reference?

@W-11658886@
forcedotcom/cli#1683

See this PR in the source tracking library for testing ideas.

@shetzel shetzel requested a review from a team as a code owner October 11, 2023 17:46
Copy link
Contributor

@mshanemc mshanemc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with non-blocking comments/suggestions

// Internal map of decoded keys to encoded keys.
// E.g., { 'foo-v1.3 Layout': 'foo-v1%2E3 Layout' }
// This is initialized in the `keysMap` getter.
private internalkeysMap!: Map<string, string>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not init it during declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I originally had the Map initialization done during declaration and it would fail during construction due to the way super works. super must be the first call in a constructor, which means the map init was done after that. So if you construct a new map by passing in a nested array, it will call set() which needs the internal map but it wasn't initialized until later. To solve this problem I used the getter and conditionally initialized it there.
I'll add a comment.

// This is initialized in the `keysMap` getter.
private internalkeysMap!: Map<string, string>;

private get keysMap(): Map<string, string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you init at declaration, you also wouldn't have to have a getter for a private prop--you could just use the prop.

if (super.has(decodedKey)) {
return decodedKey;
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perf, maybe? you could try checking the keysMap 2nd instead of 3rd to defer the decode operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be done either way with the internal Map implementation.

@mshanemc
Copy link
Contributor

QA (repeating other PR's steps forcedotcom/source-tracking#458

add the title field to the Broker 1.1 layout and save
✅ retrieve preview matches changed layout to existing layout

Will Retrieve [1] files.
 Type   Fullname                       Path                                                                              
 ────── ────────────────────────────── ───────────────────────────────────────────────────────────────────────────────── 
 Layout Broker__c-v1%2E1 Broker Layout src/force-app/main/default/layouts/Broker__c-v1%2E1 Broker Layout.layout-meta.xml 

create new layout for Broker__c named 1.1 año día
✅ both retrieve (existing updates existing locally, new created in default dir with encoded name)

create new default dir src/unpackaged2
✅ preview shows existing file will be updated
✅ retrieve start updates existing

Profiles also use encoding

create Shane's new & fancy profile!
retrieve preview
✅ ignored is correct
remove Profiles from ignored
✅ will retrieve is correct
✅ retrieve creates 2 new profiles including

| Created Shane%27s new %26 fancy profile%21 Profile src/unpackaged2/main/default/profiles/Shane%27s new %26 fancy profile%21.profile-meta.xml 

new pkgdir as default
modify profile by adding a description
✅ retrieves to existing location, not default
📓 there are profilePasswordPolicies and profileSessionSettings added in the new defaultdir

@mshanemc mshanemc merged commit 7fe0bab into main Oct 16, 2023
63 checks passed
@mshanemc mshanemc deleted the sh/decoded-componentSet-keys branch October 16, 2023 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants