All files / modules/85-cv/pages/health-source/HealthSourceDrawer/component/customiseHealthSource CustomiseHealthSource.utils.tsx

66.67% Statements 36/54
49.41% Branches 42/85
100% Functions 4/4
65.38% Lines 34/52

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              23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x     23x                 2x   1x                                                           1x     1x                 23x 2x 2x 2x       2x     1x 2x   1x     1x   2x    
/*
 * 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 React from 'react'
import { isEmpty } from 'lodash-es'
import GCOLogsMonitoringSource from '@cv/pages/health-source/connectors/GCOLogsMonitoringSource/GCOLogsMonitoringSource'
import SplunkHealthSource from '@cv/pages/health-source/connectors/SplunkHealthSource/SplunkHealthSource'
import AppDHealthSourceContainer from '@cv/pages/health-source/connectors/AppDynamics/AppDHealthSourceContainer'
import { PrometheusHealthSource } from '@cv/pages/health-source/connectors/PrometheusHealthSource/PrometheusHealthSource'
import NewrelicMonitoredSourceContainer from '@cv/pages/health-source/connectors/NewRelic/NewRelicHealthSourceContainer'
import { Connectors } from '@connectors/constants'
import { GCOMetricsHealthSource } from '@cv/pages/health-source/connectors/GCOMetricsHealthSource/GCOMetricsHealthSource'
import { GCOProduct } from '@cv/pages/health-source/connectors/GCOMetricsHealthSource/GCOMetricsHealthSource.utils'
import { HealthSourceTypes } from '@cv/pages/health-source/types'
import DatadogMetricsHealthSource from '@cv/pages/health-source/connectors/DatadogMetricsHealthSource/DatadogMetricsHealthSource'
import { DatadogProduct } from '@cv/pages/health-source/connectors/DatadogMetricsHealthSource/DatadogMetricsHealthSource.utils'
import { CustomHealthSource } from '@cv/pages/health-source/connectors/CustomHealthSource/CustomHealthSource'
import { DatadogLogsHealthSource } from '@cv/pages/health-source/connectors/DatadogLogsHealthSource/DatadogLogsHealthSource'
import ErrorTrackingHealthSource from '@cv/pages/health-source/connectors/ErrorTrackingHealthSource/ErrorTrackingHealthSource'
import DynatraceHealthSourceContainer from '@cv/pages/health-source/connectors/Dynatrace/DynatraceHealthSourceContainer'
import CustomHealthLogSource from '@cv/pages/health-source/connectors/CustomHealthLogSource/CustomHealthLogSource'
import { CustomHealthProduct } from '@cv/pages/health-source/connectors/CustomHealthSource/CustomHealthSource.constants'
import type { UpdatedHealthSource } from '../../HealthSourceDrawerContent.types'
 
export const LoadSourceByType = ({
  type,
  data,
  onSubmit
}: {
  type: string
  data: any
  onSubmit: (formdata: any, healthSourceList: UpdatedHealthSource) => Promise<void>
}): JSX.Element => {
  switch (type) {
    case HealthSourceTypes.AppDynamics:
      return <AppDHealthSourceContainer data={data} onSubmit={onSubmit} />
    case Connectors.GCP:
      if (data?.product?.value === GCOProduct.CLOUD_LOGS) {
        return <GCOLogsMonitoringSource data={data} onSubmit={onSubmit} />
      } else {
        return <GCOMetricsHealthSource data={data} onSubmit={onSubmit} />
      }
    case HealthSourceTypes.StackdriverLog:
      return <GCOLogsMonitoringSource data={data} onSubmit={onSubmit} />
    case HealthSourceTypes.StackdriverMetrics:
      return <GCOMetricsHealthSource data={data} onSubmit={onSubmit} />
    case Connectors.DATADOG:
      if (data?.product?.value === DatadogProduct.CLOUD_METRICS) {
        return <DatadogMetricsHealthSource data={data} onSubmit={onSubmit} />
      } else {
        return <DatadogLogsHealthSource data={data} onSubmit={onSubmit} />
      }
    case HealthSourceTypes.DatadogMetrics:
      return <DatadogMetricsHealthSource data={data} onSubmit={onSubmit} />
    case HealthSourceTypes.DatadogLog:
      return <DatadogLogsHealthSource data={data} onSubmit={onSubmit} />
    case HealthSourceTypes.Prometheus:
      return <PrometheusHealthSource data={data} onSubmit={onSubmit} />
    case Connectors.NEW_RELIC:
      return <NewrelicMonitoredSourceContainer data={data} onSubmit={onSubmit} />
    case Connectors.DYNATRACE:
      return <DynatraceHealthSourceContainer data={data} onSubmit={onSubmit} />
    case Connectors.SPLUNK:
      return <SplunkHealthSource data={data} onSubmit={onSubmit} />
    case HealthSourceTypes.CustomHealth:
      Iif (data.product?.value === CustomHealthProduct.METRICS) {
        return <CustomHealthSource data={data} onSubmit={onSubmit} />
      } else {
        return <CustomHealthLogSource data={data} onSubmit={onSubmit} />
      }
    case Connectors.ERROR_TRACKING:
      return <ErrorTrackingHealthSource data={data} onSubmit={onSubmit} />
    default:
      return <></>
  }
}
 
export const createHealthsourceList = (formData: any, healthSourcesPayload: UpdatedHealthSource): any => {
  const healthSources = formData?.healthSourceList
  let updatedHealthSources = []
  if (
    healthSources &&
    !isEmpty(healthSources) &&
    healthSources.some(
      (el: any) => el?.identifier === healthSourcesPayload?.identifier && el?.type === healthSourcesPayload?.type
    )
  ) {
    updatedHealthSources = healthSources?.map((el: any) =>
      el?.identifier === healthSourcesPayload?.identifier ? healthSourcesPayload : el
    )
  } else Iif (healthSources && !isEmpty(healthSources)) {
    updatedHealthSources = [...healthSources, healthSourcesPayload]
  } else {
    updatedHealthSources = [healthSourcesPayload]
  }
  return updatedHealthSources
}