All files / modules/85-cv/pages/health-source/HealthSourceTable HealthSourceTable.utils.ts

80.43% Statements 37/46
71.59% Branches 63/88
100% Functions 7/7
78.57% Lines 33/42

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                32x   32x   32x     32x 20x               13x       7x           32x 96x   1x     69x       1x         1x   1x   1x   1x   1x     2x         3x         2x     7x             4x     2x               32x       2x 2x       2x     2x 2x             2x     32x         2x     4x            
/*
 * 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 type { IconName } from '@wings-software/uicore'
import { isEmpty } from 'lodash-es'
import type { ChangeSourceDTO, Sources } from 'services/cv'
import { Connectors } from '@connectors/constants'
import type { UseStringsReturn } from 'framework/strings'
import { HealthSourceTypes } from '../types'
import type { UpdatedHealthSource, RowData } from '../HealthSourceDrawer/HealthSourceDrawerContent.types'
 
export const getTypeByFeature = (feature: string, getString: UseStringsReturn['getString']): string => {
  switch (feature) {
    case Connectors.APP_DYNAMICS:
    case Connectors.GCP:
    case Connectors.NEW_RELIC:
    case Connectors.PROMETHEUS:
    case Connectors.DYNATRACE:
    case HealthSourceTypes.StackdriverMetrics:
    case HealthSourceTypes.DatadogMetrics:
      return getString('pipeline.verification.analysisTab.metrics')
    case HealthSourceTypes.StackdriverLog:
    case HealthSourceTypes.DatadogLog:
    case HealthSourceTypes.Splunk:
      return getString('pipeline.verification.analysisTab.logs')
    default:
      return getString('common.repo_provider.customLabel')
  }
}
 
export const getIconBySourceType = (type: string): IconName => {
  switch (type) {
    case 'KUBERNETES':
      return 'service-kubernetes'
    case 'APP_DYNAMICS':
    case 'AppDynamics':
      return 'service-appdynamics'
    case 'HARNESS_CD10':
      return 'harness'
    case 'STACKDRIVER':
      return 'service-stackdriver'
    case 'DATADOG':
      return 'service-datadog'
    case 'NEW_RELIC':
    case 'NewRelic':
      return 'service-newrelic'
    case 'HEALTH':
      return 'health'
    case 'CANARY':
      return 'canary-outline'
    case 'BLUE_GREEN':
      return 'bluegreen'
    case 'TEST':
      return 'lab-test'
    case 'PROMETHEUS':
    case 'Prometheus':
      return 'service-prometheus'
    //TODO one type will be removed once it is full deprecated from backend.
    case 'STACKDRIVER_LOG':
    case 'StackdriverLog':
    case 'Stackdriver':
      return 'service-stackdriver'
    case 'DatadogMetrics':
    case 'DatadogLog':
    case 'DATADOG_METRICS':
    case 'DATADOG_LOG':
      return 'service-datadog'
    case 'SPLUNK':
    case 'Splunk':
      return 'service-splunk'
    case 'PagerDuty':
      return 'service-pagerduty'
    case 'CUSTOM_HEALTH_METRIC':
    case 'CUSTOM_HEALTH_LOG':
    case 'CustomHealthLog':
    case 'CustomHealthMetric':
      return 'service-custom-connector'
    case 'DYNATRACE':
    case 'Dynatrace':
      return 'service-dynatrace'
    case 'ErrorTracking':
      return 'error-tracking'
    default:
      return 'placeholder'
  }
}
 
export const createHealthsourceList = (
  healthSources: RowData[],
  healthSourcesPayload: UpdatedHealthSource
): UpdatedHealthSource[] => {
  let updatedHealthSources = []
  Eif (
    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 if (healthSources && !isEmpty(healthSources)) {
    updatedHealthSources = [...healthSources, healthSourcesPayload]
  } else {
    updatedHealthSources = [healthSourcesPayload]
  }
  return updatedHealthSources
}
 
export const deleteHealthSource = (
  selectedRow: RowData,
  changeSourcesData: ChangeSourceDTO[],
  tableData: RowData[]
): { monitoredService: { sources: Sources } } => {
  return {
    monitoredService: {
      sources: {
        healthSources: tableData?.filter(healthSource => healthSource.identifier !== selectedRow.identifier),
        changeSources: changeSourcesData
      }
    }
  }
}