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: handling folders during various operations #208

Merged
merged 8 commits into from
Nov 20, 2020
Merged

Conversation

brpowell
Copy link
Contributor

@brpowell brpowell commented Nov 19, 2020

What does this PR do?

Properly handles folder components in the following scenarios:

  • Converting (remove file extension when converting to metadata format)
  • Package xml generation
  • Package xml parsing

What issues does this PR fix or reference?

@W-8380700@

@brpowell brpowell marked this pull request as ready for review November 20, 2020 14:52
@brpowell brpowell requested a review from a team as a code owner November 20, 2020 14:52
Comment on lines +131 to +135
let type = registry.getTypeByName(typeName);
// if there is no delimeter and it's a type in folders, infer folder component
if (type.folderType && !fullName.includes('/')) {
type = registry.getTypeByName(type.folderType);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a member of an inFolder type is encountered like so

<types>
  <member>A_Folder</member>
  <name>Report</name>
</types>

This will be resolved to the folder type related to Report

{
  fullName: 'A_Folder',
  type: {
    id: 'reportfolder',
    name: 'ReportFolder'
    // ...
  }
}

Comment on lines +223 to +233
// build folder related members separately to combine folder types and types in folders into one
const isFolderRelatedType = type.folderType || type.folderContentType;
if (isFolderRelatedType) {
const { name: contentTypeName } = type.folderContentType
? this.registry.getTypeByName(type.folderContentType)
: type;
if (!folderMembers.has(contentTypeName)) {
folderMembers.set(contentTypeName, []);
}
members = folderMembers.get(contentTypeName);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the reverse of parsing. If the set has these components:

[
  {
    fullName: 'A_Folder',
    type: {
      id: 'reportfolder',
      name: 'ReportFolder'
      // ...
    }
  },
  {
    fullName: 'A_Folder/My_Report',
    type: {
      id: 'report',
      name: 'Report'
      // ...
    }
  }
]

The manifest object is resolved to this:

{
  types: [
    {
      name: 'Report',
      members: ['A_Folder', 'A_Folder/My_Report']
    }
  ]
  // ...
}

Comment on lines 40 to 41
folderContentType?: string;
folderType?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These "fields" are a 1-to-1 relationship with each other. Types in folders define folderType to reference its folder type, while folder types define folderContentType to reference the type that it is a container for.

if (targetFormat === 'metadata') {
const { folderContentType, suffix } = component.type;
xmlDestination = folderContentType
? xmlDestination.replace(`.${suffix}`, '')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line is this fix for the second quirk during conversion.

@@ -352,15 +352,17 @@
"suffix": "report",
"directoryName": "reports",
"inFolder": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

inFolder is unnecessary now and considered deprecated, now that we have the two new fields to define folder relationships

@@ -23,6 +23,7 @@ export type MetadataType = {
* Whether or not components are stored in folders.
*
* __Examples:__ Reports, Dashboards, Documents, EmailTemplates
* @deprecated use `folderType` to get the related folder type, if one exists
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is deprecated are we removing it once we take care of references outside of the changes in this PR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's what I was thinking instead of changing it all now.

},
"dashboardfolder": {
"id": "dashboardfolder",
"name": "DashboardFolder",
"suffix": "dashboardFolder",
"directoryName": "dashboards",
"inFolder": false
"inFolder": false,
"folderContentType": "dashboard"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is folderContentType going to be updated by the describe api script, etc ?

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 catch, I'll update the registry script

Comment on lines +5 to 9
"emailtemplatefolder": {
"id": "emailfolder",
"name": "EmailFolder",
"suffix": "emailFolder"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type doesn't follow the typeName + "Folder" pattern like the rest, so add an override for it

@brpowell brpowell merged commit e09a007 into develop Nov 20, 2020
@brpowell brpowell deleted the bp/folderFixes branch November 20, 2020 22:04
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.

2 participants