All files / modules/85-cv/pages/health-source/connectors/AppDynamics AppDHealthSource.utils.ts

97.06% Statements 198/204
79.08% Branches 397/502
100% Functions 38/38
96.72% Lines 177/183

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566              27x             27x                 27x 27x     27x 3x 3x 3x 3x 7x               3x     27x 3x 3x 3x 3x 3x 3x   3x 7x                 3x     27x 4x 2x             4x   4x                         4x 2x 2x 2x   2x                                             4x     27x             30x 52x   30x 18x         30x 18x         30x   30x 4x         30x 13x                   30x     27x               13x   13x 10x     13x 1x 1x   3x   3x 1x   1x 1x       20x 13x     13x     13x     10x 4x   6x     13x   13x           13x 1x     13x           13x 13x     27x 10x 10x 9x     10x 9x     10x 10x     10x 1x         10x 1x       9x 1x         10x     27x               13x 18x     13x     10x 4x   6x     13x 1x       13x     27x             13x 13x       13x 13x 12x 1x       12x 3x       12x 1x           13x     27x             7x 7x 7x 1x 1x 1x   6x 6x     7x     27x       6x 2x 2x 2x 2x     27x 3x             3x 3x                             5x   5x             5x 5x   5x 2x   5x 1x     5x   5x                                           3x                   6x           6x         27x                 2x                             2x 2x 1x 1x   1x 1x 1x   1x 1x     27x 9x 9x 12x 9x     27x                           6x 6x 6x 6x 6x   6x     6x                                   27x 8x               27x       16x   36x   27x 9x   9x   27x 18x           27x       25x  
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import { cloneDeep, isEmpty } from 'lodash-es'
import type { FormikProps } from 'formik'
import type { StringKeys } from 'framework/strings'
import type { StringsMap } from 'framework/strings/StringsContext'
import type { AppDMetricDefinitions, AppDynamicsHealthSourceSpec, MetricPackDTO, RiskProfile } from 'services/cv'
import type { SelectOption } from '@pipeline/components/PipelineSteps/Steps/StepsTypes'
import type { UpdatedHealthSource } from '../../HealthSourceDrawer/HealthSourceDrawerContent.types'
import { HealthSourceTypes } from '../../types'
import type {
  AppDynamicsData,
  AppDynamicsFomikFormInterface,
  MapAppDynamicsMetric,
  ValidateMappingInterface
} from './AppDHealthSource.types'
import type { BasePathData } from './Components/BasePath/BasePath.types'
import type { MetricPathData } from './Components/MetricPath/MetricPath.types'
import { AppDynamicsMonitoringSourceFieldNames, initCustomForm } from './AppDHealthSource.constants'
import { PATHTYPE } from './Components/AppDCustomMetricForm/AppDCustomMetricForm.constants'
import type { CustomMappedMetric } from '../../common/CustomMetric/CustomMetric.types'
 
export const convertStringBasePathToObject = (baseFolder: string | BasePathData): BasePathData => {
  let basePathObj = {} as any
  Eif (typeof baseFolder === 'string') {
    const list = [...baseFolder?.split('|'), '']
    list.forEach((item, index) => {
      basePathObj[`basePathDropdown_${index}`] = {
        path: index === 0 ? '' : list.slice(0, index).join('|'),
        value: item
      }
    })
  } else {
    basePathObj = baseFolder
  }
  return basePathObj
}
 
export const convertStringMetricPathToObject = (metricPath: string | MetricPathData): MetricPathData => {
  let metricPathObj = {} as any
  Eif (typeof metricPath === 'string') {
    const list = [...metricPath?.split('|'), '']
    let secondLastIndex = 0
    Eif (list.length > 1) {
      secondLastIndex = list.length - 2
    }
    list.forEach((item, index) => {
      metricPathObj[`metricPathDropdown_${index}`] = {
        value: item,
        path: index === 0 ? '' : list.slice(0, index).join('|'),
        isMetric: secondLastIndex === index ? true : false
      }
    })
  } else {
    metricPathObj = metricPath
  }
  return metricPathObj
}
 
export const createAppDynamicsData = (sourceData: any): AppDynamicsData => {
  const payload: UpdatedHealthSource = sourceData?.healthSourceList?.find(
    (source: UpdatedHealthSource) => source.identifier === sourceData.healthSourceIdentifier
  )
 
  const {
    applicationName = '',
    tierName = '',
    metricPacks = undefined
  } = (payload?.spec as AppDynamicsHealthSourceSpec) || {}
 
  const appdData = {
    name: sourceData?.healthSourceName,
    identifier: sourceData?.healthSourceIdentifier,
    connectorRef: sourceData?.connectorRef,
    isEdit: sourceData?.isEdit,
    product: sourceData?.product,
    type: HealthSourceTypes.AppDynamics,
    applicationName,
    tierName,
    metricPacks,
    mappedServicesAndEnvs: new Map()
  }
 
  for (const metricDefinition of (payload?.spec as AppDynamicsHealthSourceSpec)?.metricDefinitions || []) {
    Eif (metricDefinition?.metricName) {
      const basePathObj = convertStringBasePathToObject(metricDefinition?.baseFolder || '')
      const metricPathObj = convertStringMetricPathToObject(metricDefinition?.metricPath || '')
 
      appdData.mappedServicesAndEnvs.set(metricDefinition.metricName, {
        metricPath: metricPathObj,
        basePath: basePathObj,
        metricName: metricDefinition.metricName,
        metricIdentifier: metricDefinition.identifier,
        riskCategory:
          metricDefinition?.analysis?.riskProfile?.category && metricDefinition?.analysis?.riskProfile?.metricType
            ? `${metricDefinition?.analysis?.riskProfile?.category}/${metricDefinition?.analysis?.riskProfile?.metricType}`
            : '',
        serviceInstance: metricDefinition?.analysis?.deploymentVerification?.serviceInstanceFieldName,
        lowerBaselineDeviation:
          metricDefinition?.analysis?.riskProfile?.thresholdTypes?.includes('ACT_WHEN_LOWER') || false,
        higherBaselineDeviation:
          metricDefinition?.analysis?.riskProfile?.thresholdTypes?.includes('ACT_WHEN_HIGHER') || false,
        groupName: { label: metricDefinition.groupName || '', value: metricDefinition.groupName || '' },
        continuousVerification: metricDefinition?.analysis?.deploymentVerification?.enabled,
        healthScore: metricDefinition?.analysis?.liveMonitoring?.enabled,
        sli: metricDefinition.sli?.enabled,
        serviceInstanceMetricPath: metricDefinition.analysis?.deploymentVerification?.serviceInstanceMetricPath
      })
    }
  }
 
  return appdData
}
 
export const validateMapping = ({
  values,
  createdMetrics,
  selectedMetricIndex,
  getString,
  mappedMetrics
}: ValidateMappingInterface): ((key: string | boolean | string[]) => string) => {
  let errors = {} as any
  const metricValueList = values?.metricData ? Object.values(values?.metricData).filter(val => val) : []
 
  if (!values.appdApplication) {
    errors[AppDynamicsMonitoringSourceFieldNames.APPDYNAMICS_APPLICATION] = getString(
      'cv.healthSource.connectors.AppDynamics.validation.application'
    )
  }
 
  if (!values.appDTier) {
    errors[AppDynamicsMonitoringSourceFieldNames.APPDYNAMICS_TIER] = getString(
      'cv.healthSource.connectors.AppDynamics.validation.tier'
    )
  }
 
  const hasMetricNameAndCustomMetricAdded = !!values.metricName && values?.showCustomMetric
 
  if (!metricValueList.length && !hasMetricNameAndCustomMetricAdded) {
    errors[AppDynamicsMonitoringSourceFieldNames.METRIC_DATA] = getString(
      'cv.monitoringSources.appD.validations.selectMetricPack'
    )
  }
 
  if (values?.showCustomMetric) {
    errors = validateCustomMetricFields(
      values,
      createdMetrics,
      selectedMetricIndex,
      errors,
      getString,
      mappedMetrics as Map<string, MapAppDynamicsMetric>
    )
  }
 
  return errors
}
 
const validateCustomMetricFields = (
  values: any,
  createdMetrics: string[],
  selectedMetricIndex: number,
  errors: any,
  getString: (key: StringKeys) => string,
  mappedMetrics?: Map<string, MapAppDynamicsMetric>
): ((key: string | boolean | string[]) => string) => {
  let _error = cloneDeep(errors)
 
  if (values.pathType === PATHTYPE.DropdownPath) {
    _error = validateMetricBasePath(values, _error, getString)
  }
 
  if (values.pathType === PATHTYPE.FullPath) {
    const isfullPathEmpty = !values.fullPath.length
    const fullPathContainsTierInfo = values.fullPath
      .split('|')
      .map((item: string) => item.trim())
      .includes(values?.appDTier)
    const incorrectPairing = values.fullPath.split('|').filter((item: string) => !item.length).length
    Iif (incorrectPairing && isfullPathEmpty) {
      _error[PATHTYPE.FullPath] = getString('cv.healthSource.connectors.AppDynamics.validation.fullPath')
    } else Eif (!fullPathContainsTierInfo) {
      _error[PATHTYPE.FullPath] = getString('cv.healthSource.connectors.AppDynamics.validation.missingTierInFullPath')
    }
  }
 
  const isAssignComponentValid = [values.sli, values.continuousVerification, values.healthScore].find(i => i)
  const isRiskCategoryValid = !!values?.riskCategory
 
  const selectedMetricIndexNew =
    createdMetrics.indexOf(values.metricName) > -1 ? selectedMetricIndex : createdMetrics.indexOf(values.metricName)
 
  const duplicateNames =
    createdMetrics.length < 2
      ? []
      : createdMetrics?.filter((metricName, index) => {
          if (index === selectedMetricIndexNew) {
            return false
          }
          return metricName === values.metricName
        })
 
  _error = validateIdentifier(values, createdMetrics, selectedMetricIndexNew, _error, getString, mappedMetrics)
 
  Iif (!values.groupName) {
    _error[AppDynamicsMonitoringSourceFieldNames.GROUP_NAME] = getString(
      'cv.monitoringSources.prometheus.validation.groupName'
    )
  }
 
  if (!values.metricName) {
    _error[AppDynamicsMonitoringSourceFieldNames.METRIC_NAME] = getString('cv.monitoringSources.metricNameValidation')
  }
 
  Iif (values.metricName && duplicateNames.length) {
    _error[AppDynamicsMonitoringSourceFieldNames.METRIC_NAME] = getString(
      'cv.monitoringSources.prometheus.validation.metricNameUnique'
    )
  }
 
  _error = validateAssignComponent(isAssignComponentValid, _error, getString, values, isRiskCategoryValid)
  return _error
}
 
const validateMetricBasePath = (values: any, errors: any, getString: (key: StringKeys) => string) => {
  const _error = cloneDeep(errors)
  const isBasePathValid = values?.basePath
    ? Object.values(values?.basePath as BasePathData).some(path => path?.value)
    : false
 
  const isMetricPathValid = values?.metricPath
    ? Object.values(values?.metricPath as MetricPathData).some(path => path?.value)
    : false
 
  const metricHasLeafNodeSelected = values?.metricPath
    ? Object.values(values?.metricPath as MetricPathData).some(item => item.isMetric)
    : false
 
  if (!isBasePathValid) {
    _error[AppDynamicsMonitoringSourceFieldNames.BASE_PATH] = getString(
      'cv.healthSource.connectors.AppDynamics.validation.basePath'
    )
  }
 
  if (!isMetricPathValid) {
    _error[AppDynamicsMonitoringSourceFieldNames.METRIC_PATH] = getString(
      'cv.healthSource.connectors.AppDynamics.validation.metricPath'
    )
  } else {
    if (!metricHasLeafNodeSelected) {
      _error[AppDynamicsMonitoringSourceFieldNames.METRIC_PATH] = getString(
        'cv.healthSource.connectors.AppDynamics.validation.metricPathWithoutLeafNode'
      )
    }
  }
  return _error
}
 
const validateIdentifier = (
  values: any,
  createdMetrics: string[],
  selectedMetricIndex: number,
  errors: any,
  getString: (key: StringKeys) => string,
  mappedMetrics?: Map<string, MapAppDynamicsMetric>
): ((key: string | boolean | string[]) => string) => {
  const _error = cloneDeep(errors)
  const identifiers = createdMetrics.map(metricName => mappedMetrics?.get(metricName)?.metricIdentifier)
 
  const duplicateIdentifier =
    identifiers.length < 2
      ? []
      : identifiers?.filter((identifier, index) => {
          if (index === selectedMetricIndex) {
            return false
          }
          return identifier === values.metricIdentifier
        })
 
  if (values.identifier && duplicateIdentifier.length) {
    _error[AppDynamicsMonitoringSourceFieldNames.METRIC_IDENTIFIER] = getString(
      'cv.monitoringSources.prometheus.validation.metricIdentifierUnique'
    )
  }
  return _error
}
 
const validateAssignComponent = (
  isAssignComponentValid: boolean,
  errors: any,
  getString: (key: StringKeys) => string,
  values: any,
  isRiskCategoryValid: boolean
): ((key: string | boolean | string[]) => string) => {
  const _error = cloneDeep(errors)
  Iif (!isAssignComponentValid) {
    _error[AppDynamicsMonitoringSourceFieldNames.SLI] = getString(
      'cv.monitoringSources.gco.mapMetricsToServicesPage.validation.baseline'
    )
  } else Eif (isAssignComponentValid) {
    if (values.continuousVerification || values.healthScore) {
      if (values.lowerBaselineDeviation !== true && values.higherBaselineDeviation !== true) {
        _error[AppDynamicsMonitoringSourceFieldNames.LOWER_BASELINE_DEVIATION] = getString(
          'cv.monitoringSources.prometheus.validation.deviation'
        )
      }
      if (values.continuousVerification && !values.serviceInstanceMetricPath) {
        _error[AppDynamicsMonitoringSourceFieldNames.CONTINUOUS_VERIFICATION] = getString(
          'cv.healthSource.connectors.AppDynamics.validation.missingServiceInstanceMetricPath'
        )
      }
      if (!isRiskCategoryValid) {
        _error[AppDynamicsMonitoringSourceFieldNames.RISK_CATEGORY] = getString(
          'cv.monitoringSources.gco.mapMetricsToServicesPage.validation.riskCategory'
        )
      }
    }
  }
  return _error
}
 
export const getBaseAndMetricPath = (
  basePath: BasePathData,
  metricPath: MetricPathData,
  fullPath: string | null,
  appDTier: string
): { derivedBasePath: string; derivedMetricPath: string } => {
  // convert full path to metricPath and basePath
  let derivedBasePath = ''
  let derivedMetricPath = ''
  if (fullPath) {
    const data = convertFullPathToBaseAndMetric(fullPath, appDTier)
    derivedBasePath = data.derivedBasePath
    derivedMetricPath = data.derivedMetricPath
  } else {
    derivedBasePath = basePath[Object.keys(basePath)[Object.keys(basePath).length - 1]]?.path
    derivedMetricPath = metricPath[Object.keys(metricPath)[Object.keys(metricPath).length - 1]]?.path
  }
 
  return { derivedBasePath, derivedMetricPath }
}
 
export const convertFullPathToBaseAndMetric = (
  fullPath: string,
  appDTier: string
): { derivedBasePath: string; derivedMetricPath: string } => {
  const fullPathArray = fullPath.split('|').map((item: string) => item.trim())
  const indexOfManager = fullPathArray.indexOf(appDTier)
  const derivedBasePath = fullPathArray.slice(0, indexOfManager).join('|')
  const derivedMetricPath = fullPathArray.slice(indexOfManager + 1, fullPathArray.length).join('|')
  return { derivedBasePath, derivedMetricPath }
}
 
export const createAppDynamicsPayload = (formData: any): UpdatedHealthSource | null => {
  const specPayload = {
    applicationName: formData.appdApplication as string,
    tierName: formData.appDTier as string,
    metricData: formData.metricData,
    metricDefinitions: [] as AppDMetricDefinitions[]
  }
 
  Eif (formData.showCustomMetric) {
    for (const entry of formData.mappedServicesAndEnvs.entries()) {
      const {
        metricName,
        groupName,
        riskCategory,
        lowerBaselineDeviation,
        higherBaselineDeviation,
        sli,
        continuousVerification,
        healthScore,
        basePath,
        metricPath,
        metricIdentifier,
        serviceInstanceMetricPath,
        fullPath
      } = entry[1]
 
      const { derivedBasePath, derivedMetricPath } = getBaseAndMetricPath(
        basePath,
        metricPath,
        fullPath,
        formData.appDTier
      )
 
      const [category, metricType] = riskCategory?.split('/') || []
      const thresholdTypes: RiskProfile['thresholdTypes'] = []
 
      if (lowerBaselineDeviation) {
        thresholdTypes.push('ACT_WHEN_LOWER')
      }
      if (higherBaselineDeviation) {
        thresholdTypes.push('ACT_WHEN_HIGHER')
      }
 
      const ifOnlySliIsSelected = Boolean(sli) && !(Boolean(healthScore) || Boolean(continuousVerification))
 
      specPayload?.metricDefinitions?.push({
        identifier: metricIdentifier,
        metricName,
        baseFolder: derivedBasePath,
        metricPath: derivedMetricPath,
        groupName: groupName?.value as string,
        sli: { enabled: Boolean(sli) },
        analysis: {
          riskProfile: ifOnlySliIsSelected
            ? {}
            : {
                category,
                metricType,
                thresholdTypes
              },
          liveMonitoring: { enabled: Boolean(healthScore) },
          deploymentVerification: { enabled: Boolean(continuousVerification), serviceInstanceMetricPath }
        }
      })
    }
  }
 
  return {
    name: formData.name || (formData.healthSourceName as string),
    identifier: formData.identifier || (formData.healthSourceIdentifier as string),
    type: 'AppDynamics' as any,
    spec: {
      ...specPayload,
      feature: 'Application Monitoring' as string,
      connectorRef: (formData?.connectorRef?.connector?.identifier as string) || (formData.connectorRef as string),
      metricPacks: Object.entries(formData?.metricData)
        .map(item => {
          return item[1]
            ? {
                identifier: item[0]
              }
            : {}
        })
        .filter(item => !isEmpty(item))
    }
  }
}
 
export const submitData = (
  formik: FormikProps<AppDynamicsFomikFormInterface>,
  mappedMetrics: Map<string, CustomMappedMetric>,
  selectedMetric: string,
  selectedMetricIndex: number,
  createdMetrics: string[],
  getString: (key: StringKeys) => string,
  onSubmit: (healthSourcePayload: any) => void
): void => {
  formik.setTouched({
    ...formik.touched,
    [AppDynamicsMonitoringSourceFieldNames.APPDYNAMICS_TIER]: true,
    [AppDynamicsMonitoringSourceFieldNames.APPDYNAMICS_APPLICATION]: true,
    [AppDynamicsMonitoringSourceFieldNames.SLI]: true,
    [AppDynamicsMonitoringSourceFieldNames.CONTINUOUS_VERIFICATION]: true,
    [AppDynamicsMonitoringSourceFieldNames.GROUP_NAME]: true,
    [AppDynamicsMonitoringSourceFieldNames.METRIC_NAME]: true,
    [AppDynamicsMonitoringSourceFieldNames.LOWER_BASELINE_DEVIATION]: true,
    [AppDynamicsMonitoringSourceFieldNames.RISK_CATEGORY]: true,
    [AppDynamicsMonitoringSourceFieldNames.BASE_PATH]: { basePathDropdown_0: { value: true, path: true } },
    [AppDynamicsMonitoringSourceFieldNames.METRIC_PATH]: { metricPathDropdown_0: { value: true, path: true } },
    [AppDynamicsMonitoringSourceFieldNames.METRIC_DATA]: { Errors: true, Performance: true },
    [PATHTYPE.FullPath]: true
  })
  const errors = validateMapping({ values: formik.values, createdMetrics, selectedMetricIndex, getString })
  if (Object.keys(errors || {})?.length > 0) {
    formik.validateForm()
    return
  }
  const updatedMetric = formik.values
  Eif (updatedMetric) {
    mappedMetrics.set(selectedMetric, updatedMetric)
  }
  const updatedValues = { ...formik.values, mappedServicesAndEnvs: mappedMetrics }
  onSubmit(updatedValues)
}
 
export const convertMetricPackToMetricData = (value?: MetricPackDTO[]) => {
  const dataObject: { [key: string]: boolean } = {}
  const metricList: MetricPackDTO[] = value || []
  metricList.forEach((i: MetricPackDTO) => (dataObject[i.identifier as string] = true))
  return dataObject
}
 
export const createAppDFormData = (
  appDynamicsData: AppDynamicsData,
  mappedMetrics: Map<string, CustomMappedMetric>,
  selectedMetric: string,
  nonCustomFeilds: {
    appdApplication: string
    appDTier: string
    metricPacks?: MetricPackDTO[]
    metricData: {
      [key: string]: boolean
    }
  },
  showCustomMetric: boolean
): AppDynamicsFomikFormInterface => {
  const mappedMetricsData = mappedMetrics.get(selectedMetric) as MapAppDynamicsMetric
  const metricIdentifier = mappedMetricsData?.metricIdentifier || selectedMetric?.split(' ').join('_')
  const { basePath = {}, metricPath = {} } = mappedMetricsData || {}
  const lastItemBasePath = Object.keys(basePath)[Object.keys(basePath).length - 1]
  const lastItemMetricPath = Object.keys(metricPath)[Object.keys(metricPath).length - 1]
  const fullPath =
    basePath[lastItemBasePath]?.path && metricPath[lastItemMetricPath]?.path && appDynamicsData.tierName
      ? `${basePath[lastItemBasePath]?.path}|${appDynamicsData.tierName}|${metricPath[lastItemMetricPath]?.path}`
      : ''
  return {
    name: appDynamicsData.name,
    identifier: appDynamicsData.identifier,
    connectorRef: appDynamicsData.connectorRef,
    isEdit: appDynamicsData.isEdit,
    product: appDynamicsData.product,
    type: appDynamicsData.type,
    pathType: PATHTYPE.DropdownPath,
    fullPath,
    mappedServicesAndEnvs: appDynamicsData.mappedServicesAndEnvs,
    ...nonCustomFeilds,
    ...(mappedMetrics.get(selectedMetric) as MapAppDynamicsMetric),
    metricName: selectedMetric,
    showCustomMetric,
    metricIdentifier
  }
}
 
export const initializeNonCustomFields = (appDynamicsData: AppDynamicsData) => {
  return {
    appdApplication: appDynamicsData.applicationName || '',
    appDTier: appDynamicsData.tierName || '',
    metricPacks: appDynamicsData.metricPacks || undefined,
    metricData: convertMetricPackToMetricData(appDynamicsData?.metricPacks)
  }
}
 
export const setAppDynamicsApplication = (
  appdApplication: string,
  applicationOptions: SelectOption[]
): SelectOption | undefined =>
  !appdApplication
    ? { label: '', value: '' }
    : applicationOptions.find((item: SelectOption) => item.label === appdApplication)
 
export const setAppDynamicsTier = (tierLoading: boolean, appDTier: string, tierOptions: SelectOption[]) =>
  tierLoading || !appDTier
    ? { label: '', value: '' }
    : tierOptions.find((item: SelectOption) => item.label === appDTier)
 
export const initAppDCustomFormValue = () => {
  return {
    ...initCustomForm,
    groupName: { label: '', value: '' }
  }
}
 
export const getPlaceholder = (
  loading: boolean,
  placeholderText: keyof StringsMap,
  getString: (key: StringKeys) => string
): string => (loading ? getString('loading') : getString(placeholderText))