All files / modules/10-common/components/ConnectivityMode ConnectivityMode.tsx

100% Statements 17/17
100% Branches 2/2
100% Functions 4/4
100% Lines 17/17

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              267x 267x 267x 267x     267x 267x 267x   267x 267x 267x                             267x 17x 17x                                 17x           26x                               27x           267x  
/*
 * 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 cx from 'classnames'
import { Text, FormikCollapsableSelect, CollapsableSelectType, CollapsableSelectOptions } from '@wings-software/uicore'
import { Color, FontVariation } from '@harness/design-system'
import type { FormikContext } from 'formik'
 
import DelegatesGit from '@common/icons/DelegatesGit.svg'
import PlatformGit from '@common/icons/PlatformGit.svg'
import { useStrings } from 'framework/strings'
 
export enum ConnectivityModeType {
  Manager = 'Manager',
  Delegate = 'Delegate'
}
export interface ConnectivityCardItem extends CollapsableSelectOptions {
  type: ConnectivityModeType
  title: string
  info: string
  icon: JSX.Element
}
 
interface ConnectivityModeProps {
  formik: FormikContext<Record<string, unknown>>
  className?: string
  onChange: (val: ConnectivityCardItem) => void
}
 
const ConnectivityMode: React.FC<ConnectivityModeProps> = props => {
  const { getString } = useStrings()
  const ConnectivityCard: ConnectivityCardItem[] = [
    {
      type: ConnectivityModeType.Manager,
      title: getString('common.connectThroughPlatform'),
      info: getString('common.connectThroughPlatformInfo'),
      icon: <img src={PlatformGit} width="100%" />,
      value: ConnectivityModeType.Manager
    },
    {
      type: ConnectivityModeType.Delegate,
      title: getString('common.connectThroughDelegate'),
      info: getString('common.connectThroughDelegateInfo'),
      icon: <img src={DelegatesGit} width="100%" />,
      value: ConnectivityModeType.Delegate
    }
  ]
 
  return (
    <FormikCollapsableSelect<ConnectivityCardItem>
      name="connectivityMode"
      items={ConnectivityCard}
      itemClassName={cx(props.className)}
      renderItem={(item: ConnectivityCardItem) => {
        return (
          <>
            <Text font={{ variation: FontVariation.H6 }} color={Color.GREY_900} margin={{ bottom: 'small' }}>
              {item.title}
            </Text>
 
            <Text color={Color.BLACK} font={{ variation: FontVariation.SMALL }}>
              {item.info}
            </Text>
            {item.icon}
          </>
        )
      }}
      onChange={props.onChange}
      type={CollapsableSelectType.CardView}
      selected={
        ConnectivityCard[ConnectivityCard.findIndex(card => card.type === props.formik.values.connectivityMode)]
      }
    />
  )
}
 
export default ConnectivityMode