-
Notifications
You must be signed in to change notification settings - Fork 90
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
SALTO-582: custom obj translation reference fields and validation rules #813
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d17a0cc
custom obj translation refrence fields and validation rules
hadard d1b24d2
CR+
hadard 9aac21f
move tests
hadard afb212c
e2e improvments
hadard 9323598
take element id from parent annotation
hadard a79fe11
more improv
hadard e3a7eb4
fix tests
hadard 3c34d47
CR - renames
hadard 4c74c1a
more more CR ;)
hadard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"packages/*" | ||
], | ||
"nohoist": [ | ||
"salto-vscode/**" | ||
"vscode/**" | ||
] | ||
}, | ||
"devDependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/salesforce-adapter/src/filters/custom_object_translation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2020 Salto Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import wu from 'wu' | ||
import { | ||
Element, ElemID, ReferenceExpression, Field, isObjectType, | ||
} from '@salto-io/adapter-api' | ||
import { findInstances, findElements } from '@salto-io/adapter-utils' | ||
import { collections } from '@salto-io/lowerdash' | ||
import _ from 'lodash' | ||
import { logger } from '@salto-io/logging' | ||
import { apiName } from '../transformers/transformer' | ||
import { FilterWith } from '../filter' | ||
import { relativeApiName, instanceParent, parentApiNameToMetadataTypeInstances } from './utils' | ||
import { SALESFORCE, CUSTOM_OBJECT_TRANSLATION_METADATA_TYPE, VALIDATION_RULES_METADATA_TYPE } from '../constants' | ||
|
||
const log = logger(module) | ||
|
||
const { makeArray } = collections.array | ||
|
||
const FIELDS = 'fields' | ||
const NAME = 'name' | ||
const VALIDATION_RULES = 'validationRules' | ||
|
||
/** | ||
* This filter change CustomObjectTranslation logical references to fields and validation rules to | ||
* Salto referenes | ||
*/ | ||
const filterCreator = (): FilterWith<'onFetch'> => ({ | ||
onFetch: async (elements: Element[]) => { | ||
const allCustomObjectFields = (elemID: ElemID): Iterable<Field> => | ||
wu(findElements(elements, elemID)) | ||
.filter(isObjectType) | ||
.map(elem => Object.values(elem.fields)) | ||
.flatten() | ||
|
||
const customToRule = parentApiNameToMetadataTypeInstances( | ||
elements, VALIDATION_RULES_METADATA_TYPE | ||
) | ||
|
||
wu(findInstances(elements, new ElemID(SALESFORCE, CUSTOM_OBJECT_TRANSLATION_METADATA_TYPE))) | ||
.forEach(customTranslation => { | ||
const customObjectElemId = instanceParent(customTranslation) | ||
if (_.isUndefined(customObjectElemId)) { | ||
log.warn('failed to find custom object for custom translation %s', | ||
apiName(customTranslation)) | ||
return | ||
} | ||
|
||
// Change fields to reference | ||
const customFields = new Map( | ||
wu(allCustomObjectFields(customObjectElemId)) | ||
.map(f => [apiName(f, true), f]) | ||
) | ||
makeArray(customTranslation.value[FIELDS]).forEach(field => { | ||
const customField = customFields.get(field[NAME]) | ||
if (customField) { | ||
field[NAME] = new ReferenceExpression(customField.elemID) | ||
} else { | ||
log.warn('failed to find field %s in %s', field[NAME], customObjectElemId.getFullName()) | ||
} | ||
}) | ||
|
||
// Change validation rules to refs | ||
const objRules = new Map( | ||
makeArray(customToRule[customObjectElemId.getFullName()]) | ||
.map(r => [relativeApiName(r), r]) | ||
) | ||
makeArray(customTranslation.value[VALIDATION_RULES]).forEach(rule => { | ||
const ruleInstance = objRules.get(rule[NAME]) | ||
if (ruleInstance) { | ||
rule[NAME] = new ReferenceExpression(ruleInstance.elemID) | ||
} else { | ||
log.warn('failed to validation rule %s for %s', rule[NAME], | ||
customObjectElemId.getFullName()) | ||
} | ||
}) | ||
}) | ||
}, | ||
}) | ||
|
||
export default filterCreator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unrelated to this PR.
maybe a separate commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I wonder if it was actually needed so it should be fixed instead of removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per my understanding, it should be removed as “nohoist” enables workspaces to consume 3rd-party libraries not yet compatible with its hoisting scheme." and AFAIK we don't have such a case.
Notice that practically it's not working for a long time (not sure if it means something as vscode extension is also not working)
@royra @roironn WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's needed for packaging of the vscode extension: microsoft/vscode-vsce#300
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so I'll change
salto-vscode
->vscode
instead of removing