All files / modules/35-connectors/components/CreateConnectorWizard CreateConnectorWizard.tsx

72.22% Statements 65/90
30.56% Branches 11/36
75% Functions 3/4
71.59% Lines 63/88

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              218x 218x 218x       218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x 218x                                 218x 20x 18x 18x               18x                         18x       18x 18x 14x         18x       1x   5x   1x   1x   1x   1x                       4x               1x   1x   1x           1x                                                       218x 20x            
/*
 * 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 { pick } from 'lodash-es'
import { Connectors } from '@connectors/constants'
import type { ConnectorRequestBody, ConnectorInfoDTO } from 'services/cd-ng'
import type { IGitContextFormProps } from '@common/components/GitContextForm/GitContextForm'
import type { ConnectivityModeType } from '@common/components/ConnectivityMode/ConnectivityMode'
import { useFeatureFlags } from '@common/hooks/useFeatureFlag'
import { useTelemetry } from '@common/hooks/useTelemetry'
import { Category, ConnectorActions } from '@common/constants/TrackingConstants'
import CreateGitConnector from '../CreateConnector/GitConnector/CreateGitConnector'
import CreateGithubConnector from '../CreateConnector/GithubConnector/CreateGithubConnector'
import CreateGitlabConnector from '../CreateConnector/GitlabConnector/CreateGitlabConnector'
import CreateBitbucketConnector from '../CreateConnector/BitbucketConnector/CreateBitbucketConnector'
import CreateK8sConnector from '../CreateConnector/K8sConnector/CreateK8sConnector'
import CreateHashiCorpVault from '../CreateConnector/HashiCorpVault/CreateHashiCorpVault'
import CreateAppDynamicsConnector from '../CreateConnector/AppDynamicsConnector/CreateAppDynamicsConnector'
import CreateSplunkConnector from '../CreateConnector/SplunkConnector/CreateSplunkConnector'
import CreateDockerConnector from '../CreateConnector/DockerConnector/CreateDockerConnector'
import CreateAWSConnector from '../CreateConnector/AWSConnector/CreateAWSConnector'
import CreateAWSCodeCommitConnector from '../CreateConnector/AWSCodeCommitConnector/CreateAWSCodeCommitConnector'
import CreateNexusConnector from '../CreateConnector/NexusConnector/CreateNexusConnector'
import CreateArtifactoryConnector from '../CreateConnector/ArtifactoryConnector/CreateArtifactoryConnector'
import CreateGcpConnector from '../CreateConnector/GcpConnector/CreateGcpConnector'
import HelmRepoConnector from '../CreateConnector/HelmRepoConnector/HemRepoConnector'
import JiraConnector from '../CreateConnector/JiraConnector/JiraConnector'
import ServiceNowConnector from '../CreateConnector/ServiceNowConnector/ServiceNowConnector'
import CreateAwsKmsConnector from '../CreateConnector/AWSKmsConnector/CreateAwsKmsConnector'
import CreateGcpKmsConnector from '../CreateConnector/GcpKmsConnector/CreateGcpKmsConnector'
import CreateAwsSecretManagerConnector from '../CreateConnector/AWSSecretManager/CreateAwsSecretManagerConnector'
import CreateNewRelicConnector from '../CreateConnector/NewRelicConnector/CreateNewRelicConnector'
import CreatePrometheusConnector from '../CreateConnector/PrometheusConnector/CreatePrometheusConnector'
import CreateDataDogConnector from '../CreateConnector/DataDogConnector/CreateDataDogConnector'
import CreatePagerDutyConnector from '../CreateConnector/PagerDutyConnector/CreatePagerDutyConnector'
import CreateCeAzureConnector from '../CreateConnector/CEAzureConnector/CreateCeAzureConnector'
import CreateCEK8sConnector from '../CreateConnector/CEK8sConnector/CreateCEK8sConnector'
import CreateAzureKeyVaultConnector from '../CreateConnector/CreateAzureKeyConnector/CreateAzureKeyVaultConnector'
import CreateDynatraceConnector from '../CreateConnector/DynatraceConnector/CreateDynatraceConnector'
import CreateSumoLogicConnector from '../CreateConnector/SumoLogicConnector/CreateSumoLogicConnector'
import CENGAwsConnector from '../CreateConnector/CENGAwsConnector/CreateCeAwsConnector'
import CreateCeGcpConnector from '../CreateConnector/CEGcpConnector/CreateCeGcpConnector'
import CreateCustomHealthConnector from '../CreateConnector/CustomHealthConnector/CreateCustomHealthConnector'
import CreateErrorTrackingConnector from '../CreateConnector/ErrorTrackingConnector/CreateErrorTrackingConnector'
import css from './CreateConnectorWizard.module.scss'
 
interface CreateConnectorWizardProps {
  accountId: string
  projectIdentifier: string
  orgIdentifier: string
  type: ConnectorInfoDTO['type']
  isEditMode: boolean
  setIsEditMode: (val: boolean) => void
  connectorInfo: ConnectorInfoDTO | void
  connectivityMode?: ConnectivityModeType
  setConnectivityMode?: (val: ConnectivityModeType) => void
  gitDetails?: IGitContextFormProps
  onClose: () => void
  onSuccess: (data?: ConnectorRequestBody) => void | Promise<void>
}
 
export const ConnectorWizard: React.FC<CreateConnectorWizardProps> = props => {
  const { type } = props
  const { trackEvent } = useTelemetry()
  const onSuccessWithEventTracking = (data?: ConnectorRequestBody): void | Promise<void> => {
    props.onSuccess(data)
    trackEvent(ConnectorActions.SaveCreateConnector, {
      category: Category.CONNECTOR,
      data
    })
  }
 
  let commonProps = pick(props, [
    'onSuccess',
    'onClose',
    'isEditMode',
    'setIsEditMode',
    'connectorInfo',
    'gitDetails',
    'accountId',
    'orgIdentifier',
    'projectIdentifier',
    'connectivityMode',
    'setConnectivityMode'
  ])
  commonProps = {
    ...commonProps,
    onSuccess: onSuccessWithEventTracking
  }
  const { ERROR_TRACKING_ENABLED } = useFeatureFlags()
  React.useEffect(() => {
    trackEvent(ConnectorActions.StartCreateConnector, {
      category: Category.CONNECTOR
    })
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])
  switch (type) {
    case Connectors.CUSTOM:
      return <CreateCustomHealthConnector {...commonProps} />
    case Connectors.KUBERNETES_CLUSTER:
      return <CreateK8sConnector {...commonProps} />
    case Connectors.GIT:
      return <CreateGitConnector {...commonProps} />
    case Connectors.GITHUB:
      return <CreateGithubConnector {...commonProps} />
    case Connectors.GITLAB:
      return <CreateGitlabConnector {...commonProps} />
    case Connectors.BITBUCKET:
      return <CreateBitbucketConnector {...commonProps} />
    case Connectors.VAULT:
      return <CreateHashiCorpVault {...commonProps} />
    case Connectors.Jira:
      return <JiraConnector {...commonProps} />
    case Connectors.APP_DYNAMICS:
      return <CreateAppDynamicsConnector {...commonProps} />
    case Connectors.SPLUNK:
      return <CreateSplunkConnector {...commonProps} />
    case Connectors.NEW_RELIC:
      return <CreateNewRelicConnector {...commonProps} />
    case Connectors.PROMETHEUS:
      return <CreatePrometheusConnector {...commonProps} />
    case Connectors.DOCKER:
      return <CreateDockerConnector {...commonProps} />
    case Connectors.HttpHelmRepo:
      return <HelmRepoConnector {...commonProps} />
    case Connectors.AWS:
      return <CreateAWSConnector {...commonProps} />
    case Connectors.AWS_CODECOMMIT:
      return <CreateAWSCodeCommitConnector {...commonProps} />
    case Connectors.NEXUS:
      return <CreateNexusConnector {...commonProps} />
    case Connectors.ARTIFACTORY:
      return <CreateArtifactoryConnector {...commonProps} />
    case Connectors.GCP:
      return <CreateGcpConnector {...commonProps} />
    case Connectors.AWS_KMS:
      return <CreateAwsKmsConnector {...commonProps} />
    case Connectors.AWS_SECRET_MANAGER:
      return <CreateAwsSecretManagerConnector {...commonProps} />
    case Connectors.GCP_KMS:
      return <CreateGcpKmsConnector {...commonProps} />
    case Connectors.CE_AZURE:
      return <CreateCeAzureConnector {...commonProps} />
    case Connectors.CE_KUBERNETES:
      return <CreateCEK8sConnector {...commonProps} />
    case Connectors.DATADOG:
      return <CreateDataDogConnector {...commonProps} />
    case Connectors.AZURE_KEY_VAULT:
      return <CreateAzureKeyVaultConnector {...commonProps} />
    case Connectors.DYNATRACE:
      return <CreateDynatraceConnector {...commonProps} />
    case Connectors.SUMOLOGIC:
      return <CreateSumoLogicConnector {...commonProps} />
    case Connectors.CEAWS:
      return <CENGAwsConnector {...commonProps} />
    case Connectors.CE_GCP:
      return <CreateCeGcpConnector {...commonProps} />
    case Connectors.PAGER_DUTY:
      return <CreatePagerDutyConnector {...commonProps} />
    case Connectors.SERVICE_NOW:
      return <ServiceNowConnector {...commonProps} />
    case Connectors.ERROR_TRACKING:
      return ERROR_TRACKING_ENABLED ? <CreateErrorTrackingConnector {...commonProps} /> : null
    default:
      return null
  }
}
 
export const CreateConnectorWizard: React.FC<CreateConnectorWizardProps> = props => {
  return (
    <div className={css.createConnectorWizard}>
      <ConnectorWizard {...props} />
    </div>
  )
}