Skip to content

Commit

Permalink
Revert "SALTO-4990: Salesforce: Remodel picklist value lists to maps,…
Browse files Browse the repository at this point in the history
… to allo…" (#6680)

This reverts commit b367e65.
  • Loading branch information
yelly authored Oct 15, 2024
1 parent acd202b commit 524abfb
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 729 deletions.
2 changes: 1 addition & 1 deletion packages/salesforce-adapter/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = deepMerge(require('../../jest.base.config.js'), {
: undefined,
coverageThreshold: {
global: {
branches: 87.75,
branches: 87.8,
functions: 94,
lines: 95,
statements: 95,
Expand Down
3 changes: 1 addition & 2 deletions packages/salesforce-adapter/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ export const allFilters: Array<FilterCreator> = [
profilePermissionsFilter,
// emailTemplateFilter should run before convertMapsFilter
emailTemplateFilter,
// standardValueSetFilter should run before convertMapsFilter
standardValueSetFilter,
// convertMapsFilter should run before profile fieldReferencesFilter
convertMapsFilter,
standardValueSetFilter,
flowFilter,
customObjectInstanceReferencesFilter,
cpqReferencableFieldReferencesFilter,
Expand Down
2 changes: 0 additions & 2 deletions packages/salesforce-adapter/src/change_validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import elementApiVersionValidator from './change_validators/element_api_version'
import cpqBillingStartDate from './change_validators/cpq_billing_start_date'
import cpqBillingTriggers from './change_validators/cpq_billing_triggers'
import managedApexComponent from './change_validators/managed_apex_component'
import orderedMaps from './change_validators/ordered_maps'
import SalesforceClient from './client/client'
import { ChangeValidatorName, DEPLOY_CONFIG, FetchProfile, SalesforceConfig } from './types'
import { buildFetchProfile } from './fetch_profile/fetch_profile'
Expand Down Expand Up @@ -105,7 +104,6 @@ export const changeValidators: Record<ChangeValidatorName, ChangeValidatorCreato
cpqBillingStartDate: () => cpqBillingStartDate,
cpqBillingTriggers: () => cpqBillingTriggers,
managedApexComponent: () => managedApexComponent,
orderedMaps: ({ fetchProfile }) => orderedMaps(fetchProfile),
..._.mapValues(getDefaultChangeValidators(), validator => () => validator),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
Value,
Values,
isReferenceExpression,
getField,
} from '@salto-io/adapter-api'
import { safeJsonStringify } from '@salto-io/adapter-utils'
import { collections } from '@salto-io/lowerdash'
Expand All @@ -39,45 +38,23 @@ type FieldDef = {
const FIELD_NAME_TO_INNER_CONTEXT_FIELD: Record<string, FieldDef> = {
applicationVisibilities: { name: 'application' },
recordTypeVisibilities: { name: 'recordType', nested: true },

// TODO(SALTO-4990): Remove once picklistsAsMaps FF is deployed and removed.
standardValue: { name: 'label' },
customValue: { name: 'label' },

'standardValue.values': { name: 'label' },
'customValue.values': { name: 'label' },
}

type ValueSetInnerObject = {
default: boolean
label: string
} & Values[]

type FieldWithValueSetList = Field & {
type FieldWithValueSet = Field & {
annotations: {
valueSet: Array<ValueSetInnerObject>
}
}

// TODO(SALTO-4990): Remove once picklistsAsMaps FF is deployed and removed.
type FieldWithValueSetOrderedMap = Field & {
annotations: {
valueSet: {
values: Array<ValueSetInnerObject>
}
}
}

type FieldWithValueSet = FieldWithValueSetList | FieldWithValueSetOrderedMap

const isFieldWithValueSetList = (field: Field): field is FieldWithValueSetList =>
_.isArray(field.annotations[FIELD_ANNOTATIONS.VALUE_SET])

const isFieldWithOrderedMapValueSet = (field: Field): field is FieldWithValueSetOrderedMap =>
_.isArray(field.annotations[FIELD_ANNOTATIONS.VALUE_SET]?.order)

const isFieldWithValueSet = (field: Field): field is FieldWithValueSet =>
isFieldWithValueSetList(field) || isFieldWithOrderedMapValueSet(field)
_.isArray(field.annotations[FIELD_ANNOTATIONS.VALUE_SET])

const formatContext = (context: Value): string => {
if (isReferenceExpression(context)) {
Expand Down Expand Up @@ -107,9 +84,7 @@ const createFieldChangeError = (field: Field, contexts: string[]): ChangeError =
})

const getPicklistMultipleDefaultsErrors = (field: FieldWithValueSet): ChangeError[] => {
const contexts = (
isFieldWithValueSetList(field) ? field.annotations.valueSet : Object.values(field.annotations.valueSet.values)
)
const contexts = field.annotations.valueSet
.filter(obj => obj.default)
.map(obj => obj[LABEL])
.map(formatContext)
Expand Down Expand Up @@ -137,9 +112,6 @@ const getInstancesMultipleDefaultsErrors = async (after: InstanceElement): Promi
valueName: string,
): Promise<string[] | undefined> => {
const defaultObjects = await getDefaultObjectsList(value, fieldType)
if (!_.isArray(defaultObjects)) {
return undefined
}
const contexts = defaultObjects
.filter(val => val.default)
.map(obj => obj[valueName])
Expand All @@ -158,18 +130,17 @@ const getInstancesMultipleDefaultsErrors = async (after: InstanceElement): Promi
return []
}

const errors: ChangeError[] = await awu(Object.keys(FIELD_NAME_TO_INNER_CONTEXT_FIELD))
.filter(fieldPath => _.has(after.value, fieldPath))
.flatMap(async fieldPath => {
const value = _.get(after.value, fieldPath)
const field = await getField(await after.getType(), fieldPath.split('.'))
const errors: ChangeError[] = await awu(Object.entries(after.value))
.filter(([fieldName]) => Object.keys(FIELD_NAME_TO_INNER_CONTEXT_FIELD).includes(fieldName))
.flatMap(async ([fieldName, value]) => {
const field = (await after.getType()).fields[fieldName]
if (field === undefined) {
// Can happen if the field exists in the instance but not in the type.
return []
}
const fieldType = await field.getType()
const valueName = FIELD_NAME_TO_INNER_CONTEXT_FIELD[fieldPath].name
if (_.isPlainObject(value) && FIELD_NAME_TO_INNER_CONTEXT_FIELD[fieldPath].nested) {
const valueName = FIELD_NAME_TO_INNER_CONTEXT_FIELD[fieldName].name
if (_.isPlainObject(value) && FIELD_NAME_TO_INNER_CONTEXT_FIELD[fieldName].nested) {
return awu(Object.entries(value)).flatMap(async ([_key, innerValue]) => {
const startLevelType = isMapType(fieldType) ? await fieldType.getInnerType() : fieldType
const defaultsContexts = await findMultipleDefaults(innerValue, startLevelType, valueName)
Expand Down
137 changes: 0 additions & 137 deletions packages/salesforce-adapter/src/change_validators/ordered_maps.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const optionalFeaturesDefaultValues: OptionalFeaturesDefaultValues = {
logDiffsFromParsingXmlNumbers: true,
extendTriggersMetadata: false,
removeReferenceFromFilterItemToRecordType: false,
picklistsAsMaps: false,
}

type BuildFetchProfileParams = {
Expand Down
Loading

0 comments on commit 524abfb

Please sign in to comment.