All files / modules/35-connectors/common/ErrorSuggestions ErrorSuggestionsCe.tsx

100% Statements 16/16
100% Branches 3/3
100% Functions 2/2
100% Lines 16/16

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              259x 259x 259x 259x 259x 259x   259x             259x 2x 2x 1x                                                                   1x 1x               1x 1x                                                         259x  
/*
 * Copyright 2022 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 { Container, Icon, Layout, Text, IconName } from '@harness/uicore'
import { Color, FontVariation } from '@harness/design-system'
import React from 'react'
import cx from 'classnames'
import { Connectors } from '@connectors/constants'
import { useStrings } from 'framework/strings'
import type { ResponseMessage } from 'services/cd-ng'
import css from '@common/components/ErrorHandler/ErrorHandler.module.scss'
 
const Suggestions: React.FC<{
  items: ResponseMessage[]
  header: string
  icon: IconName
  connectorType: string
}> = props => {
  const { getString } = useStrings()
  if (!props.items.length) {
    return null
  }
  /* istanbul ignore next */
  const getDocumentIndex = (msg: string) => {
    const docIndex = msg.lastIndexOf('documentation')
    let firstStr = msg
    let secondStr = ''
    if (docIndex >= 0) {
      firstStr = msg.slice(0, docIndex)
      secondStr = msg.slice(docIndex)
    }
    return { firstStr, secondStr }
  }
 
  /* istanbul ignore next */
  const getDocLink = () => {
    switch (props.connectorType) {
      case Connectors.CE_KUBERNETES:
        return 'https://ngdocs.harness.io/article/ltt65r6k39-set-up-cost-visibility-for-kubernetes'
 
      case Connectors.CEAWS:
        return 'https://ngdocs.harness.io/article/80vbt5jv0q-set-up-cost-visibility-for-aws'
 
      case Connectors.CE_AZURE:
        return 'https://ngdocs.harness.io/article/v682mz6qfd-set-up-cost-visibility-for-azure'
 
      case Connectors.CE_GCP:
        return 'https://ngdocs.harness.io/article/kxnsritjls-set-up-cost-visibility-for-gcp'
 
      default:
        return 'https://ngdocs.harness.io/article/n8e7rddf8w-cloud-cost-management-overview'
    }
  }
 
  const docUrl = getDocLink()
  return (
    <Layout.Horizontal margin={{ bottom: 'xlarge' }}>
      <Icon name={props.icon} margin={{ right: 'small' }} />
      <Layout.Vertical className={cx(css.errorListTextContainer, css.shrink)}>
        <Text font={{ variation: FontVariation.SMALL_SEMI }} color={Color.BLACK} margin={{ bottom: 'xsmall' }}>
          {props.header}
        </Text>
        {props.items.map((item, index) => {
          const { firstStr, secondStr } = getDocumentIndex(item.message as string)
          return (
            <Container margin={{ bottom: 'xsmall' }} key={index}>
              <Text color={Color.BLACK} font={{ variation: FontVariation.SMALL }} className={css.text}>
                {firstStr}
                {secondStr ? (
                  /* istanbul ignore next */
                  <a href={docUrl} target="_blank" rel="noreferrer" className={cx(css.link, css.linkSmall)}>
                    {secondStr}
                  </a>
                ) : /* istanbul ignore next */ null}
              </Text>
              {!secondStr ? (
                <Text font={{ variation: FontVariation.SMALL_SEMI }} color={Color.BLACK} margin={{ bottom: 'xsmall' }}>
                  {getString('common.errorHandler.contactLabel')}
                  <a href="mailto:support@harness.io">{getString('common.errorHandler.contactSupport')}</a>
                  {getString('or')}
                  <a href="https://community.harness.io/" target="_blank" rel="noreferrer">
                    {getString('common.errorHandler.communityForum')}
                  </a>
                </Text>
              ) : /* istanbul ignore next */ null}
            </Container>
          )
        })}
      </Layout.Vertical>
    </Layout.Horizontal>
  )
}
 
export default Suggestions